Просмотр исходного кода

Fixed bug where mergeOptions would incorrectly call applyOptions

* Use resolved options when applying options in ChildController
* mergeOptions only if view is visible
Guy Carmeli 6 лет назад
Родитель
Сommit
a5d01ba45a

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Просмотреть файл

@@ -23,9 +23,9 @@ import com.reactnativenavigation.utils.Now;
23 23
 import com.reactnativenavigation.utils.TypefaceLoader;
24 24
 import com.reactnativenavigation.utils.UiThread;
25 25
 import com.reactnativenavigation.utils.UiUtils;
26
-import com.reactnativenavigation.viewcontrollers.navigator.Navigator;
27 26
 import com.reactnativenavigation.viewcontrollers.ViewController;
28 27
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
28
+import com.reactnativenavigation.viewcontrollers.navigator.Navigator;
29 29
 
30 30
 import java.util.Map;
31 31
 
@@ -61,7 +61,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
61 61
 
62 62
 	@ReactMethod
63 63
 	public void setRoot(String commandId, ReadableMap rawLayoutTree, Promise promise) {
64
-		final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree).optJSONObject("root"));
64
+        final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree).optJSONObject("root"));
65 65
 		handle(() -> {
66 66
             navigator().setEventEmitter(eventEmitter);
67 67
             final ViewController viewController = newLayoutFactory().create(layoutTree);
@@ -81,7 +81,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
81 81
 
82 82
 	@ReactMethod
83 83
 	public void push(String commandId, String onComponentId, ReadableMap rawLayoutTree, Promise promise) {
84
-		final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree));
84
+        final LayoutNode layoutTree = LayoutNodeParser.parse(JSONParser.parse(rawLayoutTree));
85 85
 		handle(() -> {
86 86
             final ViewController viewController = newLayoutFactory().create(layoutTree);
87 87
             navigator().push(onComponentId, viewController, new NativeCommandListener(commandId, promise, eventEmitter, now));

+ 4
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ChildController.java Просмотреть файл

@@ -48,16 +48,17 @@ public abstract class ChildController<T extends ViewGroup> extends ViewControlle
48 48
     @Override
49 49
     public void applyOptions(Options options) {
50 50
         super.applyOptions(options);
51
-        presenter.applyOptions(getView(), options);
51
+        Options resolvedOptions = resolveCurrentOptions();
52
+        presenter.applyOptions(getView(), resolvedOptions);
52 53
         if (isRoot()) {
53
-            presenter.applyRootOptions(getView(), options);
54
+            presenter.applyRootOptions(getView(), resolvedOptions);
54 55
         }
55 56
     }
56 57
 
57 58
     @Override
58 59
     public void mergeOptions(Options options) {
59 60
         if (options == Options.EMPTY) return;
60
-        presenter.mergeOptions(getView(), options);
61
+        if (isViewShown()) presenter.mergeOptions(getView(), options);
61 62
         super.mergeOptions(options);
62 63
     }
63 64
 

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Просмотреть файл

@@ -108,7 +108,6 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
108 108
     public void mergeOptions(Options options) {
109 109
         this.initialOptions = this.initialOptions.mergeWith(options);
110 110
         this.options = this.options.mergeWith(options);
111
-        if (view != null) applyOptions(this.options);
112 111
         this.options.clearOneTimeOptions();
113 112
         initialOptions.clearOneTimeOptions();
114 113
     }

+ 12
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllerTest.java Просмотреть файл

@@ -21,12 +21,18 @@ public class ChildControllerTest extends BaseTest {
21 21
     private ChildController uut;
22 22
     private ChildControllersRegistry childRegistry;
23 23
     private OptionsPresenter presenter;
24
+    private Options resolvedOptions = new Options();
24 25
 
25 26
     @Override
26 27
     public void beforeEach() {
27 28
         childRegistry = spy(new ChildControllersRegistry());
28 29
         presenter = Mockito.mock(OptionsPresenter.class);
29
-        uut = new SimpleViewController(newActivity(), childRegistry, "childId", presenter, new Options());
30
+        uut = new SimpleViewController(newActivity(), childRegistry, "childId", presenter, new Options()) {
31
+            @Override
32
+            public Options resolveCurrentOptions() {
33
+                return resolvedOptions;
34
+            }
35
+        };
30 36
     }
31 37
 
32 38
     @Test
@@ -45,10 +51,9 @@ public class ChildControllerTest extends BaseTest {
45 51
 
46 52
     @Test
47 53
     public void applyOptions_applyRootOptionsIfRoot() {
48
-        addToParent(newActivity(), uut);
49
-        Options options = new Options();
50
-        uut.applyOptions(options);
51
-        verify(presenter, times(1)).applyRootOptions(uut.getView(), options);
54
+        newActivity().setContentView(uut.getView());
55
+        verify(presenter).applyOptions(uut.getView(), resolvedOptions);
56
+        verify(presenter).applyRootOptions(uut.getView(), resolvedOptions);
52 57
     }
53 58
 
54 59
     @Test
@@ -61,6 +66,8 @@ public class ChildControllerTest extends BaseTest {
61 66
 
62 67
     @Test
63 68
     public void mergeOptions() {
69
+        newActivity().setContentView(uut.getView());
70
+
64 71
         Options options = new Options();
65 72
         uut.mergeOptions(options);
66 73
         verify(presenter).mergeOptions(uut.getView(), options);