Selaa lähdekoodia

A few improvements for Android (#3150)

1. Sideenus weren't clickable on Android. It seems the order in which
child views were being added to parent controllers, left or right
before center, were affecting the ability to interact with the menus.
I've changed the code to always add them in a specific order: center,
then left, then right.

I believe this closes issue #2835.

  https://github.com/wix/react-native-navigation/issues/2835.

2. On Android, merging options to open a menu works.

  Navigation.mergeOptions(currentComponentId, {
      sideMenu: {
          left: {
              visible: true
          }
      }
  })

But merging options to close it wasn't working.

  Navigation.mergeOptions(currentComponentId, {
      sideMenu: {
          left: {
              visible: false
          }
      }
  })

3. The bottom tabs controller was reserving a margin space for the tabs
when switching from one to another, regardless of its visibility
settings.
Rafael Viotti 6 vuotta sitten
vanhempi
commit
f57099c0db

+ 28
- 7
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java Näytä tiedosto

@@ -75,24 +75,45 @@ public class LayoutFactory {
75 75
 	}
76 76
 
77 77
     private ViewController createSideMenuRoot(LayoutNode node) {
78
-        SideMenuController sideMenuController = new SideMenuController(activity, childRegistry, node.id, parseNodeOptions(node));
78
+		SideMenuController sideMenuController = new SideMenuController(activity, childRegistry, node.id, parseNodeOptions(node));
79
+		ViewController childControllerCenter = null, childControllerLeft = null, childControllerRight = null;
80
+
79 81
 		for (LayoutNode child : node.children) {
80
-			ViewController childController = create(child);
81
-            childController.setParentController(sideMenuController);
82 82
 			switch (child.type) {
83 83
 				case SideMenuCenter:
84
-					sideMenuController.setCenterController(childController);
84
+					childControllerCenter = create(child);
85
+					childControllerCenter.setParentController(sideMenuController);
85 86
 					break;
86 87
 				case SideMenuLeft:
87
-					sideMenuController.setLeftController(childController);
88
+					childControllerLeft = create(child);
89
+					childControllerLeft.setParentController(sideMenuController);
88 90
 					break;
89 91
 				case SideMenuRight:
90
-					sideMenuController.setRightController(childController);
92
+					childControllerRight = create(child);
93
+					childControllerRight.setParentController(sideMenuController);
91 94
 					break;
92 95
 				default:
93 96
 					throw new IllegalArgumentException("Invalid node type in sideMenu: " + node.type);
94 97
 			}
95
-        }
98
+		}
99
+
100
+		// Need to set the center controller first, otherwise "onPress" events on the JS components
101
+		// of the left and right drawers are not handled properly.
102
+		//
103
+		// See https://github.com/wix/react-native-navigation/issues/2835
104
+		//
105
+		if (childControllerCenter != null) {
106
+			sideMenuController.setCenterController(childControllerCenter);
107
+		}
108
+
109
+		if (childControllerLeft != null) {
110
+			sideMenuController.setLeftController(childControllerLeft);
111
+		}
112
+
113
+		if (childControllerRight != null) {
114
+			sideMenuController.setRightController(childControllerRight);
115
+		}
116
+
96 117
 		return sideMenuController;
97 118
 	}
98 119
 

+ 3
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabsOptionsPresenter.java Näytä tiedosto

@@ -52,7 +52,9 @@ public class BottomTabsOptionsPresenter {
52 52
         if (options.drawBehind.isTrue()) {
53 53
             lp.bottomMargin = 0;
54 54
         }
55
-        if (options.drawBehind.isFalseOrUndefined()) {
55
+
56
+        // Allocate space for the bottom tabs only if it is visible and it should not draw behind.
57
+        if (options.visible.isTrueOrUndefined() && options.drawBehind.isFalseOrUndefined()) {
56 58
             lp.bottomMargin = bottomTabs.getHeight();
57 59
         }
58 60
 

+ 7
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/SideMenuOptionsPresenter.java Näytä tiedosto

@@ -16,9 +16,16 @@ public class SideMenuOptionsPresenter {
16 16
     public void present(SideMenuRootOptions options) {
17 17
         if (options.left.visible.isTrue()) {
18 18
             sideMenu.openDrawer(Gravity.LEFT);
19
+
20
+        } else if (options.left.visible.isFalse() && sideMenu.isDrawerOpen(Gravity.LEFT)) {
21
+            sideMenu.closeDrawer(Gravity.LEFT);
19 22
         }
23
+
20 24
         if (options.right.visible.isTrue()) {
21 25
             sideMenu.openDrawer(Gravity.RIGHT);
26
+
27
+        } else if (options.right.visible.isFalse() && sideMenu.isDrawerOpen(Gravity.RIGHT)){
28
+            sideMenu.closeDrawer(Gravity.RIGHT);
22 29
         }
23 30
     }
24 31
 }