Browse Source

Fix drawBehind in default options not working

Take default options into account when calculating topInset.
Fixes #5286
Guy Carmeli 5 years ago
parent
commit
0e933661ae

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java View File

@@ -543,4 +543,8 @@ public class StackPresenter {
543 543
         int statusBarInset = withDefault.statusBar.visible.isTrueOrUndefined() ? StatusBarUtils.getStatusBarHeight(child.getActivity()) : 0;
544 544
         return topMargin + statusBarInset;
545 545
     }
546
+
547
+    public int getTopInset(Options resolvedOptions) {
548
+        return resolvedOptions.withDefaultOptions(defaultOptions).topBar.isHiddenOrDrawBehind() ? 0 : topBarController.getHeight();
549
+    }
546 550
 }

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

@@ -412,7 +412,7 @@ public class StackController extends ParentController<StackLayout> {
412 412
 
413 413
     @Override
414 414
     public int getTopInset(ViewController child) {
415
-        return resolveChildOptions(child).topBar.isHiddenOrDrawBehind() ? 0 : topBarController.getHeight();
415
+        return presenter.getTopInset(resolveChildOptions(child));
416 416
     }
417 417
 
418 418
     @RestrictTo(RestrictTo.Scope.TESTS)

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

@@ -1148,6 +1148,16 @@ public class StackControllerTest extends BaseTest {
1148 1148
         assertThat(uut.getTopInset(child1)).isEqualTo(0);
1149 1149
     }
1150 1150
 
1151
+    @Test
1152
+    public void getTopInset_defaultOptionsAreTakenIntoAccount() {
1153
+        assertThat(uut.getTopInset(child1)).isEqualTo(topBarController.getHeight());
1154
+        Options defaultOptions = new Options();
1155
+        defaultOptions.topBar.drawBehind = new Bool(true);
1156
+        uut.setDefaultOptions(defaultOptions);
1157
+
1158
+        assertThat(uut.getTopInset(child1)).isZero();
1159
+    }
1160
+
1151 1161
     private void assertContainsOnlyId(String... ids) {
1152 1162
         assertThat(uut.size()).isEqualTo(ids.length);
1153 1163
         assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, String>) ViewController::getId).containsOnly(ids);