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

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

87
         if (options == Options.EMPTY) return;
87
         if (options == Options.EMPTY) return;
88
         presenter.mergeOptions(getView(), options);
88
         presenter.mergeOptions(getView(), options);
89
         super.mergeOptions(options);
89
         super.mergeOptions(options);
90
-        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
91
     }
90
     }
92
 
91
 
93
     @Override
92
     @Override

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

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.content.Context;
4
 import android.content.Context;
5
-import androidx.annotation.NonNull;
6
 import android.view.MotionEvent;
5
 import android.view.MotionEvent;
7
 
6
 
8
 import com.facebook.react.ReactInstanceManager;
7
 import com.facebook.react.ReactInstanceManager;
16
 
15
 
17
 import org.mockito.Mockito;
16
 import org.mockito.Mockito;
18
 
17
 
18
+import androidx.annotation.NonNull;
19
+
19
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
20
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
20
 
21
 
21
 public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
22
 public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
51
         return "SimpleViewController " + getId();
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
     @Override
55
     @Override
61
     public int getTopInset() {
56
     public int getTopInset() {
62
         int statusBarInset = resolveCurrentOptions().statusBar.drawBehind.isTrue() ? 0 : 63;
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
 import com.reactnativenavigation.presentation.Presenter;
6
 import com.reactnativenavigation.presentation.Presenter;
7
 import com.reactnativenavigation.viewcontrollers.ChildController;
7
 import com.reactnativenavigation.viewcontrollers.ChildController;
8
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
8
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
9
+import com.reactnativenavigation.viewcontrollers.ParentController;
9
 
10
 
10
 import org.junit.Test;
11
 import org.junit.Test;
11
 import org.mockito.Mockito;
12
 import org.mockito.Mockito;
17
 
18
 
18
 public class ChildControllerTest extends BaseTest {
19
 public class ChildControllerTest extends BaseTest {
19
 
20
 
21
+    private ParentController parent;
20
     private ChildController uut;
22
     private ChildController uut;
21
     private ChildControllersRegistry childRegistry;
23
     private ChildControllersRegistry childRegistry;
22
     private Presenter presenter;
24
     private Presenter presenter;
32
                 return resolvedOptions;
34
                 return resolvedOptions;
33
             }
35
             }
34
         };
36
         };
37
+        parent = Mockito.mock(ParentController.class);
38
+        uut.setParentController(parent);
35
     }
39
     }
36
 
40
 
37
     @Test
41
     @Test
63
         verify(presenter, times(0)).mergeOptions(any(), any());
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
     @Test
77
     @Test
67
     public void destroy() {
78
     public void destroy() {
68
         uut.destroy();
79
         uut.destroy();

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

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

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

60
     }
60
     }
61
   });
61
   });
62
 
62
 
63
-  switchTabByComponentId = () => Navigation.mergeOptions(this, {
63
+  switchTabByComponentId = () => Navigation.mergeOptions('SecondTab', {
64
     bottomTabs: {
64
     bottomTabs: {
65
       currentTabId: 'SecondTab'
65
       currentTabId: 'SecondTab'
66
     }
66
     }