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
         if (!tabsAttachMode.hasValue()) tabsAttachMode = defaultOptions.tabsAttachMode;
79
         if (!tabsAttachMode.hasValue()) tabsAttachMode = defaultOptions.tabsAttachMode;
80
     }
80
     }
81
 
81
 
82
+    public boolean isHiddenOrDrawBehind() {
83
+        return visible.isFalse() || drawBehind.isTrue();
84
+    }
85
+
82
     public void clearOneTimeOptions() {
86
     public void clearOneTimeOptions() {
83
         currentTabId = new NullText();
87
         currentTabId = new NullText();
84
         currentTabIndex = new NullNumber();
88
         currentTabIndex = new NullNumber();

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

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

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

177
 
177
 
178
     @Override
178
     @Override
179
     public int getBottomInset(ViewController child) {
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
         return bottomTabsInset + perform(getParentController(), 0, p -> p.getBottomInset(this));
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
 import com.facebook.react.ReactInstanceManager;
7
 import com.facebook.react.ReactInstanceManager;
8
 import com.reactnativenavigation.interfaces.ScrollEventListener;
8
 import com.reactnativenavigation.interfaces.ScrollEventListener;
9
 import com.reactnativenavigation.parse.Options;
9
 import com.reactnativenavigation.parse.Options;
10
+import com.reactnativenavigation.presentation.ComponentPresenterBase;
10
 import com.reactnativenavigation.presentation.Presenter;
11
 import com.reactnativenavigation.presentation.Presenter;
11
 import com.reactnativenavigation.react.ReactView;
12
 import com.reactnativenavigation.react.ReactView;
12
 import com.reactnativenavigation.viewcontrollers.ChildController;
13
 import com.reactnativenavigation.viewcontrollers.ChildController;
20
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
21
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
21
 
22
 
22
 public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
23
 public class SimpleViewController extends ChildController<SimpleViewController.SimpleView> {
23
-
24
+    private ComponentPresenterBase presenter = new ComponentPresenterBase();
24
 
25
 
25
     public SimpleViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options options) {
26
     public SimpleViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options options) {
26
         this(activity, childRegistry, id, new Presenter(activity, new Options()), options);
27
         this(activity, childRegistry, id, new Presenter(activity, new Options()), options);
58
         return statusBarInset + perform(getParentController(), 0, p -> p.getTopInset(this));
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
     public static class SimpleView extends ReactView implements ReactComponent {
67
     public static class SimpleView extends ReactView implements ReactComponent {
62
 
68
 
63
         public SimpleView(@NonNull Context context) {
69
         public SimpleView(@NonNull Context context) {

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

4
 import android.graphics.Color;
4
 import android.graphics.Color;
5
 import android.view.Gravity;
5
 import android.view.Gravity;
6
 import android.view.View;
6
 import android.view.View;
7
+import android.view.ViewGroup.MarginLayoutParams;
7
 
8
 
8
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.TestUtils;
10
 import com.reactnativenavigation.TestUtils;
27
 import com.reactnativenavigation.viewcontrollers.ViewController;
28
 import com.reactnativenavigation.viewcontrollers.ViewController;
28
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
29
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
29
 import com.reactnativenavigation.views.BottomTabs;
30
 import com.reactnativenavigation.views.BottomTabs;
31
+import com.reactnativenavigation.views.bottomtabs.BottomTabsLayout;
30
 
32
 
31
 import org.junit.Test;
33
 import org.junit.Test;
32
 import org.mockito.ArgumentCaptor;
34
 import org.mockito.ArgumentCaptor;
84
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
86
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
85
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
87
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
86
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
88
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
87
-        child4 = spy(createStack("someStack"));
89
+        child4 = spy(createStack());
88
         child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
90
         child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
89
         when(child5.handleBack(any())).thenReturn(true);
91
         when(child5.handleBack(any())).thenReturn(true);
90
         tabs = createTabs();
92
         tabs = createTabs();
208
 
210
 
209
     @Test
211
     @Test
210
     public void mergeOptions_drawBehind() {
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
         Options o1 = new Options();
215
         Options o1 = new Options();
214
         o1.bottomTabsOptions.drawBehind = new Bool(true);
216
         o1.bottomTabsOptions.drawBehind = new Bool(true);
215
         child1.mergeOptions(o1);
217
         child1.mergeOptions(o1);
216
-        assertThat(uut.getBottomInset()).isEqualTo(0);
218
+        assertThat(uut.getBottomInset(child1)).isEqualTo(0);
217
 
219
 
218
         Options o2 = new Options();
220
         Options o2 = new Options();
219
         o2.topBar.title.text = new Text("Some text");
221
         o2.topBar.title.text = new Text("Some text");
220
         child1.mergeOptions(o1);
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
     @Test
243
     @Test
369
         return Arrays.asList(child1, child2, child3, child4, child5);
388
         return Arrays.asList(child1, child2, child3, child4, child5);
370
     }
389
     }
371
 
390
 
372
-    private StackController createStack(String id) {
391
+    private StackController createStack() {
373
         return TestUtils.newStackController(activity)
392
         return TestUtils.newStackController(activity)
374
-                .setId(id)
393
+                .setId("someStack")
375
                 .setInitialOptions(tabOptions)
394
                 .setInitialOptions(tabOptions)
376
                 .build();
395
                 .build();
377
     }
396
     }
401
                 uut.getView().layout(0, 0, 1000, 1000);
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
             @NonNull
431
             @NonNull
405
             @Override
432
             @Override
406
             protected BottomTabs createBottomTabs() {
433
             protected BottomTabs createBottomTabs() {