From 9afa15fa710984c2769d42b1d9accf04d2ad52a8 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 16 Jun 2020 15:18:48 -0700 Subject: [PATCH] fix(ios): gesture handling resilience when views are destroyed quickly (#8645) closes https://github.com/NativeScript/NativeScript/issues/8641 --- nativescript-core/ui/gestures/gestures.ios.ts | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/nativescript-core/ui/gestures/gestures.ios.ts b/nativescript-core/ui/gestures/gestures.ios.ts index 61b2fb8de..5933d85c2 100644 --- a/nativescript-core/ui/gestures/gestures.ios.ts +++ b/nativescript-core/ui/gestures/gestures.ios.ts @@ -128,55 +128,75 @@ export class GesturesObserver extends GesturesObserverBase { if (type & GestureTypes.tap) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.tap, args => { - this._executeCallback(_getTapData(args)); + if (args.view) { + this._executeCallback(_getTapData(args)); + } })); } if (type & GestureTypes.doubleTap) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, args => { - this._executeCallback(_getTapData(args)); + if (args.view) { + this._executeCallback(_getTapData(args)); + } })); } if (type & GestureTypes.pinch) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.pinch, args => { - this._executeCallback(_getPinchData(args)); + if (args.view) { + this._executeCallback(_getPinchData(args)); + } })); } if (type & GestureTypes.pan) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.pan, args => { - this._executeCallback(_getPanData(args, target.nativeViewProtected)); + if (args.view) { + this._executeCallback(_getPanData(args, target.nativeViewProtected)); + } })); } if (type & GestureTypes.swipe) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => { - this._executeCallback(_getSwipeData(args)); + if (args.view) { + this._executeCallback(_getSwipeData(args)); + } }, UISwipeGestureRecognizerDirection.Down)); nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => { - this._executeCallback(_getSwipeData(args)); + if (args.view) { + this._executeCallback(_getSwipeData(args)); + } }, UISwipeGestureRecognizerDirection.Left)); nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => { - this._executeCallback(_getSwipeData(args)); + if (args.view) { + this._executeCallback(_getSwipeData(args)); + } }, UISwipeGestureRecognizerDirection.Right)); nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => { - this._executeCallback(_getSwipeData(args)); + if (args.view) { + this._executeCallback(_getSwipeData(args)); + } }, UISwipeGestureRecognizerDirection.Up)); } if (type & GestureTypes.rotation) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.rotation, args => { - this._executeCallback(_getRotationData(args)); + if (args.view) { + this._executeCallback(_getRotationData(args)); + } })); } if (type & GestureTypes.longPress) { nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress, args => { - this._executeCallback(_getLongPressData(args)); + if (args.view) { + this._executeCallback(_getLongPressData(args)); + } })); }