Browse Source

Use resolved child options when applying stack child options

When a stack’s child appears we previously applied the child’s options on the stack, without merging the child and the stack’s options.
This commit fixes this by resolving options of all visible children when applying child options.
Guy Carmeli 6 years ago
parent
commit
d5ca8e4de9

+ 1
- 1
e2e/ScreenStyle.test.js View File

@@ -9,7 +9,7 @@ describe('screen style', () => {
9 9
     await device.relaunchApp();
10 10
   });
11 11
 
12
-  test('declare a options on component component', async () => {
12
+  test('declare options on a component', async () => {
13 13
     await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
14 14
     await expect(elementByLabel('Static Title')).toBeVisible();
15 15
   });

+ 2
- 0
lib/android/app/src/main/AndroidManifest.xml View File

@@ -1,6 +1,8 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 2
           package="com.reactnativenavigation">
3 3
 
4
+    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
5
+
4 6
     <application>
5 7
         <activity
6 8
             android:name="com.facebook.react.devsupport.DevSettingsActivity"

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

@@ -78,5 +78,6 @@ public class BottomTabOptions {
78 78
         if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
79 79
         if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize;
80 80
         if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
81
+        if (!testId.hasValue()) testId = defaultOptions.testId;
81 82
     }
82 83
 }

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

@@ -45,7 +45,8 @@ public abstract class ParentController<T extends ViewGroup> extends ChildControl
45 45
 	    if (CollectionUtils.isNullOrEmpty(getChildControllers())) return initialOptions;
46 46
         return getCurrentChild()
47 47
                 .resolveCurrentOptions()
48
-                .mergeWith(initialOptions);
48
+                .copy()
49
+                .withDefaultOptions(initialOptions);
49 50
     }
50 51
 
51 52
     @Override

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

@@ -77,7 +77,7 @@ public class StackController extends ParentController<StackLayout> {
77 77
     @Override
78 78
     public void applyChildOptions(Options options, Component child) {
79 79
         super.applyChildOptions(options, child);
80
-        presenter.applyChildOptions(options, child);
80
+        presenter.applyChildOptions(resolveCurrentOptions(), child);
81 81
         if (child instanceof ReactComponent) {
82 82
             fabOptionsPresenter.applyOptions(this.options.fabOptions, (ReactComponent) child, getView());
83 83
         }

+ 8
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java View File

@@ -194,7 +194,13 @@ public class ParentControllerTest extends BaseTest {
194 194
     public void resolveCurrentOptions_mergesWithCurrentChild() {
195 195
         ViewController child1 = Mockito.mock(ViewController.class);
196 196
         when(child1.getView()).thenReturn(new FrameLayout(activity));
197
-        Options childOptions = spy(new Options());
197
+        Options copiedChildOptions = spy(new Options());
198
+        Options childOptions = spy(new Options() {
199
+            @Override
200
+            public Options copy() {
201
+                return copiedChildOptions;
202
+            }
203
+        });
198 204
         when(child1.resolveCurrentOptions()).thenReturn(childOptions);
199 205
 
200 206
         children.add(child1);
@@ -203,7 +209,7 @@ public class ParentControllerTest extends BaseTest {
203 209
         assertThat(uut.getCurrentChild()).isEqualTo(child1);
204 210
         uut.resolveCurrentOptions();
205 211
         verify(child1).resolveCurrentOptions();
206
-        verify(childOptions).mergeWith(uut.initialOptions);
212
+        verify(copiedChildOptions).withDefaultOptions(uut.initialOptions);
207 213
     }
208 214
 
209 215
     @Test

+ 18
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java View File

@@ -830,6 +830,24 @@ public class StackControllerTest extends BaseTest {
830 830
         assertThat(captor.getValue().fabOptions.hasValue()).isFalse();
831 831
     }
832 832
 
833
+    @Test
834
+    public void applyChildOptions_appliesResolvedOptions() {
835
+        disablePushAnimation(child1, child2);
836
+
837
+        uut.push(child1, new CommandListenerAdapter());
838
+
839
+        assertThat(uut.getTopBar().getTitle()).isNullOrEmpty();
840
+
841
+        Options uutOptions = new Options();
842
+        uutOptions.topBar.title.text = new Text("UUT");
843
+        uut.mergeOptions(uutOptions);
844
+
845
+        assertThat(uut.getTopBar().getTitle()).isEqualTo("UUT");
846
+
847
+        uut.push(child2, new CommandListenerAdapter());
848
+        assertThat(uut.getTopBar().getTitle()).isEqualTo("UUT");
849
+    }
850
+
833 851
     @Test
834 852
     public void mergeChildOptions_presenterDoesNotApplyOptionsIfViewIsNotShown() {
835 853
         ViewController vc = mock(ViewController.class);