Browse Source

Force UiManager to measure SideMenu

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

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

11
 import com.facebook.react.ReactNativeHost;
11
 import com.facebook.react.ReactNativeHost;
12
 import com.facebook.react.ReactPackage;
12
 import com.facebook.react.ReactPackage;
13
 import com.facebook.react.bridge.ReactContext;
13
 import com.facebook.react.bridge.ReactContext;
14
+import com.facebook.react.uimanager.UIManagerModule;
14
 import com.reactnativenavigation.bridge.EventEmitter;
15
 import com.reactnativenavigation.bridge.EventEmitter;
15
 import com.reactnativenavigation.controllers.ActivityCallbacks;
16
 import com.reactnativenavigation.controllers.ActivityCallbacks;
16
 import com.reactnativenavigation.react.NavigationReactGateway;
17
 import com.reactnativenavigation.react.NavigationReactGateway;
92
         return eventEmitter;
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
      * @see ReactNativeHost#getJSMainModuleName()
104
      * @see ReactNativeHost#getJSMainModuleName()
97
      */
105
      */

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

8
 import android.view.ViewGroup;
8
 import android.view.ViewGroup;
9
 import android.widget.RelativeLayout;
9
 import android.widget.RelativeLayout;
10
 
10
 
11
+import com.facebook.react.bridge.Callback;
11
 import com.reactnativenavigation.NavigationApplication;
12
 import com.reactnativenavigation.NavigationApplication;
12
 import com.reactnativenavigation.params.BaseScreenParams;
13
 import com.reactnativenavigation.params.BaseScreenParams;
13
 import com.reactnativenavigation.params.SideMenuParams;
14
 import com.reactnativenavigation.params.SideMenuParams;
130
         sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
131
         sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
131
             @Override
132
             @Override
132
             public void onDisplay() {
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
                     lp.width = params.fixedWidth;
136
                     lp.width = params.fixedWidth;
137
+                    sideMenuView.setLayoutParams(lp);
137
                 } else {
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
             setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, params.side.gravity);
181
             setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, params.side.gravity);
177
         }
182
         }
178
     }
183
     }
179
-}
184
+}