Skip to content

Commit 9afa15f

Browse files
authored
fix(ios): gesture handling resilience when views are destroyed quickly (NativeScript#8645)
closes NativeScript#8641
1 parent 5cacc25 commit 9afa15f

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

nativescript-core/ui/gestures/gestures.ios.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,55 +128,75 @@ export class GesturesObserver extends GesturesObserverBase {
128128

129129
if (type & GestureTypes.tap) {
130130
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.tap, args => {
131-
this._executeCallback(_getTapData(args));
131+
if (args.view) {
132+
this._executeCallback(_getTapData(args));
133+
}
132134
}));
133135
}
134136

135137
if (type & GestureTypes.doubleTap) {
136138
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, args => {
137-
this._executeCallback(_getTapData(args));
139+
if (args.view) {
140+
this._executeCallback(_getTapData(args));
141+
}
138142
}));
139143
}
140144

141145
if (type & GestureTypes.pinch) {
142146
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.pinch, args => {
143-
this._executeCallback(_getPinchData(args));
147+
if (args.view) {
148+
this._executeCallback(_getPinchData(args));
149+
}
144150
}));
145151
}
146152

147153
if (type & GestureTypes.pan) {
148154
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.pan, args => {
149-
this._executeCallback(_getPanData(args, target.nativeViewProtected));
155+
if (args.view) {
156+
this._executeCallback(_getPanData(args, target.nativeViewProtected));
157+
}
150158
}));
151159
}
152160

153161
if (type & GestureTypes.swipe) {
154162
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => {
155-
this._executeCallback(_getSwipeData(args));
163+
if (args.view) {
164+
this._executeCallback(_getSwipeData(args));
165+
}
156166
}, UISwipeGestureRecognizerDirection.Down));
157167

158168
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => {
159-
this._executeCallback(_getSwipeData(args));
169+
if (args.view) {
170+
this._executeCallback(_getSwipeData(args));
171+
}
160172
}, UISwipeGestureRecognizerDirection.Left));
161173

162174
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => {
163-
this._executeCallback(_getSwipeData(args));
175+
if (args.view) {
176+
this._executeCallback(_getSwipeData(args));
177+
}
164178
}, UISwipeGestureRecognizerDirection.Right));
165179

166180
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, args => {
167-
this._executeCallback(_getSwipeData(args));
181+
if (args.view) {
182+
this._executeCallback(_getSwipeData(args));
183+
}
168184
}, UISwipeGestureRecognizerDirection.Up));
169185
}
170186

171187
if (type & GestureTypes.rotation) {
172188
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.rotation, args => {
173-
this._executeCallback(_getRotationData(args));
189+
if (args.view) {
190+
this._executeCallback(_getRotationData(args));
191+
}
174192
}));
175193
}
176194

177195
if (type & GestureTypes.longPress) {
178196
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress, args => {
179-
this._executeCallback(_getLongPressData(args));
197+
if (args.view) {
198+
this._executeCallback(_getLongPressData(args));
199+
}
180200
}));
181201
}
182202

0 commit comments

Comments
 (0)