void CheckForBoundaryHop(NSSet touches)
        {
            long id = touches.Handle.ToInt64();

            // TODO: Might require converting to a List for multiple hits
            TouchRecognizer_Touch recognizerHit = null;

            foreach (UIView view in _viewDictionary.Keys)
            {
                var locations = touches.Cast <UITouch>().Select(touch => touch.LocationInView(view));
                if (locations.Any(location => IsInView(view, location)))
                {
                    recognizerHit = _viewDictionary[view];
                }
            }

            if (!ReferenceEquals(recognizerHit, _idToTouchDictionary[id]))
            {
                if (_idToTouchDictionary[id] != null)
                {
                    RaiseEvent(_idToTouchDictionary[id], id, TouchState.Exited, touches, true);
                }

                if (recognizerHit != null)
                {
                    RaiseEvent(recognizerHit, id, TouchState.Entered, touches, true);
                }

                _idToTouchDictionary[id] = recognizerHit;
            }
        }
        private static void RaiseEvent(TouchRecognizer_Touch recognizer, long id, TouchState actionType, NSSet touches, bool isInContact)
        {
            var formsPoints = touches.Cast <UITouch>()
                              .Select(touch => touch.LocationInView(recognizer.View))
                              .Select(cgPoint => new TouchPoint(cgPoint.ToPoint(), IsInView(recognizer.View, cgPoint)))
                              .ToList();

            // Get the method to call for firing events
            // note: this would live on the VisualElement and not in an effect :)
            var effect = recognizer._formsView.Effects.FirstOrDefault(x => x.Is <TouchEffect>()) as TouchEffect;

            effect?.SendTouched(recognizer._formsView, new TouchEventArgs(actionType, formsPoints, id, isInContact));
        }
Exemple #3
0
        protected override void OnAttached()
        {
            if (!Element.Is(out _formsElement))
            {
                throw new InvalidOperationException("Can only attach Touch Effects to Views");
            }

            _uiGestureRecognizer = new TouchRecognizer_Touch(_formsElement, UiView);

            UiView.UserInteractionEnabled = true;

            // none of this has to do with Forms GestureRecognizers
            if (!(UiView.GestureRecognizers is null) && UiView.GestureRecognizers.Contains(_uiGestureRecognizer))
            {
                UiView.RemoveGestureRecognizer(_uiGestureRecognizer);
            }

            UiView.AddGestureRecognizer(_uiGestureRecognizer);
        }