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
     private final Toolbar titleBar;
33
     private final Toolbar titleBar;
34
     private TitleBarButton.OnClickListener onClickListener;
34
     private TitleBarButton.OnClickListener onClickListener;
35
     private final TopBarCollapseBehavior collapsingBehavior;
35
     private final TopBarCollapseBehavior collapsingBehavior;
36
-    private final TopBarAnimator animator;
36
+    private TopBarAnimator animator;
37
     private TopTabs topTabs;
37
     private TopTabs topTabs;
38
     private StackLayout parentView;
38
     private StackLayout parentView;
39
 
39
 
179
         if (getVisibility() == View.VISIBLE) {
179
         if (getVisibility() == View.VISIBLE) {
180
             return;
180
             return;
181
         }
181
         }
182
-        if (animated.isTrue()) {
182
+        if (animated.isTrueOrUndefined()) {
183
             animator.show();
183
             animator.show();
184
         } else {
184
         } else {
185
             setVisibility(View.VISIBLE);
185
             setVisibility(View.VISIBLE);
190
         if (getVisibility() == View.GONE) {
190
         if (getVisibility() == View.GONE) {
191
             return;
191
             return;
192
         }
192
         }
193
-        if (animated.isTrue()) {
193
+        if (animated.isTrueOrUndefined()) {
194
             animator.hide();
194
             animator.hide();
195
         } else {
195
         } else {
196
             setVisibility(View.GONE);
196
             setVisibility(View.GONE);
213
         titleBar.getMenu().clear();
213
         titleBar.getMenu().clear();
214
     }
214
     }
215
 
215
 
216
+    public void clearTopTabs() {
217
+        topTabs.clear(this);
218
+    }
219
+
216
     @VisibleForTesting()
220
     @VisibleForTesting()
217
     public TopTabs getTopTabs() {
221
     public TopTabs getTopTabs() {
218
         return topTabs;
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
 
147
 
148
         Options opts = new Options();
148
         Options opts = new Options();
149
         opts.topBarOptions.visible = new Bool(false);
149
         opts.topBarOptions.visible = new Bool(false);
150
+        opts.topBarOptions.animateHide = new Bool(false);
150
         uut.mergeOptions(opts);
151
         uut.mergeOptions(opts);
151
 
152
 
152
         assertThat(stackController.getTopBar().getVisibility()).isEqualTo(View.GONE);
153
         assertThat(stackController.getTopBar().getVisibility()).isEqualTo(View.GONE);

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

1
 package com.reactnativenavigation.views;
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
 public class TopBarTest extends BaseTest {
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
     @Test
29
     @Test
11
     public void title() throws Exception {
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
 }