Browse Source

Hide topBar with animation by default (#2752)

* Hide topBar with animation by default

* fix unit tests
Guy Carmeli 6 years ago
parent
commit
34a812cd55
No account linked to committer's email address

+ 10
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -33,7 +33,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
33 33
     private final Toolbar titleBar;
34 34
     private TitleBarButton.OnClickListener onClickListener;
35 35
     private final TopBarCollapseBehavior collapsingBehavior;
36
-    private final TopBarAnimator animator;
36
+    private TopBarAnimator animator;
37 37
     private TopTabs topTabs;
38 38
     private StackLayout parentView;
39 39
 
@@ -179,7 +179,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
179 179
         if (getVisibility() == View.VISIBLE) {
180 180
             return;
181 181
         }
182
-        if (animated.isTrue()) {
182
+        if (animated.isTrueOrUndefined()) {
183 183
             animator.show();
184 184
         } else {
185 185
             setVisibility(View.VISIBLE);
@@ -190,7 +190,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
190 190
         if (getVisibility() == View.GONE) {
191 191
             return;
192 192
         }
193
-        if (animated.isTrue()) {
193
+        if (animated.isTrueOrUndefined()) {
194 194
             animator.hide();
195 195
         } else {
196 196
             setVisibility(View.GONE);
@@ -213,12 +213,17 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
213 213
         titleBar.getMenu().clear();
214 214
     }
215 215
 
216
+    public void clearTopTabs() {
217
+        topTabs.clear(this);
218
+    }
219
+
216 220
     @VisibleForTesting()
217 221
     public TopTabs getTopTabs() {
218 222
         return topTabs;
219 223
     }
220 224
 
221
-    public void clearTopTabs() {
222
-        topTabs.clear(this);
225
+    @VisibleForTesting
226
+    public void setAnimator(TopBarAnimator animator) {
227
+        this.animator = animator;
223 228
     }
224 229
 }

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

@@ -147,6 +147,7 @@ public class OptionsApplyingTest extends BaseTest {
147 147
 
148 148
         Options opts = new Options();
149 149
         opts.topBarOptions.visible = new Bool(false);
150
+        opts.topBarOptions.animateHide = new Bool(false);
150 151
         uut.mergeOptions(opts);
151 152
 
152 153
         assertThat(stackController.getTopBar().getVisibility()).isEqualTo(View.GONE);

+ 37
- 7
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java View File

@@ -1,18 +1,48 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
-import com.reactnativenavigation.*;
3
+import com.reactnativenavigation.BaseTest;
4
+import com.reactnativenavigation.anim.TopBarAnimator;
5
+import com.reactnativenavigation.parse.params.Bool;
6
+import com.reactnativenavigation.parse.params.NullBool;
4 7
 
5
-import org.junit.*;
8
+import org.junit.Test;
6 9
 
7
-import static org.assertj.core.api.Java6Assertions.*;
10
+import static org.assertj.core.api.Java6Assertions.assertThat;
11
+import static org.mockito.Mockito.spy;
12
+import static org.mockito.Mockito.times;
13
+import static org.mockito.Mockito.verify;
8 14
 
9 15
 public class TopBarTest extends BaseTest {
16
+
17
+    private TopBar uut;
18
+    private TopBarAnimator animator;
19
+
20
+    @Override
21
+    public void beforeEach() {
22
+        StackLayout parent = new StackLayout(newActivity());
23
+        uut = new TopBar(newActivity(), buttonId -> {}, parent);
24
+        animator = spy(new TopBarAnimator(uut));
25
+        uut.setAnimator(animator);
26
+        parent.addView(uut);
27
+    }
28
+
10 29
     @Test
11 30
     public void title() throws Exception {
12
-        TopBar topBar = new TopBar(newActivity(), buttonId -> {}, null);
13
-        assertThat(topBar.getTitle()).isEmpty();
31
+        assertThat(uut.getTitle()).isEmpty();
32
+        uut.setTitle("new title");
33
+        assertThat(uut.getTitle()).isEqualTo("new title");
34
+    }
14 35
 
15
-        topBar.setTitle("new title");
16
-        assertThat(topBar.getTitle()).isEqualTo("new title");
36
+    @Test
37
+    public void hide_animateHideUnlessSpecifiedOtherwise() throws Exception {
38
+        uut.hide(new NullBool());
39
+        verify(animator, times(1)).hide();
40
+    }
41
+
42
+    @Test
43
+    public void show_animateShowUnlessSpecifiedOtherwise() throws Exception {
44
+        uut.hide(new Bool(false));
45
+        uut.show(new NullBool());
46
+        verify(animator, times(1)).show();
17 47
     }
18 48
 }