Browse Source

Apply TopBar visibility options when adding initial child to stack

Guy Carmeli 6 years ago
parent
commit
9fc1dda043

+ 18
- 14
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java View File

@@ -47,14 +47,15 @@ public class StackOptionsPresenter {
47 47
     }
48 48
 
49 49
     public void applyLayoutParamsOptions(Options options, View view) {
50
-        Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions);
50
+        Options withDefault = options.copy().withDefaultOptions(defaultOptions);
51 51
         if (view instanceof Component) {
52
-            if (withDefaultOptions.topBar.drawBehind.isTrue() && !withDefaultOptions.layout.topMargin.hasValue()) {
52
+            if (withDefault.topBar.drawBehind.isTrue() && !withDefault.layout.topMargin.hasValue()) {
53 53
                 ((Component) view).drawBehindTopBar();
54 54
             } else if (options.topBar.drawBehind.isFalseOrUndefined()) {
55 55
                 ((Component) view).drawBelowTopBar(topBar);
56 56
             }
57 57
         }
58
+        applyTopBarVisibility(withDefault.topBar, withDefault.animations, options);
58 59
     }
59 60
 
60 61
     public void applyChildOptions(Options options, Component child) {
@@ -95,7 +96,22 @@ public class StackOptionsPresenter {
95 96
         topBar.setBackgroundColor(options.background.color.get(Color.WHITE));
96 97
         topBar.setBackgroundComponent(options.background.component);
97 98
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
99
+        applyTopBarVisibility(options, animationOptions, componentOptions);
100
+        if (options.drawBehind.isTrue() && !componentOptions.layout.topMargin.hasValue()) {
101
+            component.drawBehindTopBar();
102
+        } else if (options.drawBehind.isFalseOrUndefined()) {
103
+            component.drawBelowTopBar(topBar);
104
+        }
105
+        if (options.hideOnScroll.isTrue()) {
106
+            if (component instanceof IReactView) {
107
+                topBar.enableCollapse(((IReactView) component).getScrollEventListener());
108
+            }
109
+        } else if (options.hideOnScroll.isFalseOrUndefined()) {
110
+            topBar.disableCollapse();
111
+        }
112
+    }
98 113
 
114
+    private void applyTopBarVisibility(TopBarOptions options, AnimationsOptions animationOptions, Options componentOptions) {
99 115
         if (options.visible.isFalse()) {
100 116
             if (options.animate.isTrueOrUndefined() && componentOptions.animations.push.enable.isTrueOrUndefined()) {
101 117
                 topBar.hideAnimate(animationOptions.pop.topBar);
@@ -110,18 +126,6 @@ public class StackOptionsPresenter {
110 126
                 topBar.show();
111 127
             }
112 128
         }
113
-        if (options.drawBehind.isTrue() && !componentOptions.layout.topMargin.hasValue()) {
114
-            component.drawBehindTopBar();
115
-        } else if (options.drawBehind.isFalseOrUndefined()) {
116
-            component.drawBelowTopBar(topBar);
117
-        }
118
-        if (options.hideOnScroll.isTrue()) {
119
-            if (component instanceof IReactView) {
120
-                topBar.enableCollapse(((IReactView) component).getScrollEventListener());
121
-            }
122
-        } else if (options.hideOnScroll.isFalseOrUndefined()) {
123
-            topBar.disableCollapse();
124
-        }
125 129
     }
126 130
 
127 131
     private void applyButtons(TopBarButtons buttons) {

+ 14
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackOptionsPresenterTest.java View File

@@ -2,6 +2,7 @@ package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.graphics.Typeface;
5
+import android.view.View;
5 6
 
6 7
 import com.reactnativenavigation.BaseTest;
7 8
 import com.reactnativenavigation.mocks.TestComponentLayout;
@@ -16,10 +17,12 @@ import com.reactnativenavigation.parse.params.Fraction;
16 17
 import com.reactnativenavigation.parse.params.Number;
17 18
 import com.reactnativenavigation.parse.params.Text;
18 19
 import com.reactnativenavigation.presentation.StackOptionsPresenter;
20
+import com.reactnativenavigation.views.Component;
19 21
 import com.reactnativenavigation.views.topbar.TopBar;
20 22
 
21 23
 import org.json.JSONObject;
22 24
 import org.junit.Test;
25
+import org.mockito.Mockito;
23 26
 
24 27
 import java.util.ArrayList;
25 28
 
@@ -142,6 +145,17 @@ public class StackOptionsPresenterTest extends BaseTest {
142 145
         verify(topBar, times(1)).setTopTabFontFamily(1, Typeface.DEFAULT_BOLD);
143 146
     }
144 147
 
148
+    @Test
149
+    public void applyLayoutParamsOptions() {
150
+        Options options = new Options();
151
+        options.topBar.visible = new Bool(false);
152
+        options.topBar.animate = new Bool(false);
153
+        View view = Mockito.mock(View.class, Mockito.withSettings().extraInterfaces(Component.class));
154
+
155
+        uut.applyLayoutParamsOptions(options, view);
156
+        verify(topBar).hide();
157
+    }
158
+
145 159
     private void assertTopBarOptions(Options options, int t) {
146 160
         if (options.topBar.title.component.hasValue()) {
147 161
             verify(topBar, times(0)).setTitle(any());

+ 1
- 1
playground/src/screens/WelcomeScreen.js View File

@@ -24,7 +24,7 @@ class WelcomeScreen extends Component {
24 24
         },
25 25
         drawBehind: true,
26 26
         visible: false,
27
-        animate: true
27
+        animate: false
28 28
       }
29 29
     };
30 30
   }