protected override void OnAttached()
        {
            effect = TouchEffect.PickFrom(Element);
            if (effect?.IsDisabled ?? true)
            {
                return;
            }

            effect.Element = (VisualElement)Element;

            touchGesture = new TouchUITapGestureRecognizer(effect);
            hoverGesture = new UIHoverGestureRecognizer(OnHover);

            if (View != null)
            {
                if (((View as IVisualNativeElementRenderer)?.Control ?? View) is UIButton button)
                {
                    button.AllTouchEvents += PreventButtonHighlight;
                    touchGesture.IsButton  = true;
                }

                View.AddGestureRecognizer(touchGesture);
                View.AddGestureRecognizer(hoverGesture);
                View.UserInteractionEnabled = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HoverRecognizer"/> class.
        /// </summary>
        /// <param name="view">The native view.</param>
        public HoverRecognizer(UIView view) : base(view)
        {
            if (!UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                throw new NotSupportedException($"{nameof(HoverRecognizer)} is only supported on iOS 13 and above.");
            }

            _recognizer = new NativeHoverRecognizer(this);
            view.AddGestureRecognizer(_recognizer);
        }
        protected override void OnDetached()
        {
            if (effect?.Element == null)
            {
                return;
            }

            if (((View as IVisualNativeElementRenderer)?.Control ?? View) is UIButton button)
            {
                button.AllTouchEvents -= PreventButtonHighlight;
            }

            View?.RemoveGestureRecognizer(touchGesture);
            View?.RemoveGestureRecognizer(hoverGesture);
            touchGesture?.Dispose();
            hoverGesture?.Dispose();
            touchGesture   = null;
            hoverGesture   = null;
            effect.Element = null;
            effect         = null;
        }