1515import com .swmansion .gesturehandler .GestureHandler ;
1616import com .swmansion .gesturehandler .ViewConfigurationHelper ;
1717
18+ import java .util .ArrayList ;
19+
1820public class PageLayout extends org .nativescript .widgets .GridLayout {
19- public PageLayout (Context context ) {
21+ public PageLayout (Context context , int rootGestureTag ) {
2022 super (context );
23+ mRootGestureTag = rootGestureTag ;
2124 addRow (new ItemSpec (1 , GridUnitType .auto ));
2225 addRow (new ItemSpec (1 , GridUnitType .star ));
2326 }
24- private final static int GESTURE_HANDLER_TAG = -12345 ;
2527
28+ private int mRootGestureTag ;
2629 private GestureHandlerOrchestrator mOrchestrator ;
2730 private GestureHandlerRegistryImpl mRegistry ;
2831 private ViewConfigurationHelper configurationHelper ;
@@ -31,6 +34,7 @@ public PageLayout(Context context) {
3134 private boolean mShouldIntercept = false ;
3235 private boolean mPassingTouch = false ;
3336 private boolean mDispatchToOrchestra = true ;
37+ private boolean mShouldAddRootGesture = true ;
3438
3539 public void setShouldIntercept (boolean value ) {
3640 if (GestureHandler .debug ) {
@@ -42,6 +46,13 @@ public void setShouldIntercept(boolean value) {
4246 public void setPassingTouch (boolean value ) {
4347 this .mPassingTouch = value ;
4448 }
49+ public void setShouldAddRootGesture (boolean value ) {
50+ this .mShouldAddRootGesture = value ;
51+ }
52+
53+ public int getRootGestureTag () {
54+ return mRootGestureTag ;
55+ }
4556
4657 public void setDispatchToOrchestra (boolean value ) {
4758 if (GestureHandler .debug ) {
@@ -71,12 +82,21 @@ public void tryCancelAllHandlers() {
7182 if (GestureHandler .debug ) {
7283 Log .d ("JS" , "PageLayout tryCancelAllHandlers " );
7384 }
74- // In order to cancel handlers we activate handler that is hooked to the root view
75- if (this .rootGestureHandler != null && this .rootGestureHandler .getState () == com .swmansion .gesturehandler .GestureHandler .STATE_BEGAN ) {
76- // Try activate main JS handler
77- this .rootGestureHandler .activate ();
78- this .rootGestureHandler .end ();
85+ ArrayList <GestureHandler > handlers = this .mRegistry .getAllHandlers ();
86+ if (handlers != null ) {
87+ for (int i = 0 ; i < handlers .size (); i ++) {
88+ GestureHandler handler = handlers .get (i );
89+ if (handler != this .rootGestureHandler ) {
90+ handler .cancel ();
91+ }
92+ }
7993 }
94+ // In order to cancel handlers we activate handler that is hooked to the root view
95+ // if (this.rootGestureHandler != null && this.rootGestureHandler.getState() == com.swmansion.gesturehandler.GestureHandler.STATE_BEGAN) {
96+ // // Try activate main JS handler
97+ // this.rootGestureHandler.activate();
98+ // this.rootGestureHandler.end();
99+ // }
80100 }
81101
82102 public void requestDisallowInterceptTouchEvent (boolean disallowIntercept ) {
@@ -156,9 +176,9 @@ public View getChildInDrawingOrderAtIndex(ViewGroup parent, int index) {
156176 this .mOrchestrator .setMinimumAlphaForTraversal (0.01f );
157177
158178 this .rootGestureHandler = new RootViewGestureHandler ();
159- this .rootGestureHandler .setTag (GESTURE_HANDLER_TAG );
179+ this .rootGestureHandler .setTag (mRootGestureTag );
160180 this .mRegistry .registerHandler (this .rootGestureHandler );
161- this .mRegistry .attachHandlerToView (GESTURE_HANDLER_TAG , this );
181+ this .mRegistry .attachHandlerToView (mRootGestureTag , this );
162182 }
163183
164184 public void tearDown () {
0 commit comments