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
     }
47
     }
48
 
48
 
49
     public void applyLayoutParamsOptions(Options options, View view) {
49
     public void applyLayoutParamsOptions(Options options, View view) {
50
-        Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions);
50
+        Options withDefault = options.copy().withDefaultOptions(defaultOptions);
51
         if (view instanceof Component) {
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
                 ((Component) view).drawBehindTopBar();
53
                 ((Component) view).drawBehindTopBar();
54
             } else if (options.topBar.drawBehind.isFalseOrUndefined()) {
54
             } else if (options.topBar.drawBehind.isFalseOrUndefined()) {
55
                 ((Component) view).drawBelowTopBar(topBar);
55
                 ((Component) view).drawBelowTopBar(topBar);
56
             }
56
             }
57
         }
57
         }
58
+        applyTopBarVisibility(withDefault.topBar, withDefault.animations, options);
58
     }
59
     }
59
 
60
 
60
     public void applyChildOptions(Options options, Component child) {
61
     public void applyChildOptions(Options options, Component child) {
95
         topBar.setBackgroundColor(options.background.color.get(Color.WHITE));
96
         topBar.setBackgroundColor(options.background.color.get(Color.WHITE));
96
         topBar.setBackgroundComponent(options.background.component);
97
         topBar.setBackgroundComponent(options.background.component);
97
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
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
         if (options.visible.isFalse()) {
115
         if (options.visible.isFalse()) {
100
             if (options.animate.isTrueOrUndefined() && componentOptions.animations.push.enable.isTrueOrUndefined()) {
116
             if (options.animate.isTrueOrUndefined() && componentOptions.animations.push.enable.isTrueOrUndefined()) {
101
                 topBar.hideAnimate(animationOptions.pop.topBar);
117
                 topBar.hideAnimate(animationOptions.pop.topBar);
110
                 topBar.show();
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
     private void applyButtons(TopBarButtons buttons) {
131
     private void applyButtons(TopBarButtons buttons) {

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

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.graphics.Typeface;
4
 import android.graphics.Typeface;
5
+import android.view.View;
5
 
6
 
6
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.mocks.TestComponentLayout;
8
 import com.reactnativenavigation.mocks.TestComponentLayout;
16
 import com.reactnativenavigation.parse.params.Number;
17
 import com.reactnativenavigation.parse.params.Number;
17
 import com.reactnativenavigation.parse.params.Text;
18
 import com.reactnativenavigation.parse.params.Text;
18
 import com.reactnativenavigation.presentation.StackOptionsPresenter;
19
 import com.reactnativenavigation.presentation.StackOptionsPresenter;
20
+import com.reactnativenavigation.views.Component;
19
 import com.reactnativenavigation.views.topbar.TopBar;
21
 import com.reactnativenavigation.views.topbar.TopBar;
20
 
22
 
21
 import org.json.JSONObject;
23
 import org.json.JSONObject;
22
 import org.junit.Test;
24
 import org.junit.Test;
25
+import org.mockito.Mockito;
23
 
26
 
24
 import java.util.ArrayList;
27
 import java.util.ArrayList;
25
 
28
 
142
         verify(topBar, times(1)).setTopTabFontFamily(1, Typeface.DEFAULT_BOLD);
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
     private void assertTopBarOptions(Options options, int t) {
159
     private void assertTopBarOptions(Options options, int t) {
146
         if (options.topBar.title.component.hasValue()) {
160
         if (options.topBar.title.component.hasValue()) {
147
             verify(topBar, times(0)).setTitle(any());
161
             verify(topBar, times(0)).setTitle(any());

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

24
         },
24
         },
25
         drawBehind: true,
25
         drawBehind: true,
26
         visible: false,
26
         visible: false,
27
-        animate: true
27
+        animate: false
28
       }
28
       }
29
     };
29
     };
30
   }
30
   }