55
66import Observable from '@nativescript-community/observable' ;
77import { EventData } from '@nativescript/core' ;
8- import { View } from '@nativescript/core/ui' ;
8+ import { Property , View , booleanConverter } from '@nativescript/core/ui' ;
99import {
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
257258export const ViewInitEvent = 'ViewInitEvent' ;
258259export 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+ } ) ;
259267class 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
278299let installed = false ;
279300export function overrideViewBase ( ) {
280301 const NSView = require ( '@nativescript/core/ui/core/view' ) . View ;
302+ exclusiveTouchProperty . register ( NSView ) ;
281303 applyMixins ( NSView , [ ViewGestureExtended ] ) ;
282304}
283305
0 commit comments