Browse Source

Measure SideMenu width according to react root view (#544)

Guy Carmeli 8 years ago
parent
commit
f75fb8d3a1

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/views/SideMenu.java View File

4
 import android.support.v4.view.GravityCompat;
4
 import android.support.v4.view.GravityCompat;
5
 import android.support.v4.widget.DrawerLayout;
5
 import android.support.v4.widget.DrawerLayout;
6
 import android.view.Gravity;
6
 import android.view.Gravity;
7
+import android.view.ViewGroup;
7
 import android.widget.RelativeLayout;
8
 import android.widget.RelativeLayout;
8
 
9
 
9
 import com.reactnativenavigation.params.SideMenuParams;
10
 import com.reactnativenavigation.params.SideMenuParams;
11
+import com.reactnativenavigation.screens.Screen;
10
 import com.reactnativenavigation.utils.ViewUtils;
12
 import com.reactnativenavigation.utils.ViewUtils;
11
 
13
 
12
 public class SideMenu extends DrawerLayout {
14
 public class SideMenu extends DrawerLayout {
71
         sideMenuView = new ContentView(getContext(), sideMenuParams.screenId, sideMenuParams.navigationParams);
73
         sideMenuView = new ContentView(getContext(), sideMenuParams.screenId, sideMenuParams.navigationParams);
72
         LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
74
         LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
73
         lp.gravity = Gravity.START;
75
         lp.gravity = Gravity.START;
76
+        setSideMenuWidth();
74
         addView(sideMenuView, lp);
77
         addView(sideMenuView, lp);
75
     }
78
     }
76
 
79
 
80
+    private void setSideMenuWidth() {
81
+        sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
82
+            @Override
83
+            public void onDisplay() {
84
+                ViewGroup.LayoutParams lp = sideMenuView.getLayoutParams();
85
+                lp.width = sideMenuView.getChildAt(0).getWidth();
86
+                sideMenuView.setLayoutParams(lp);
87
+            }
88
+        });
89
+    }
90
+
77
     private void setStyle(SideMenuParams params) {
91
     private void setStyle(SideMenuParams params) {
78
         if (params.disableOpenGesture) {
92
         if (params.disableOpenGesture) {
79
             setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
93
             setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);