Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
d5ca8e4de9

+ 1
- 1
e2e/ScreenStyle.test.js Näytä tiedosto

9
     await device.relaunchApp();
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
     await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
13
     await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
14
     await expect(elementByLabel('Static Title')).toBeVisible();
14
     await expect(elementByLabel('Static Title')).toBeVisible();
15
   });
15
   });

+ 2
- 0
lib/android/app/src/main/AndroidManifest.xml Näytä tiedosto

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

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

78
         if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
78
         if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
79
         if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize;
79
         if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize;
80
         if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
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 Näytä tiedosto

45
 	    if (CollectionUtils.isNullOrEmpty(getChildControllers())) return initialOptions;
45
 	    if (CollectionUtils.isNullOrEmpty(getChildControllers())) return initialOptions;
46
         return getCurrentChild()
46
         return getCurrentChild()
47
                 .resolveCurrentOptions()
47
                 .resolveCurrentOptions()
48
-                .mergeWith(initialOptions);
48
+                .copy()
49
+                .withDefaultOptions(initialOptions);
49
     }
50
     }
50
 
51
 
51
     @Override
52
     @Override

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java Näytä tiedosto

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

+ 8
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java Näytä tiedosto

194
     public void resolveCurrentOptions_mergesWithCurrentChild() {
194
     public void resolveCurrentOptions_mergesWithCurrentChild() {
195
         ViewController child1 = Mockito.mock(ViewController.class);
195
         ViewController child1 = Mockito.mock(ViewController.class);
196
         when(child1.getView()).thenReturn(new FrameLayout(activity));
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
         when(child1.resolveCurrentOptions()).thenReturn(childOptions);
204
         when(child1.resolveCurrentOptions()).thenReturn(childOptions);
199
 
205
 
200
         children.add(child1);
206
         children.add(child1);
203
         assertThat(uut.getCurrentChild()).isEqualTo(child1);
209
         assertThat(uut.getCurrentChild()).isEqualTo(child1);
204
         uut.resolveCurrentOptions();
210
         uut.resolveCurrentOptions();
205
         verify(child1).resolveCurrentOptions();
211
         verify(child1).resolveCurrentOptions();
206
-        verify(childOptions).mergeWith(uut.initialOptions);
212
+        verify(copiedChildOptions).withDefaultOptions(uut.initialOptions);
207
     }
213
     }
208
 
214
 
209
     @Test
215
     @Test

+ 18
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java Näytä tiedosto

830
         assertThat(captor.getValue().fabOptions.hasValue()).isFalse();
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
     @Test
851
     @Test
834
     public void mergeChildOptions_presenterDoesNotApplyOptionsIfViewIsNotShown() {
852
     public void mergeChildOptions_presenterDoesNotApplyOptionsIfViewIsNotShown() {
835
         ViewController vc = mock(ViewController.class);
853
         ViewController vc = mock(ViewController.class);