Skip to content

Commit 94f6599

Browse files
committed
feat: exclusiveTouch property
1 parent f027a14 commit 94f6599

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/gesturehandler.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
GestureStateEventData,
2020
GestureTouchEventData,
2121
HandlerType,
22-
Manager as ManagerBase,
22+
ManagerBase,
2323
OptionsTypeMap,
2424
TypeMap,
2525
ViewDisposeEvent,

src/gesturehandler.common.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import Observable from '@nativescript-community/observable';
77
import { EventData } from '@nativescript/core';
8-
import { View } from '@nativescript/core/ui';
8+
import { Property, View, booleanConverter } from '@nativescript/core/ui';
99
import {
1010
FlingGestureHandler,
1111
FlingGestureHandlerOptions,
@@ -14,6 +14,7 @@ import {
1414
Handler,
1515
LongPressGestureHandler,
1616
LongPressGestureHandlerOptions,
17+
Manager,
1718
NativePropertyOptions,
1819
NativeViewGestureHandler,
1920
NativeViewGestureHandlerOptions,
@@ -142,7 +143,7 @@ export abstract class BaseNative<T, U extends {}> extends Observable {
142143
}
143144
}
144145

145-
export abstract class Manager extends Observable {
146+
export abstract class ManagerBase extends Observable {
146147
abstract createGestureHandler<T extends HandlerType>(handlerName: T, handlerTag: number, config?: OptionsTypeMap[T]): TypeMap[T];
147148
}
148149

@@ -256,28 +257,49 @@ export function applyMixins(
256257

257258
export const ViewInitEvent = 'ViewInitEvent';
258259
export const ViewDisposeEvent = 'ViewDisposeEvent';
260+
261+
let NATIVE_GESTURE_TAG = 74000;
262+
export const exclusiveTouchProperty = new Property<View, boolean>({
263+
name: 'exclusiveTouch',
264+
defaultValue: false,
265+
valueConverter: booleanConverter,
266+
});
259267
class ViewGestureExtended extends View {
268+
exclusiveTouchGestureHandler: NativeViewGestureHandler;
260269
initNativeView() {
261-
// console.log(this.constructor.name, 'initNativeView', this.nativeView);
262270
if (this.nativeView) {
263271
this.nativeView.nsView = new WeakRef(this);
264272
}
265-
266273
this.notify({ eventName: ViewInitEvent, object: this });
267274
}
268275
disposeNativeView() {
269-
// console.log(this.constructor.name, 'disposeNativeView', this.nativeView);
270276
if (this.nativeView) {
271277
this.nativeView.nsView = null;
272278
}
273-
// console.log('disposeNativeView', this);
274279
this.notify({ eventName: ViewDisposeEvent, object: this });
275280
}
281+
[exclusiveTouchProperty.setNative](value: boolean) {
282+
// console.log('exclusiveTouchProperty', this, value);
283+
if (value) {
284+
if (!this.exclusiveTouchGestureHandler) {
285+
const gestureHandler = Manager.getInstance().createGestureHandler(HandlerType.NATIVE_VIEW, NATIVE_GESTURE_TAG++, {
286+
disallowInterruption: true,
287+
shouldActivateOnStart: true,
288+
shouldCancelWhenOutside: false,
289+
});
290+
this.exclusiveTouchGestureHandler = gestureHandler as any;
291+
}
292+
this.exclusiveTouchGestureHandler.attachToView(this);
293+
} else if (this.exclusiveTouchGestureHandler) {
294+
this.exclusiveTouchGestureHandler.detachFromView();
295+
}
296+
}
276297
}
277298

278299
let installed = false;
279300
export function overrideViewBase() {
280301
const NSView = require('@nativescript/core/ui/core/view').View;
302+
exclusiveTouchProperty.register(NSView);
281303
applyMixins(NSView, [ViewGestureExtended]);
282304
}
283305

src/gesturehandler.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
GestureStateEventData,
1111
GestureTouchEventData,
1212
HandlerType,
13-
Manager as ManagerBase,
13+
ManagerBase,
1414
OptionsTypeMap,
1515
TypeMap,
1616
ViewDisposeEvent,

0 commit comments

Comments
 (0)