Skip to content

Commit 1630b15

Browse files
committed
fix: android method to disable all current gestures
1 parent 12c7754 commit 1630b15

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/gesturehandler/gesturehandler.android.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export { GestureState, GestureHandlerStateEvent, GestureHandlerTouchEvent, Gestu
3636
let PageLayout: typeof com.nativescript.gesturehandler.PageLayout;
3737
class PageGestureExtended extends Page {
3838
nativeViewProtected: com.nativescript.gesturehandler.PageLayout;
39+
tryCancelAllHandlers() {
40+
this.nativeView?.tryCancelAllHandlers();
41+
}
3942
initNativeView() {
4043
this.nativeViewProtected.initialize();
4144
}
@@ -50,6 +53,9 @@ let installed = false;
5053
let installedOverrides = false;
5154

5255
export class GestureRootView extends BaseGestureRootView {
56+
tryCancelAllHandlers() {
57+
this.nativeView?.tryCancelAllHandlers();
58+
}
5359
createNativeView() {
5460
if (!PageLayout) {
5561
PageLayout = com.nativescript.gesturehandler.PageLayout;
@@ -550,12 +556,10 @@ export class Manager extends ManagerBase {
550556
}
551557
return handler as any;
552558
}
553-
554-
findRegistry(view: View): com.swmansion.gesturehandler.GestureHandlerRegistryImpl {
559+
findRootView(view: View): PageGestureExtended | GestureRootView {
555560
if (view instanceof GestureRootView) {
556-
return view.registry;
561+
return view;
557562
}
558-
let registry: com.swmansion.gesturehandler.GestureHandlerRegistryImpl;
559563
let parent = view.parent;
560564
// first test for GestureRootView
561565
// otherwise it could fail with components like BottomSheet
@@ -564,7 +568,7 @@ export class Manager extends ManagerBase {
564568
// as the one use for touch
565569
while (parent) {
566570
if (parent instanceof GestureRootView) {
567-
return parent.registry;
571+
return parent;
568572
}
569573
// we need to break if it is a modal page or we will get the wrong registry
570574
if (parent['_dialogFragment']) {
@@ -574,10 +578,10 @@ export class Manager extends ManagerBase {
574578
}
575579

576580
const page = view.page as PageGestureExtended;
577-
if (page) {
578-
registry = page.registry;
579-
}
580-
return registry;
581+
return page;
582+
}
583+
findRegistry(view: View): com.swmansion.gesturehandler.GestureHandlerRegistryImpl {
584+
return this.findRootView(view)?.registry;
581585
}
582586
attachGestureHandlerToView<T extends com.swmansion.gesturehandler.GestureHandler<any> = com.swmansion.gesturehandler.GestureHandler<any>>(handler: Handler<T, any>, view: View) {
583587
const nHandler = handler.getNative();

src/gesturehandler/gesturehandler.common.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ export interface GestureTouchEventData extends EventData {
175175
};
176176
}
177177

178-
export class BaseGestureRootView extends GridLayout {}
178+
export class BaseGestureRootView extends GridLayout {
179+
tryCancelAllHandlers() {}
180+
}
179181

180182
export function applyMixins(
181183
derivedCtor: any,
@@ -267,6 +269,11 @@ let NATIVE_GESTURE_TAG = 74000;
267269
class ViewGestureExtended extends View {
268270
exclusiveTouchGestureHandler: NativeViewGestureHandler;
269271

272+
cancelAllGestures() {
273+
const rootView = Manager.getInstance().findRootView(this);
274+
console.log('cancelAllGestures', rootView);
275+
rootView.tryCancelAllHandlers?.();
276+
}
270277
initNativeView() {
271278
if (this.nativeView) {
272279
this.nativeView.nsView = new WeakRef(this);

src/gesturehandler/gesturehandler.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class ForceTouchGestureHandler extends Handler<any, ForceTouchGestureHand
169169
export class Manager extends Observable {
170170
static getInstance(): Manager;
171171
createGestureHandler<T extends HandlerType>(handlerName: T, handlerTag: number, config?: OptionsTypeMap[T]): TypeMap[T];
172+
findRootView(view: View): BaseGestureRootView;
172173
}
173174
export function install(overrideNGestures?: boolean);
174175

0 commit comments

Comments
 (0)