Selaa lähdekoodia

Clear sideMenu's visible options after applying (#4937)

* Clear sideMenu's visible options after applying

* If mergeOptions is called before a controller is attached to a parent - don’t clear one time options as they haven’t been applied yet.
Alberto Blanco 5 vuotta sitten
vanhempi
commit
283f226f55

+ 3
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java Näytä tiedosto

@@ -3,6 +3,7 @@ package com.reactnativenavigation.parse;
3 3
 import android.support.annotation.CheckResult;
4 4
 import android.support.annotation.NonNull;
5 5
 
6
+import com.reactnativenavigation.parse.params.NullBool;
6 7
 import com.reactnativenavigation.parse.params.NullNumber;
7 8
 import com.reactnativenavigation.parse.params.NullText;
8 9
 import com.reactnativenavigation.utils.TypefaceLoader;
@@ -146,6 +147,8 @@ public class Options {
146 147
     }
147 148
 
148 149
     public Options clearOneTimeOptions() {
150
+        sideMenuRootOptions.left.visible = new NullBool();
151
+        sideMenuRootOptions.right.visible = new NullBool();
149 152
         bottomTabsOptions.currentTabId = new NullText();
150 153
         bottomTabsOptions.currentTabIndex = new NullNumber();
151 154
         return this;

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Näytä tiedosto

@@ -117,8 +117,10 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
117 117
     public void mergeOptions(Options options) {
118 118
         this.initialOptions = this.initialOptions.mergeWith(options);
119 119
         this.options = this.options.mergeWith(options);
120
-        this.options.clearOneTimeOptions();
121
-        initialOptions.clearOneTimeOptions();
120
+        if (getParentController() != null) {
121
+            this.options.clearOneTimeOptions();
122
+            initialOptions.clearOneTimeOptions();
123
+        }
122 124
     }
123 125
 
124 126
     @CallSuper

+ 2
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java Näytä tiedosto

@@ -25,6 +25,7 @@ import com.reactnativenavigation.utils.ImageLoader;
25 25
 import com.reactnativenavigation.utils.OptionHelper;
26 26
 import com.reactnativenavigation.utils.ViewUtils;
27 27
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
28
+import com.reactnativenavigation.viewcontrollers.ParentController;
28 29
 import com.reactnativenavigation.viewcontrollers.ViewController;
29 30
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
30 31
 import com.reactnativenavigation.views.BottomTabs;
@@ -92,6 +93,7 @@ public class BottomTabsControllerTest extends BaseTest {
92 93
         presenter = spy(new BottomTabsPresenter(tabs, new Options()));
93 94
         tabsAttacher = spy(new BottomTabsAttacher(tabs, presenter));
94 95
         uut = createBottomTabs();
96
+        uut.setParentController(Mockito.mock(ParentController.class));
95 97
         activity.setContentView(uut.getView());
96 98
     }
97 99
 

+ 9
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/sidemenu/SideMenuControllerTest.java Näytä tiedosto

@@ -263,14 +263,18 @@ public class SideMenuControllerTest extends BaseTest {
263 263
     }
264 264
 
265 265
     private void openDrawerAndAssertVisibility(ViewController side, Functions.FuncR1<ViewController, SideMenuOptions> opt) {
266
-        assertThat(opt.run(side).visible.isTrue()).isFalse();
267
-        uut.onDrawerOpened(side.getView());
268
-        assertThat(opt.run(side).visible.isTrue()).isTrue();
266
+        Options options = new Options();
267
+        (side == left ? options.sideMenuRootOptions.left : options.sideMenuRootOptions.right).visible = new Bool(true);
268
+        uut.mergeOptions(options);
269
+        assertThat(uut.getView().isDrawerVisible(side.getView())).isTrue();
270
+        assertThat(opt.run(side).visible.isFalseOrUndefined()).isTrue();
269 271
     }
270 272
 
271 273
     private void closeDrawerAndAssertVisibility(ViewController side, Functions.FuncR1<ViewController, SideMenuOptions> opt) {
272
-        assertThat(opt.run(side).visible.isTrue()).isTrue();
273
-        uut.onDrawerClosed(side.getView());
274
+        Options options = new Options();
275
+        (side == left ? options.sideMenuRootOptions.left : options.sideMenuRootOptions.right).visible = new Bool(false);
276
+        uut.mergeOptions(options);
277
+        assertThat(uut.getView().isDrawerVisible(side.getView())).isFalse();
274 278
         assertThat(opt.run(side).visible.isTrue()).isFalse();
275 279
     }
276 280