Browse Source

Update side menu options on open / close callback (#4745)

gosuperninja 6 years ago
parent
commit
43f05ee015

+ 29
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuController.java View File

11
 
11
 
12
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.parse.Options;
13
 import com.reactnativenavigation.parse.SideMenuOptions;
13
 import com.reactnativenavigation.parse.SideMenuOptions;
14
+import com.reactnativenavigation.parse.params.Bool;
14
 import com.reactnativenavigation.presentation.Presenter;
15
 import com.reactnativenavigation.presentation.Presenter;
15
 import com.reactnativenavigation.presentation.SideMenuPresenter;
16
 import com.reactnativenavigation.presentation.SideMenuPresenter;
16
 import com.reactnativenavigation.utils.CommandListener;
17
 import com.reactnativenavigation.utils.CommandListener;
103
         return options;
104
         return options;
104
     }
105
     }
105
 
106
 
107
+    //For onDrawerOpened and onDrawerClosed :
108
+    //Merge the options to the current state, if this happened due to a gesture we need to
109
+    //update the option state
110
+
106
     @Override
111
     @Override
107
     public void onDrawerOpened(@NonNull View drawerView) {
112
     public void onDrawerOpened(@NonNull View drawerView) {
108
-        (left != null && drawerView.equals(left.getView()) ? left : right).onViewAppeared();
113
+        ViewController view = this.getMatchingView(drawerView);
114
+        view.mergeOptions(this.getOptionsWithVisability(this.viewIsLeft(drawerView), true));
115
+        view.onViewAppeared();
109
     }
116
     }
110
 
117
 
111
     @Override
118
     @Override
112
     public void onDrawerClosed(@NonNull View drawerView) {
119
     public void onDrawerClosed(@NonNull View drawerView) {
113
-        (left != null && drawerView.equals(left.getView()) ? left : right).onViewDisappear();
120
+        ViewController view = this.getMatchingView(drawerView);
121
+        view.mergeOptions(this.getOptionsWithVisability(this.viewIsLeft(drawerView), false));
122
+        view.onViewDisappear();
114
     }
123
     }
115
 
124
 
116
     @Override
125
     @Override
154
         return height;
163
         return height;
155
     }
164
     }
156
 
165
 
166
+    private ViewController getMatchingView (View drawerView) {
167
+        return this.viewIsLeft(drawerView) ? left : right;
168
+    }
169
+
170
+    private boolean viewIsLeft (View drawerView) {
171
+        return (left != null && drawerView.equals(left.getView()));
172
+    }
173
+
174
+    private Options getOptionsWithVisability ( boolean isLeft, boolean visible ) {
175
+        Options options = new Options();
176
+        if (isLeft) {
177
+            options.sideMenuRootOptions.left.visible = new Bool(visible);
178
+        } else {
179
+            options.sideMenuRootOptions.right.visible = new Bool(visible);
180
+        }
181
+        return options;
182
+    }
183
+
157
     @Override
184
     @Override
158
     public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
185
     public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
159
 
186