@@ -76,6 +76,9 @@ export interface PageLayout extends org.nativescript.widgets.GridLayout {
7676 new ( context ) : PageLayout ;
7777 setShouldIntercept ( value : boolean ) ;
7878 setPassingTouch ( value : boolean ) ;
79+ initialize ( ) ;
80+ tearDown ( ) ;
81+ registry : com . swmansion . gesturehandler . GestureHandlerRegistryImpl ;
7982}
8083function initPageLayout ( ) {
8184 if ( PageLayout ) {
@@ -89,6 +92,7 @@ function initPageLayout() {
8992 // mGestureRootHelper: GestureHandlerRootHelper;
9093
9194 mOrchestrator : com . swmansion . gesturehandler . GestureHandlerOrchestrator ;
95+ mRegistry : com . swmansion . gesturehandler . GestureHandlerRegistryImpl ;
9296 configurationHelper : com . swmansion . gesturehandler . ViewConfigurationHelper ;
9397 rootGestureHandler : RootViewGestureHandler ;
9498
@@ -101,6 +105,10 @@ function initPageLayout() {
101105 setPassingTouch ( value ) {
102106 this . mPassingTouch = value ;
103107 }
108+
109+ get registry ( ) {
110+ return this . mRegistry ;
111+ }
104112 // requestDisallowInterceptTouchEvent(disallowIntercept) {
105113 // console.log('requestDisallowInterceptTouchEvent');
106114 // if (this.mGestureRootHelper != null) {
@@ -173,7 +181,7 @@ function initPageLayout() {
173181 * default RN behavior.
174182 */
175183 initialize ( ) {
176- const registry = Manager . getInstance ( ) . registry ;
184+ this . mRegistry = new com . swmansion . gesturehandler . GestureHandlerRegistryImpl ( ) ;
177185 this . configurationHelper = new com . swmansion . gesturehandler . ViewConfigurationHelper ( {
178186 getPointerEventsConfigForView ( view : android . view . View ) {
179187 return view . isEnabled ( ) ? com . swmansion . gesturehandler . PointerEventsConfig . AUTO : com . swmansion . gesturehandler . PointerEventsConfig . NONE ;
@@ -185,19 +193,22 @@ function initPageLayout() {
185193 return parent . getChildAt ( index ) ;
186194 }
187195 } ) ;
188- this . mOrchestrator = new com . swmansion . gesturehandler . GestureHandlerOrchestrator ( this , registry , this . configurationHelper ) ;
196+ this . mOrchestrator = new com . swmansion . gesturehandler . GestureHandlerOrchestrator ( this , this . mRegistry , this . configurationHelper ) ;
197+ console . log ( this . constructor . name , 'initialize' , this . mOrchestrator , this . mRegistry ) ;
189198 this . mOrchestrator . setMinimumAlphaForTraversal ( 0.01 ) ;
190199
191200 initRootViewGestureHandler ( ) ;
192201 const tag = - 12345 ;
193202 this . rootGestureHandler = new RootViewGestureHandler ( ) ;
194203 this . rootGestureHandler . setTag ( tag ) ;
195- registry . registerHandler ( this . rootGestureHandler ) ;
204+ this . mRegistry . registerHandler ( this . rootGestureHandler ) ;
196205 // registry.attachHandlerToView(this.rootGestureHandler.getTag(), this);
197206 }
198207 tearDown ( ) {
208+ console . log ( this . constructor . name , 'tearDown' , this . mOrchestrator , this . mRegistry ) ;
199209 this . configurationHelper = null ;
200210 this . mOrchestrator = null ;
211+ this . mRegistry = null ;
201212 // if (this.mGestureRootHelper != null) {
202213 // this.mGestureRootHelper.tearDown();
203214 // this.mGestureRootHelper = null;
@@ -208,19 +219,24 @@ function initPageLayout() {
208219}
209220
210221class PageGestureExtended extends Page {
222+ nativeView : PageLayout ;
211223 initNativeView ( ) {
212224 this . nativeView . initialize ( ) ;
213225 }
214226 disposeNativeView ( ) {
215227 this . nativeView . tearDown ( ) ;
216228 }
229+ get registry ( ) {
230+ return this . nativeView && this . nativeView . registry ;
231+ }
217232}
218233export function install ( ) {
219234 installBase ( ) ;
220235 const NSPage = require ( 'tns-core-modules/ui/page/page' ) . Page ;
221236 NSPage . prototype . createNativeView = function ( ) {
222237 initPageLayout ( ) ;
223238 const layout = new PageLayout ( this . _context ) ;
239+ this . gestureRegistry = layout . registry ;
224240 layout . addRow ( new org . nativescript . widgets . ItemSpec ( 1 , org . nativescript . widgets . GridUnitType . auto ) ) ;
225241 layout . addRow ( new org . nativescript . widgets . ItemSpec ( 1 , org . nativescript . widgets . GridUnitType . star ) ) ;
226242 return layout ;
@@ -347,7 +363,6 @@ export abstract class Handler<T extends com.swmansion.gesturehandler.GestureHand
347363 if ( this . native ) {
348364 this . native . setTag ( tag ) ;
349365 }
350- console . log ( 'setTag' , tag ) ;
351366 }
352367 getTag ( ) {
353368 return this . tag ;
@@ -586,13 +601,13 @@ export class Manager extends ManagerBase {
586601 }
587602 return this . _interactionManager ;
588603 }
589- _registry : com . swmansion . gesturehandler . GestureHandlerRegistryImpl ;
590- get registry ( ) {
591- if ( ! this . _registry ) {
592- this . _registry = new com . swmansion . gesturehandler . GestureHandlerRegistryImpl ( ) ;
593- }
594- return this . _registry ;
595- }
604+ // _registry: com.swmansion.gesturehandler.GestureHandlerRegistryImpl;
605+ // get registry() {
606+ // if (!this._registry) {
607+ // this._registry = new com.swmansion.gesturehandler.GestureHandlerRegistryImpl();
608+ // }
609+ // return this._registry;
610+ // }
596611
597612 static sManager : Manager ;
598613 static getInstance ( ) {
@@ -632,23 +647,34 @@ export class Manager extends ManagerBase {
632647 }
633648 return handler as any ;
634649 }
635- attachGestureHandlerToView ( handler : Handler < any , any > , view ) {
650+ attachGestureHandlerToView ( handler : Handler < any , any > , view : View ) {
636651 const nHandler = handler . getNative ( ) ;
637652 if ( nHandler ) {
638- this . registry . registerHandler ( nHandler ) ;
639- this . registry . attachHandlerToView ( nHandler . getTag ( ) , view ) ;
653+ const registry = ( view . page as PageGestureExtended ) . registry ;
654+ if ( registry ) {
655+ registry . registerHandler ( nHandler ) ;
656+ registry . attachHandlerToView ( nHandler . getTag ( ) , view . nativeView ) ;
657+ }
658+ }
659+ }
660+
661+ detachGestureHandlerFromView ( handler : Handler < any , any > , view : View ) {
662+ const nHandler = handler . getNative ( ) ;
663+ if ( nHandler ) {
664+ const registry = ( view . page as PageGestureExtended ) . registry ;
665+ if ( registry ) {
666+ registry . dropHandler ( handler . getNative ( ) ) ;
667+ }
640668 }
641669 }
642670
643671 viewListeners = new Map < View , Map < number , { init : ( ) => void ; dispose : ( ) => void } > > ( ) ;
644672 attachGestureHandler ( handler : Handler < any , any > , view : View ) {
645673 if ( view . nativeView ) {
646- this . attachGestureHandlerToView ( handler , view . nativeView ) ;
674+ this . attachGestureHandlerToView ( handler , view ) ;
647675 }
648- const onInit = ( ) => {
649- this . attachGestureHandlerToView ( handler , view . nativeView ) ;
650- } ;
651- const onDispose = ( ) => this . registry . dropHandler ( handler . getNative ( ) ) ;
676+ const onInit = ( ) => this . attachGestureHandlerToView ( handler , view ) ;
677+ const onDispose = ( ) => this . detachGestureHandlerFromView ( handler , view ) ;
652678 view . on ( ViewInitEvent , onInit , this ) ;
653679 view . on ( ViewDisposeEvent , onDispose , this ) ;
654680 let viewListeners = this . viewListeners . get ( view ) ;
@@ -676,6 +702,6 @@ export class Manager extends ManagerBase {
676702 }
677703 }
678704 }
679- this . registry . dropHandler ( handler . getTag ( ) ) ;
705+ this . detachGestureHandlerFromView ( handler , view ) ;
680706 }
681707}
0 commit comments