public void HandleTouch(TouchStatus status, TouchInteractionStatus?touchInteractionStatus = null) { if (IsCanceled || effect == null) { return; } if (effect?.IsDisabled ?? true) { return; } if (touchInteractionStatus == TouchInteractionStatus.Started) { effect?.HandleUserInteraction(TouchInteractionStatus.Started); touchInteractionStatus = null; } effect.HandleTouch(status); if (touchInteractionStatus.HasValue) { effect.HandleUserInteraction(touchInteractionStatus.Value); } if (!effect.NativeAnimation) { return; } if (longTapStarted && !tapCompleted) { return; } var control = effect.Element; if (!(Platform.GetOrCreateRenderer(control)?.NativeView is Widget nativeView)) { return; } if (status == TouchStatus.Started) { var startColor = nativeView.BackgroundColor; if (startColor.IsDefault) { return; } var endColor = effect.NativeAnimationColor.ToNative(); if (endColor.IsDefault) { startColor = EColor.FromRgba(startColor.R, startColor.G, startColor.B, startColor.A / 2); endColor = startColor; } var transit = new Transit { Repeat = 1, Duration = .2 }; var colorEffect = new ColorEffect(startColor, endColor); colorEffect.EffectEnded += (s, e) => { transit?.Dispose(); }; transit.Objects.Add(nativeView); transit.AddEffect(colorEffect); transit.Go(.2); } }
public void HandleTouch(TouchStatus status, UserInteractionState?userInteractionState = null) { if (IsCanceled || _effect == null) { return; } if (_effect?.IsDisabled ?? true) { return; } _effect.HandleTouch(status); if (userInteractionState.HasValue) { _effect.HandleUserInteraction(userInteractionState.Value); } if (!_effect.NativeAnimation) { return; } if (_longTapStarted && !_tapCompleted) { return; } var control = _effect.Control; var nativeView = Platform.GetOrCreateRenderer(control)?.NativeView as Widget; if (nativeView == null) { return; } if (status == TouchStatus.Started) { var startColor = nativeView.BackgroundColor; if (startColor.IsDefault) { return; } var endColor = _effect.NativeAnimationColor.ToNative();; if (endColor.IsDefault) { startColor = EColor.FromRgba(startColor.R, startColor.G, startColor.B, startColor.A / 2); endColor = startColor; } Transit transit = new Transit { Repeat = 1, Duration = .2 }; var colorEffect = new ColorEffect(startColor, endColor); colorEffect.EffectEnded += (s, e) => { transit?.Dispose(); }; transit.Objects.Add(nativeView); transit.AddEffect(colorEffect); transit.Go(.2); } }