Browse Source

DrawBehind when tabs are hidden (#5663)

When BottomTabs are hidden, draw components behind the tabs even if drawBehind isn't set to true explicitly.
Guy Carmeli 5 years ago
parent
commit
002b7d8f33
No account linked to committer's email address

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

@@ -79,6 +79,10 @@ public class BottomTabsOptions {
79 79
         if (!tabsAttachMode.hasValue()) tabsAttachMode = defaultOptions.tabsAttachMode;
80 80
     }
81 81
 
82
+    public boolean isHiddenOrDrawBehind() {
83
+        return visible.isFalse() || drawBehind.isTrue();
84
+    }
85
+
82 86
     public void clearOneTimeOptions() {
83 87
         currentTabId = new NullText();
84 88
         currentTabIndex = new NullNumber();

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

@@ -71,8 +71,8 @@ public abstract class ChildController<T extends ViewGroup> extends ViewControlle
71 71
     public void mergeOptions(Options options) {
72 72
         if (options == Options.EMPTY) return;
73 73
         if (isViewShown()) presenter.mergeOptions(getView(), options);
74
-        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
75 74
         super.mergeOptions(options);
75
+        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
76 76
     }
77 77
 
78 78
     @Override

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

@@ -177,7 +177,7 @@ public class BottomTabsController extends ParentController<BottomTabsLayout> imp
177 177
 
178 178
     @Override
179 179
     public int getBottomInset(ViewController child) {
180
-        int bottomTabsInset = resolveChildOptions(child).bottomTabsOptions.drawBehind.isTrue() ? 0 : bottomTabs.getHeight();
180
+        int bottomTabsInset = resolveChildOptions(child).bottomTabsOptions.isHiddenOrDrawBehind() ? 0 : bottomTabs.getHeight();
181 181
         return bottomTabsInset + perform(getParentController(), 0, p -> p.getBottomInset(this));
182 182
     }
183 183
 

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

@@ -7,6 +7,7 @@ import android.view.MotionEvent;
7 7
 import com.facebook.react.ReactInstanceManager;
8 8
 import com.reactnativenavigation.interfaces.ScrollEventListener;
9 9
 import com.reactnativenavigation.parse.Options;
10
+import com.reactnativenavigation.presentation.ComponentPresenterBase;
10 11
 import com.reactnativenavigation.presentation.Presenter;
11 12
 import com.reactnativenavigation.react.ReactView;
12 13
 import com.reactnativenavigation.viewcontrollers.ChildController;
@@ -20,7 +21,7 @@ import androidx.annotation.NonNull;
20 21
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
21 22
 
22 23
 public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
23
-
24
+    private ComponentPresenterBase presenter = new ComponentPresenterBase();
24 25
 
25 26
     public SimpleViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options options) {
26 27
         this(activity, childRegistry, id, new Presenter(activity, new Options()), options);
@@ -58,6 +59,11 @@ public class SimpleViewController extends ChildController<SimpleViewController.S
58 59
         return statusBarInset + perform(getParentController(), 0, p -> p.getTopInset(this));
59 60
     }
60 61
 
62
+    @Override
63
+    public void applyBottomInset() {
64
+        if (view != null) presenter.applyBottomInset(view, getBottomInset());
65
+    }
66
+
61 67
     public static class SimpleView extends ReactView implements ReactComponent {
62 68
 
63 69
         public SimpleView(@NonNull Context context) {

+ 33
- 6
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java View File

@@ -4,6 +4,7 @@ import android.app.Activity;
4 4
 import android.graphics.Color;
5 5
 import android.view.Gravity;
6 6
 import android.view.View;
7
+import android.view.ViewGroup.MarginLayoutParams;
7 8
 
8 9
 import com.reactnativenavigation.BaseTest;
9 10
 import com.reactnativenavigation.TestUtils;
@@ -27,6 +28,7 @@ import com.reactnativenavigation.viewcontrollers.ParentController;
27 28
 import com.reactnativenavigation.viewcontrollers.ViewController;
28 29
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
29 30
 import com.reactnativenavigation.views.BottomTabs;
31
+import com.reactnativenavigation.views.bottomtabs.BottomTabsLayout;
30 32
 
31 33
 import org.junit.Test;
32 34
 import org.mockito.ArgumentCaptor;
@@ -84,7 +86,7 @@ public class BottomTabsControllerTest extends BaseTest {
84 86
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
85 87
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
86 88
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
87
-        child4 = spy(createStack("someStack"));
89
+        child4 = spy(createStack());
88 90
         child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
89 91
         when(child5.handleBack(any())).thenReturn(true);
90 92
         tabs = createTabs();
@@ -208,17 +210,34 @@ public class BottomTabsControllerTest extends BaseTest {
208 210
 
209 211
     @Test
210 212
     public void mergeOptions_drawBehind() {
211
-        assertThat(uut.getBottomInset()).isEqualTo(uut.getBottomTabs().getHeight());
213
+        assertThat(uut.getBottomInset(child1)).isEqualTo(uut.getBottomTabs().getHeight());
212 214
 
213 215
         Options o1 = new Options();
214 216
         o1.bottomTabsOptions.drawBehind = new Bool(true);
215 217
         child1.mergeOptions(o1);
216
-        assertThat(uut.getBottomInset()).isEqualTo(0);
218
+        assertThat(uut.getBottomInset(child1)).isEqualTo(0);
217 219
 
218 220
         Options o2 = new Options();
219 221
         o2.topBar.title.text = new Text("Some text");
220 222
         child1.mergeOptions(o1);
221
-        assertThat(uut.getBottomInset()).isEqualTo(0);
223
+        assertThat(uut.getBottomInset(child1)).isEqualTo(0);
224
+    }
225
+
226
+    @Test
227
+    public void mergeOptions_drawBehind_stack() {
228
+        uut.selectTab(3);
229
+
230
+        SimpleViewController stackChild = new SimpleViewController(activity, childRegistry, "stackChild", new Options());
231
+        disablePushAnimation(stackChild);
232
+        child4.push(stackChild, new CommandListenerAdapter());
233
+
234
+        assertThat(((MarginLayoutParams) stackChild.getView().getLayoutParams()).bottomMargin).isEqualTo(bottomTabs.getHeight());
235
+
236
+        Options o1 = new Options();
237
+        o1.bottomTabsOptions.drawBehind = new Bool(true);
238
+        stackChild.mergeOptions(o1);
239
+
240
+        assertThat(((MarginLayoutParams) stackChild.getView().getLayoutParams()).bottomMargin).isEqualTo(0);
222 241
     }
223 242
 
224 243
     @Test
@@ -369,9 +388,9 @@ public class BottomTabsControllerTest extends BaseTest {
369 388
         return Arrays.asList(child1, child2, child3, child4, child5);
370 389
     }
371 390
 
372
-    private StackController createStack(String id) {
391
+    private StackController createStack() {
373 392
         return TestUtils.newStackController(activity)
374
-                .setId(id)
393
+                .setId("someStack")
375 394
                 .setInitialOptions(tabOptions)
376 395
                 .build();
377 396
     }
@@ -401,6 +420,14 @@ public class BottomTabsControllerTest extends BaseTest {
401 420
                 uut.getView().layout(0, 0, 1000, 1000);
402 421
             }
403 422
 
423
+            @NonNull
424
+            @Override
425
+            protected BottomTabsLayout createView() {
426
+                BottomTabsLayout view = super.createView();
427
+                bottomTabs.getLayoutParams().height = 100;
428
+                return view;
429
+            }
430
+
404 431
             @NonNull
405 432
             @Override
406 433
             protected BottomTabs createBottomTabs() {