Parcourir la source

Disable side menu (including using swipe gesture) for a given component on Android (#4142) (#4143)

Mo Alraddadi il y a 6 ans
Parent
révision
9fdbc6adc0

+ 25
- 14
lib/android/app/src/main/java/com/reactnativenavigation/presentation/SideMenuPresenter.java Voir le fichier

@@ -13,7 +13,32 @@ public class SideMenuPresenter {
13 13
         this.sideMenu = sideMenu;
14 14
     }
15 15
 
16
+    /**
17
+     * Called when initializing the sideMenu DrawerLayout.
18
+     *
19
+     * @param options Side menu options
20
+     */
21
+    public void applyInitialOptions(SideMenuRootOptions options) {
22
+        if (options.left.enabled.isFalse()) {
23
+            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
24
+        }
25
+        else  if (options.left.enabled.isTrue()) {
26
+            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
27
+        }
28
+
29
+        if (options.right.enabled.isFalse()) {
30
+            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
31
+        }
32
+        else  if (options.right.enabled.isTrue()) {
33
+            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
34
+        }
35
+    }
36
+
16 37
     public void present(SideMenuRootOptions options) {
38
+        // TODO: Not sure why we call these options when we show the DrawerLayout rather than when initializing it.
39
+        // TODO: (i.e. `setDrawerLockMode()` is supposed to be called when the DrawerLayout is initialized.
40
+        applyInitialOptions(options);
41
+
17 42
         if (options.left.visible.isTrue()) {
18 43
             sideMenu.openDrawer(Gravity.LEFT);
19 44
 
@@ -27,20 +52,6 @@ public class SideMenuPresenter {
27 52
         } else if (options.right.visible.isFalse() && sideMenu.isDrawerOpen(Gravity.RIGHT)){
28 53
             sideMenu.closeDrawer(Gravity.RIGHT);
29 54
         }
30
-
31
-        if (options.left.enabled.isFalse()) {
32
-            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT);
33
-        }
34
-        else  if (options.left.enabled.isTrue()) {
35
-            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
36
-        }
37
-
38
-        if (options.right.enabled.isFalse()) {
39
-            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
40
-        }
41
-        else  if (options.right.enabled.isTrue()) {
42
-            sideMenu.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
43
-        }
44 55
     }
45 56
 
46 57
     public boolean handleBack() {

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuController.java Voir le fichier

@@ -72,6 +72,7 @@ public class SideMenuController extends ParentController<DrawerLayout> {
72 72
     @Override
73 73
     public void applyChildOptions(Options options, Component child) {
74 74
         super.applyChildOptions(options, child);
75
+        presenter.applyInitialOptions(options.sideMenuRootOptions);
75 76
         performOnParentController(parentController ->
76 77
                 ((ParentController) parentController).applyChildOptions(this.options, child)
77 78
         );