Browse Source

Force UiManager to measure SideMenu

Related to #2485 #2302 #1851 #1583
Guy Carmeli 6 years ago
parent
commit
b681887340

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

@@ -11,6 +11,7 @@ import com.facebook.react.ReactApplication;
11 11
 import com.facebook.react.ReactNativeHost;
12 12
 import com.facebook.react.ReactPackage;
13 13
 import com.facebook.react.bridge.ReactContext;
14
+import com.facebook.react.uimanager.UIManagerModule;
14 15
 import com.reactnativenavigation.bridge.EventEmitter;
15 16
 import com.reactnativenavigation.controllers.ActivityCallbacks;
16 17
 import com.reactnativenavigation.react.NavigationReactGateway;
@@ -92,6 +93,13 @@ public abstract class NavigationApplication extends Application implements React
92 93
         return eventEmitter;
93 94
     }
94 95
 
96
+    public UIManagerModule getUiManagerModule() {
97
+        return getReactGateway()
98
+                .getReactInstanceManager()
99
+                .getCurrentReactContext()
100
+                .getNativeModule(UIManagerModule.class);
101
+    }
102
+
95 103
     /**
96 104
      * @see ReactNativeHost#getJSMainModuleName()
97 105
      */

+ 12
- 7
android/app/src/main/java/com/reactnativenavigation/views/SideMenu.java View File

@@ -8,6 +8,7 @@ import android.view.View;
8 8
 import android.view.ViewGroup;
9 9
 import android.widget.RelativeLayout;
10 10
 
11
+import com.facebook.react.bridge.Callback;
11 12
 import com.reactnativenavigation.NavigationApplication;
12 13
 import com.reactnativenavigation.params.BaseScreenParams;
13 14
 import com.reactnativenavigation.params.SideMenuParams;
@@ -130,15 +131,19 @@ public class SideMenu extends DrawerLayout {
130 131
         sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
131 132
             @Override
132 133
             public void onDisplay() {
133
-                ViewGroup.LayoutParams lp = sideMenuView.getLayoutParams();
134
-                if (params != null
135
-                    && params.fixedWidth > 0) {
134
+                final ViewGroup.LayoutParams lp = sideMenuView.getLayoutParams();
135
+                if (params != null && params.fixedWidth > 0) {
136 136
                     lp.width = params.fixedWidth;
137
+                    sideMenuView.setLayoutParams(lp);
137 138
                 } else {
138
-                    lp.width = sideMenuView.getChildAt(0).getWidth();
139
+                    NavigationApplication.instance.getUiManagerModule().measure(sideMenuView.getId(), new Callback() {
140
+                        @Override
141
+                        public void invoke(Object... args) {
142
+                            lp.width = sideMenuView.getChildAt(0).getWidth();
143
+                            sideMenuView.setLayoutParams(lp);
144
+                        }
145
+                    });
139 146
                 }
140
-
141
-                sideMenuView.setLayoutParams(lp);
142 147
             }
143 148
         });
144 149
     }
@@ -176,4 +181,4 @@ public class SideMenu extends DrawerLayout {
176 181
             setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, params.side.gravity);
177 182
         }
178 183
     }
179
-}
184
+}