Browse Source

Added optional fixedWidth property to the Android side menu (#2380)

* v1.1.314 [ci skip]

* Added optional fixedWidth property to the Android side menu

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

* Added fixedWidth drawer param to te top-level-api doc
Ioannis Kokkinidis 6 years ago
parent
commit
4fe86525cb

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/SideMenuParams.java View File

5
 public class SideMenuParams extends BaseScreenParams {
5
 public class SideMenuParams extends BaseScreenParams {
6
     public boolean disableOpenGesture;
6
     public boolean disableOpenGesture;
7
     public SideMenu.Side side;
7
     public SideMenu.Side side;
8
+    public int fixedWidth;
8
 }
9
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/SideMenuParamsParser.java View File

23
         result.screenId = sideMenu.getString("screenId");
23
         result.screenId = sideMenu.getString("screenId");
24
         result.navigationParams = new NavigationParams(sideMenu.getBundle("navigationParams"));
24
         result.navigationParams = new NavigationParams(sideMenu.getBundle("navigationParams"));
25
         result.disableOpenGesture = sideMenu.getBoolean("disableOpenGesture", false);
25
         result.disableOpenGesture = sideMenu.getBoolean("disableOpenGesture", false);
26
+        result.fixedWidth = sideMenu.getInt("fixedWidth", 0);
26
         result.side = side;
27
         result.side = side;
27
         return result;
28
         return result;
28
     }
29
     }

+ 9
- 3
android/app/src/main/java/com/reactnativenavigation/views/SideMenu.java View File

121
         ContentView sideMenuView = new ContentView(getContext(), params.screenId, params.navigationParams);
121
         ContentView sideMenuView = new ContentView(getContext(), params.screenId, params.navigationParams);
122
         LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
122
         LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
123
         lp.gravity = params.side.gravity;
123
         lp.gravity = params.side.gravity;
124
-        setSideMenuWidth(sideMenuView);
124
+        setSideMenuWidth(sideMenuView, params);
125
         addView(sideMenuView, lp);
125
         addView(sideMenuView, lp);
126
         return sideMenuView;
126
         return sideMenuView;
127
     }
127
     }
128
 
128
 
129
-    private void setSideMenuWidth(final ContentView sideMenuView) {
129
+    private void setSideMenuWidth(final ContentView sideMenuView, @Nullable final SideMenuParams params) {
130
         sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
130
         sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
131
             @Override
131
             @Override
132
             public void onDisplay() {
132
             public void onDisplay() {
133
                 ViewGroup.LayoutParams lp = sideMenuView.getLayoutParams();
133
                 ViewGroup.LayoutParams lp = sideMenuView.getLayoutParams();
134
-                lp.width = sideMenuView.getChildAt(0).getWidth();
134
+                if (params != null
135
+                    && params.fixedWidth > 0) {
136
+                    lp.width = params.fixedWidth;
137
+                } else {
138
+                    lp.width = sideMenuView.getChildAt(0).getWidth();
139
+                }
140
+
135
                 sideMenuView.setLayoutParams(lp);
141
                 sideMenuView.setLayoutParams(lp);
136
             }
142
             }
137
         });
143
         });

+ 5
- 1
docs/top-level-api.md View File

65
   drawer: { // optional, add this if you want a side menu drawer in your app
65
   drawer: { // optional, add this if you want a side menu drawer in your app
66
     left: { // optional, define if you want a drawer from the left
66
     left: { // optional, define if you want a drawer from the left
67
       screen: 'example.FirstSideMenu', // unique ID registered with Navigation.registerScreen
67
       screen: 'example.FirstSideMenu', // unique ID registered with Navigation.registerScreen
68
-      passProps: {} // simple serializable object that will pass as props to all top screens (optional)
68
+      passProps: {} // simple serializable object that will pass as props to all top screens (optional),
69
+      fixedWidth: 500, // a fixed width you want your left drawer to have (optional)
69
     },
70
     },
70
     right: { // optional, define if you want a drawer from the right
71
     right: { // optional, define if you want a drawer from the right
71
       screen: 'example.SecondSideMenu', // unique ID registered with Navigation.registerScreen
72
       screen: 'example.SecondSideMenu', // unique ID registered with Navigation.registerScreen
72
       passProps: {} // simple serializable object that will pass as props to all top screens (optional)
73
       passProps: {} // simple serializable object that will pass as props to all top screens (optional)
74
+      fixedWidth: 500, // a fixed width you want your right drawer to have (optional)
73
     },
75
     },
74
     style: { // ( iOS only )
76
     style: { // ( iOS only )
75
       drawerShadow: true, // optional, add this if you want a side menu drawer shadow
77
       drawerShadow: true, // optional, add this if you want a side menu drawer shadow
105
       screen: 'example.FirstSideMenu', // unique ID registered with Navigation.registerScreen
107
       screen: 'example.FirstSideMenu', // unique ID registered with Navigation.registerScreen
106
       passProps: {}, // simple serializable object that will pass as props to all top screens (optional)
108
       passProps: {}, // simple serializable object that will pass as props to all top screens (optional)
107
       disableOpenGesture: false // can the drawer be opened with a swipe instead of button (optional, Android only)
109
       disableOpenGesture: false // can the drawer be opened with a swipe instead of button (optional, Android only)
110
+      fixedWidth: 500, // a fixed width you want your left drawer to have (optional)
108
     },
111
     },
109
     right: { // optional, define if you want a drawer from the right
112
     right: { // optional, define if you want a drawer from the right
110
       screen: 'example.SecondSideMenu', // unique ID registered with Navigation.registerScreen
113
       screen: 'example.SecondSideMenu', // unique ID registered with Navigation.registerScreen
111
       passProps: {} // simple serializable object that will pass as props to all top screens (optional)
114
       passProps: {} // simple serializable object that will pass as props to all top screens (optional)
112
       disableOpenGesture: false // can the drawer be opened with a swipe instead of button (optional, Android only)
115
       disableOpenGesture: false // can the drawer be opened with a swipe instead of button (optional, Android only)
116
+      fixedWidth: 500, // a fixed width you want your right drawer to have (optional)
113
     },
117
     },
114
     style: { // ( iOS only )
118
     style: { // ( iOS only )
115
       drawerShadow: true, // optional, add this if you want a side menu drawer shadow
119
       drawerShadow: true, // optional, add this if you want a side menu drawer shadow

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "react-native-navigation",
2
   "name": "react-native-navigation",
3
-  "version": "1.1.85",
3
+  "version": "1.1.314",
4
   "description": "React Native Navigation - truly native navigation for iOS and Android",
4
   "description": "React Native Navigation - truly native navigation for iOS and Android",
5
   "license": "MIT",
5
   "license": "MIT",
6
   "nativePackage": true,
6
   "nativePackage": true,

+ 8
- 2
src/deprecated/platformSpecificDeprecated.android.js View File

257
       result[key] = adaptNavigationParams(result[key]);
257
       result[key] = adaptNavigationParams(result[key]);
258
       result[key].passProps = drawer[key].passProps;
258
       result[key].passProps = drawer[key].passProps;
259
       if (drawer.disableOpenGesture) {
259
       if (drawer.disableOpenGesture) {
260
-        result[key].disableOpenGesture = drawer.disableOpenGesture;
260
+        result[key].disableOpenGesture = parseInt(drawer.disableOpenGesture);
261
       } else {
261
       } else {
262
-        result[key].disableOpenGesture = drawer[key].disableOpenGesture;
262
+        let fixedWidth = drawer[key].disableOpenGesture;
263
+        result[key].disableOpenGesture = fixedWidth ? parseInt(fixedWidth) : null;
264
+      }
265
+      if (drawer.fixedWidth) {
266
+        result[key].fixedWidth = drawer.fixedWidth;
267
+      } else {
268
+        result[key].fixedWidth = drawer[key].fixedWidth;
263
       }
269
       }
264
       
270
       
265
     } else {
271
     } else {