Esempio n. 1
0
        protected override void OnAttached()
        {
            isCanTouch       = Touch.GetIsEnabled(Element);
            commandStartTap  = Touch.GetStartTap(Element);
            commandFinishTap = Touch.GetFinishTap(Element);
            commandTap       = Touch.GetTap(Element);
            commandLongTap   = Touch.GetLongTap(Element);
            longTapLatency   = Touch.GetLongTapLatency(Element);
            gestureTap       = new GestureTouchSam(OnTap);
            gestureTap.MinimumPressDuration = 0;
            gestureTap.ShouldReceiveTouch  += (UIGestureRecognizer g, UITouch t) =>
            {
                return(true);
            };
            gestureTap.ShouldRecognizeSimultaneously += (UIGestureRecognizer g, UIGestureRecognizer t) =>
            {
                return(true);
            };

            if (commandLongTap != null)
            {
                TimerInit();
            }

            View.UserInteractionEnabled = true;
            View.AddGestureRecognizer(gestureTap);

            UpdateEffectColor();
        }
Esempio n. 2
0
 public static void Preserve()
 {
     Touch.Preserve();
     TimerPlatform.Preserve();
     GestureTouchSam.Preserve();
     GView.Preserve();
 }
Esempio n. 3
0
 public static void Init()
 {
     Touch.Init();
     TouchIOS.Init();
     TimerPlatform.Init();
     GestureTouchSam.Preserve();
     GView.Preserve();
 }
Esempio n. 4
0
 public GView(UIView view, GestureTouchSam gesture)
 {
     View    = view;
     Gesture = gesture;
 }
Esempio n. 5
0
        internal void OnTap(UILongPressGestureRecognizer press)
        {
            if (View == null)
            {
                return;
            }

            var  coordinate = press.LocationInView(View);
            bool isInside   = View.PointInside(coordinate, null);

            // If this gesture detect nested TouchSam gesture
            if (nestedGesture != null)
            {
                nestedGesture.OnTap(press);

                // Detect END
                if (press.State != UIGestureRecognizerState.Changed)
                {
                    nestedGesture = null;
                }

                return;
            }

            switch (press.State)
            {
            case UIGestureRecognizerState.Began:
                // Detect nested TouchSam gestures
                var childsGestures = GetNestedTouchs(View);
                foreach (var item in childsGestures)
                {
                    if (item.Gesture == gestureTap)
                    {
                        continue;
                    }

                    var point = press.LocationInView(item.View);
                    if (item.View.PointInside(point, null))
                    {
                        nestedGesture = item.Gesture;
                        nestedGesture.OnTap(press);
                        return;
                    }
                }

                // Without nested TouchSam gestures
                if (isCanTouch)
                {
                    startPoint = coordinate;
                    StartTapExecute();
                    isTaped = true;
                    if (timer != null)
                    {
                        timer.Start(longTapLatency);
                    }
                    TapAnimation(0.3, 0, _alpha, false);
                }
                break;

            case UIGestureRecognizerState.Changed:
                if (!isInside && isTaped)
                {
                    isTaped = false;
                    TapAnimation(0.3, _alpha);
                    FinishTapExecute();
                }
                else if (isTaped)
                {
                    var diffX   = Math.Abs(coordinate.X - startPoint.X);
                    var diffY   = Math.Abs(coordinate.Y - startPoint.Y);
                    var maxDiff = Math.Max(diffX, diffY);
                    if (maxDiff > 4)
                    {
                        isTaped = false;
                        TapAnimation(0.3, _alpha);
                        FinishTapExecute();
                    }
                }
                break;

            case UIGestureRecognizerState.Ended:
                if (isInside && isTaped && isCanTouch)
                {
                    if (timer == null)
                    {
                        TapExecute();
                    }
                    else
                    {
                        if (timer.IsEnabled)
                        {
                            TapExecute();
                            timer.Stop();
                        }
                    }
                    TapAnimation(0.3, _alpha);
                    FinishTapExecute();
                }
                isTaped = false;
                break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Failed:
                if (isTaped)
                {
                    isTaped = false;
                    TapAnimation(0.3, _alpha);
                    FinishTapExecute();
                }
                break;
            }
        }