Browse Source

Always merge options with parent controller (#5606)

Until now, mergeOptions would merge with parent controller only if mergeOptions was called with
a componentId. This commit fixes the issue and makes options merge correctly even when called with a layoutId.
Guy Carmeli 4 years ago
parent
commit
0dd3315907
No account linked to committer's email address

+ 5
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ChildController.java View File

@@ -1,9 +1,6 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4
-import androidx.annotation.CallSuper;
5
-import androidx.core.view.ViewCompat;
6
-import androidx.core.view.WindowInsetsCompat;
7 4
 import android.view.View;
8 5
 import android.view.ViewGroup;
9 6
 
@@ -13,6 +10,10 @@ import com.reactnativenavigation.utils.StatusBarUtils;
13 10
 import com.reactnativenavigation.viewcontrollers.navigator.Navigator;
14 11
 import com.reactnativenavigation.views.Component;
15 12
 
13
+import androidx.annotation.CallSuper;
14
+import androidx.core.view.ViewCompat;
15
+import androidx.core.view.WindowInsetsCompat;
16
+
16 17
 public abstract class ChildController<T extends ViewGroup> extends ViewController<T>  {
17 18
     private final Presenter presenter;
18 19
     private final ChildControllersRegistry childRegistry;
@@ -70,6 +71,7 @@ public abstract class ChildController<T extends ViewGroup> extends ViewControlle
70 71
     public void mergeOptions(Options options) {
71 72
         if (options == Options.EMPTY) return;
72 73
         if (isViewShown()) presenter.mergeOptions(getView(), options);
74
+        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
73 75
         super.mergeOptions(options);
74 76
     }
75 77
 

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java View File

@@ -87,7 +87,6 @@ public class ComponentViewController extends ChildController<ComponentLayout> {
87 87
         if (options == Options.EMPTY) return;
88 88
         presenter.mergeOptions(getView(), options);
89 89
         super.mergeOptions(options);
90
-        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
91 90
     }
92 91
 
93 92
     @Override

+ 2
- 7
lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java View File

@@ -2,7 +2,6 @@ package com.reactnativenavigation.mocks;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.content.Context;
5
-import androidx.annotation.NonNull;
6 5
 import android.view.MotionEvent;
7 6
 
8 7
 import com.facebook.react.ReactInstanceManager;
@@ -16,6 +15,8 @@ import com.reactnativenavigation.views.ReactComponent;
16 15
 
17 16
 import org.mockito.Mockito;
18 17
 
18
+import androidx.annotation.NonNull;
19
+
19 20
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
20 21
 
21 22
 public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
@@ -51,12 +52,6 @@ public class SimpleViewController extends ChildController<SimpleViewController.S
51 52
         return "SimpleViewController " + getId();
52 53
     }
53 54
 
54
-    @Override
55
-    public void mergeOptions(Options options) {
56
-        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
57
-        super.mergeOptions(options);
58
-    }
59
-
60 55
     @Override
61 56
     public int getTopInset() {
62 57
         int statusBarInset = resolveCurrentOptions().statusBar.drawBehind.isTrue() ? 0 : 63;

+ 11
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllerTest.java View File

@@ -6,6 +6,7 @@ import com.reactnativenavigation.parse.Options;
6 6
 import com.reactnativenavigation.presentation.Presenter;
7 7
 import com.reactnativenavigation.viewcontrollers.ChildController;
8 8
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
9
+import com.reactnativenavigation.viewcontrollers.ParentController;
9 10
 
10 11
 import org.junit.Test;
11 12
 import org.mockito.Mockito;
@@ -17,6 +18,7 @@ import static org.mockito.Mockito.verify;
17 18
 
18 19
 public class ChildControllerTest extends BaseTest {
19 20
 
21
+    private ParentController parent;
20 22
     private ChildController uut;
21 23
     private ChildControllersRegistry childRegistry;
22 24
     private Presenter presenter;
@@ -32,6 +34,8 @@ public class ChildControllerTest extends BaseTest {
32 34
                 return resolvedOptions;
33 35
             }
34 36
         };
37
+        parent = Mockito.mock(ParentController.class);
38
+        uut.setParentController(parent);
35 39
     }
36 40
 
37 41
     @Test
@@ -63,6 +67,13 @@ public class ChildControllerTest extends BaseTest {
63 67
         verify(presenter, times(0)).mergeOptions(any(), any());
64 68
     }
65 69
 
70
+    @Test
71
+    public void mergeOptions_mergeWithParentViewController() {
72
+        Options options = new Options();
73
+        uut.mergeOptions(options);
74
+        verify(uut.getParentController()).mergeChildOptions(options, uut);
75
+    }
76
+
66 77
     @Test
67 78
     public void destroy() {
68 79
         uut.destroy();

+ 1
- 1
playground/android/build.gradle View File

@@ -29,7 +29,7 @@ allprojects {
29 29
             url "$rootDir/../../node_modules/react-native/android"
30 30
         }
31 31
         maven { url "$rootDir/../../node_modules/detox/Detox-android" }
32
-        maven { url 'https://jitpack.io' }
32
+        maven { url 'https://www.jitpack.io' }
33 33
         maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
34 34
         maven { url "$rootDir/../../node_modules/jsc-android/dist" }
35 35
     }

+ 1
- 1
playground/src/screens/FirstBottomTabScreen.js View File

@@ -60,7 +60,7 @@ class FirstBottomTabScreen extends React.Component {
60 60
     }
61 61
   });
62 62
 
63
-  switchTabByComponentId = () => Navigation.mergeOptions(this, {
63
+  switchTabByComponentId = () => Navigation.mergeOptions('SecondTab', {
64 64
     bottomTabs: {
65 65
       currentTabId: 'SecondTab'
66 66
     }