Ver código fonte

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 7 anos atrás
pai
commit
4fe86525cb

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/SideMenuParams.java Ver arquivo

@@ -5,4 +5,5 @@ import com.reactnativenavigation.views.SideMenu;
5 5
 public class SideMenuParams extends BaseScreenParams {
6 6
     public boolean disableOpenGesture;
7 7
     public SideMenu.Side side;
8
+    public int fixedWidth;
8 9
 }

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

@@ -23,6 +23,7 @@ class SideMenuParamsParser extends Parser {
23 23
         result.screenId = sideMenu.getString("screenId");
24 24
         result.navigationParams = new NavigationParams(sideMenu.getBundle("navigationParams"));
25 25
         result.disableOpenGesture = sideMenu.getBoolean("disableOpenGesture", false);
26
+        result.fixedWidth = sideMenu.getInt("fixedWidth", 0);
26 27
         result.side = side;
27 28
         return result;
28 29
     }

+ 9
- 3
android/app/src/main/java/com/reactnativenavigation/views/SideMenu.java Ver arquivo

@@ -121,17 +121,23 @@ public class SideMenu extends DrawerLayout {
121 121
         ContentView sideMenuView = new ContentView(getContext(), params.screenId, params.navigationParams);
122 122
         LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
123 123
         lp.gravity = params.side.gravity;
124
-        setSideMenuWidth(sideMenuView);
124
+        setSideMenuWidth(sideMenuView, params);
125 125
         addView(sideMenuView, lp);
126 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 130
         sideMenuView.setOnDisplayListener(new Screen.OnDisplayListener() {
131 131
             @Override
132 132
             public void onDisplay() {
133 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 141
                 sideMenuView.setLayoutParams(lp);
136 142
             }
137 143
         });

+ 5
- 1
docs/top-level-api.md Ver arquivo

@@ -65,11 +65,13 @@ Navigation.startTabBasedApp({
65 65
   drawer: { // optional, add this if you want a side menu drawer in your app
66 66
     left: { // optional, define if you want a drawer from the left
67 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 71
     right: { // optional, define if you want a drawer from the right
71 72
       screen: 'example.SecondSideMenu', // unique ID registered with Navigation.registerScreen
72 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 76
     style: { // ( iOS only )
75 77
       drawerShadow: true, // optional, add this if you want a side menu drawer shadow
@@ -105,11 +107,13 @@ Navigation.startSingleScreenApp({
105 107
       screen: 'example.FirstSideMenu', // unique ID registered with Navigation.registerScreen
106 108
       passProps: {}, // simple serializable object that will pass as props to all top screens (optional)
107 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 112
     right: { // optional, define if you want a drawer from the right
110 113
       screen: 'example.SecondSideMenu', // unique ID registered with Navigation.registerScreen
111 114
       passProps: {} // simple serializable object that will pass as props to all top screens (optional)
112 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 118
     style: { // ( iOS only )
115 119
       drawerShadow: true, // optional, add this if you want a side menu drawer shadow

+ 1
- 1
package.json Ver arquivo

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

+ 8
- 2
src/deprecated/platformSpecificDeprecated.android.js Ver arquivo

@@ -257,9 +257,15 @@ function convertDrawerParamsToSideMenuParams(drawerParams) {
257 257
       result[key] = adaptNavigationParams(result[key]);
258 258
       result[key].passProps = drawer[key].passProps;
259 259
       if (drawer.disableOpenGesture) {
260
-        result[key].disableOpenGesture = drawer.disableOpenGesture;
260
+        result[key].disableOpenGesture = parseInt(drawer.disableOpenGesture);
261 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 271
     } else {