Browse Source

Reset animation values when showing topBar

Guy Carmeli 6 years ago
parent
commit
8d4b92cf9c

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/anim/TopBarAnimator.java View File

57
                 topBar.setVisibility(View.VISIBLE);
57
                 topBar.setVisibility(View.VISIBLE);
58
             }
58
             }
59
         });
59
         });
60
+        topBar.resetAnimationOptions();
60
         showAnimator.start();
61
         showAnimator.start();
61
     }
62
     }
62
 
63
 

+ 6
- 5
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java View File

9
 import com.reactnativenavigation.parse.TopBarOptions;
9
 import com.reactnativenavigation.parse.TopBarOptions;
10
 import com.reactnativenavigation.parse.TopTabOptions;
10
 import com.reactnativenavigation.parse.TopTabOptions;
11
 import com.reactnativenavigation.parse.TopTabsOptions;
11
 import com.reactnativenavigation.parse.TopTabsOptions;
12
+import com.reactnativenavigation.parse.params.Bool;
12
 import com.reactnativenavigation.parse.params.Button;
13
 import com.reactnativenavigation.parse.params.Button;
13
 import com.reactnativenavigation.utils.UiUtils;
14
 import com.reactnativenavigation.utils.UiUtils;
14
 import com.reactnativenavigation.viewcontrollers.IReactView;
15
 import com.reactnativenavigation.viewcontrollers.IReactView;
34
     public void applyChildOptions(Options options, Component child) {
35
     public void applyChildOptions(Options options, Component child) {
35
         applyOrientation(options.orientationOptions);
36
         applyOrientation(options.orientationOptions);
36
         applyButtons(options.topBarOptions.leftButtons, options.topBarOptions.rightButtons);
37
         applyButtons(options.topBarOptions.leftButtons, options.topBarOptions.rightButtons);
37
-        applyTopBarOptions(options.topBarOptions, options.animationsOptions, child);
38
+        applyTopBarOptions(options.topBarOptions, options.animationsOptions, child, options.animated);
38
         applyTopTabsOptions(options.topTabsOptions);
39
         applyTopTabsOptions(options.topTabsOptions);
39
         applyTopTabOptions(options.topTabOptions);
40
         applyTopTabOptions(options.topTabOptions);
40
     }
41
     }
43
         ((Activity) topBar.getContext()).setRequestedOrientation(options.getValue());
44
         ((Activity) topBar.getContext()).setRequestedOrientation(options.getValue());
44
     }
45
     }
45
 
46
 
46
-    private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component) {
47
+    private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Bool animated) {
47
         topBar.setTitle(options.title.text.get(""));
48
         topBar.setTitle(options.title.text.get(""));
48
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component);
49
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component);
49
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));
50
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));
62
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
63
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
63
 
64
 
64
         if (options.visible.isFalse()) {
65
         if (options.visible.isFalse()) {
65
-            if (options.animate.isTrueOrUndefined()) {
66
+            if (options.animate.isTrueOrUndefined() && animated.isTrueOrUndefined()) {
66
                 topBar.hideAnimate(animationOptions.pop.topBar);
67
                 topBar.hideAnimate(animationOptions.pop.topBar);
67
             } else {
68
             } else {
68
                 topBar.hide();
69
                 topBar.hide();
69
             }
70
             }
70
         }
71
         }
71
         if (options.visible.isTrueOrUndefined()) {
72
         if (options.visible.isTrueOrUndefined()) {
72
-            if (options.animate.isTrueOrUndefined()) {
73
+            if (options.animate.isTrueOrUndefined() && animated.isTrueOrUndefined()) {
73
                 topBar.showAnimate(animationOptions.push.topBar);
74
                 topBar.showAnimate(animationOptions.push.topBar);
74
             } else {
75
             } else {
75
                 topBar.show();
76
                 topBar.show();
106
 
107
 
107
     public void onChildWillDisappear(Options disappearing, Options appearing) {
108
     public void onChildWillDisappear(Options disappearing, Options appearing) {
108
         if (disappearing.topBarOptions.visible.isTrueOrUndefined() && appearing.topBarOptions.visible.isFalse()) {
109
         if (disappearing.topBarOptions.visible.isTrueOrUndefined() && appearing.topBarOptions.visible.isFalse()) {
109
-            if (disappearing.topBarOptions.animate.isTrueOrUndefined()) {
110
+            if (disappearing.topBarOptions.animate.isTrueOrUndefined() && disappearing.animated.isTrueOrUndefined()) {
110
                 topBar.hideAnimate(disappearing.animationsOptions.pop.topBar);
111
                 topBar.hideAnimate(disappearing.animationsOptions.pop.topBar);
111
             } else {
112
             } else {
112
                 topBar.hide();
113
                 topBar.hide();

+ 12
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java View File

180
 
180
 
181
     public void show() {
181
     public void show() {
182
         if (visible() || animator.isAnimatingShow()) return;
182
         if (visible() || animator.isAnimatingShow()) return;
183
+        resetAnimationOptions();
183
         setVisibility(View.VISIBLE);
184
         setVisibility(View.VISIBLE);
184
     }
185
     }
185
 
186
 
240
     public TextView getTitleTextView() {
241
     public TextView getTitleTextView() {
241
         return titleBar.findTitleTextView();
242
         return titleBar.findTitleTextView();
242
     }
243
     }
244
+
245
+    public void resetAnimationOptions() {
246
+        setTranslationY(0);
247
+        setTranslationX(0);
248
+        setAlpha(1);
249
+        setScaleY(1);
250
+        setScaleX(1);
251
+        setRotationX(0);
252
+        setRotationY(0);
253
+        setRotation(0);
254
+    }
243
 }
255
 }

+ 107
- 29
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java View File

1
 package com.reactnativenavigation.viewcontrollers;
1
 package com.reactnativenavigation.viewcontrollers;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
+import android.content.Context;
4
 import android.support.annotation.NonNull;
5
 import android.support.annotation.NonNull;
5
 import android.view.View;
6
 import android.view.View;
6
 
7
 
21
 import com.reactnativenavigation.views.Component;
22
 import com.reactnativenavigation.views.Component;
22
 import com.reactnativenavigation.views.ReactComponent;
23
 import com.reactnativenavigation.views.ReactComponent;
23
 import com.reactnativenavigation.views.StackLayout;
24
 import com.reactnativenavigation.views.StackLayout;
25
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
26
+import com.reactnativenavigation.views.topbar.TopBar;
24
 
27
 
25
 import org.assertj.core.api.iterable.Extractor;
28
 import org.assertj.core.api.iterable.Extractor;
26
 import org.json.JSONObject;
29
 import org.json.JSONObject;
170
         assertThat(uut.isEmpty()).isFalse();
173
         assertThat(uut.isEmpty()).isFalse();
171
     }
174
     }
172
 
175
 
173
-    @Test
174
-    public void pushAssignsRefToSelfOnPushedController() {
175
-        assertThat(child1.getParentController()).isNull();
176
-        uut.push(child1, new CommandListenerAdapter());
177
-        assertThat(child1.getParentController()).isEqualTo(uut);
178
-
179
-        StackController anotherNavController = createStackController("another");
180
-        anotherNavController.push(child2, new CommandListenerAdapter());
181
-        assertThat(child2.getParentController()).isEqualTo(anotherNavController);
182
-    }
183
-
184
     @Test
176
     @Test
185
     public void handleBack_PopsUnlessSingleChild() {
177
     public void handleBack_PopsUnlessSingleChild() {
186
         assertThat(uut.isEmpty()).isTrue();
178
         assertThat(uut.isEmpty()).isTrue();
226
     }
218
     }
227
 
219
 
228
     @Test
220
     @Test
229
-    public void pushAddsToViewTree() {
221
+    public void push_addsToViewTree() {
230
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
222
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
231
         uut.push(child1, new CommandListenerAdapter());
223
         uut.push(child1, new CommandListenerAdapter());
232
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
224
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
233
     }
225
     }
234
 
226
 
235
     @Test
227
     @Test
236
-    public void pushRemovesPreviousFromTree() {
228
+    public void push_removesPreviousFromTree() {
237
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
229
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
238
         uut.push(child1, new CommandListenerAdapter());
230
         uut.push(child1, new CommandListenerAdapter());
239
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
231
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
247
     }
239
     }
248
 
240
 
249
     @Test
241
     @Test
250
-    public void popReplacesViewWithPrevious() {
242
+    public void push_assignsRefToSelfOnPushedController() {
243
+        assertThat(child1.getParentController()).isNull();
244
+        uut.push(child1, new CommandListenerAdapter());
245
+        assertThat(child1.getParentController()).isEqualTo(uut);
246
+
247
+        StackController anotherNavController = createStackController("another");
248
+        anotherNavController.push(child2, new CommandListenerAdapter());
249
+        assertThat(child2.getParentController()).isEqualTo(anotherNavController);
250
+    }
251
+
252
+    @Test
253
+    public void push_doesNotAnimateTopBarIfScreenIsPushedWithoutAnimation() {
254
+        uut.ensureViewIsCreated();
255
+        child1.ensureViewIsCreated();
256
+
257
+        child1.options.topBarOptions.visible = new Bool(false);
258
+        child1.options.topBarOptions.animate = new Bool(false);
259
+        child1.options.animated = new Bool(false);
260
+        child2.options.animated = new Bool(false);
261
+
262
+        uut.push(child1, new CommandListenerAdapter() {
263
+            @Override
264
+            public void onSuccess(String childId) {
265
+                child1.onViewAppeared();
266
+                assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
267
+
268
+                uut.push(child2, new CommandListenerAdapter());
269
+                child2.onViewAppeared();
270
+                verify(uut.getTopBar(), times(0)).showAnimate(child2.options.animationsOptions.push.topBar);
271
+                assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.VISIBLE);
272
+                verify(uut.getTopBar(), times(1)).resetAnimationOptions();
273
+            }
274
+        });
275
+    }
276
+
277
+    @Test
278
+    public void push_animatesAndClearsPreviousAnimationValues() {
279
+        uut.ensureViewIsCreated();
280
+
281
+        child1.options.topBarOptions.visible = new Bool(false);
282
+        child1.options.topBarOptions.animate = new Bool(false);
283
+        child1.options.animated = new Bool(false);
284
+
285
+        uut.push(child1, new CommandListenerAdapter());
286
+        uut.push(child2, new CommandListenerAdapter() {
287
+            @Override
288
+            public void onSuccess(String childId) {
289
+                verify(uut.getTopBar(), times(1)).resetAnimationOptions();
290
+            }
291
+        });
292
+    }
293
+
294
+    @Test
295
+    public void pop_replacesViewWithPrevious() {
251
         final View child2View = child2.getView();
296
         final View child2View = child2.getView();
252
         final View child1View = child1.getView();
297
         final View child1View = child1.getView();
253
 
298
 
265
     }
310
     }
266
 
311
 
267
     @Test
312
     @Test
268
-    public void popSpecificWhenTopIsRegularPop() {
313
+    public void pop_specificWhenTopIsRegularPop() {
269
         uut.push(child1, new CommandListenerAdapter());
314
         uut.push(child1, new CommandListenerAdapter());
270
         uut.push(child2, new CommandListenerAdapter() {
315
         uut.push(child2, new CommandListenerAdapter() {
271
             @Override
316
             @Override
282
     }
327
     }
283
 
328
 
284
     @Test
329
     @Test
285
-    public void popSpecificDeepInStack() {
330
+    public void popSpecific_deepInStack() {
286
         uut.push(child1, new CommandListenerAdapter());
331
         uut.push(child1, new CommandListenerAdapter());
287
         uut.push(child2, new CommandListenerAdapter());
332
         uut.push(child2, new CommandListenerAdapter());
288
         assertIsChildById(uut.getView(), child2.getView());
333
         assertIsChildById(uut.getView(), child2.getView());
460
     }
505
     }
461
 
506
 
462
     @Test
507
     @Test
463
-    public void pop_animatesTopBarIfNeeded() {
508
+    public void pop_animatesTopBar() {
464
         uut.ensureViewIsCreated();
509
         uut.ensureViewIsCreated();
465
 
510
 
466
         child1.options.topBarOptions.visible = new Bool(false);
511
         child1.options.topBarOptions.visible = new Bool(false);
467
-        child1.options.topBarOptions.animate = new Bool(false);
468
-        child2.options.topBarOptions.visible = new Bool(true);
469
-        uut.push(child1, new CommandListenerAdapter());
470
-        child1.onViewAppeared();
471
-
472
-        assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
473
-        uut.push(child2, new CommandListenerAdapter() {
512
+        child1.options.animated = new Bool(false);
513
+        child2.options.animated = new Bool(true);
514
+        uut.push(child1, new CommandListenerAdapter() {
474
             @Override
515
             @Override
475
             public void onSuccess(String childId) {
516
             public void onSuccess(String childId) {
476
-                uut.pop(new CommandListenerAdapter() {
517
+                child1.onViewAppeared();
518
+                assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
519
+                uut.push(child2, new CommandListenerAdapter() {
477
                     @Override
520
                     @Override
478
                     public void onSuccess(String childId) {
521
                     public void onSuccess(String childId) {
479
-                        verify(uut.getTopBar(), times(1)).hide();
522
+                        uut.pop(new CommandListenerAdapter() {
523
+                            @Override
524
+                            public void onSuccess(String childId) {
525
+                                verify(uut.getTopBar(), times(1)).hideAnimate(child2.options.animationsOptions.pop.topBar);
526
+                            }
527
+                        });
480
                     }
528
                     }
481
                 });
529
                 });
482
             }
530
             }
483
         });
531
         });
484
     }
532
     }
485
 
533
 
534
+    @Test
535
+    public void pop_doesNotAnimateTopBarIfScreenIsPushedWithoutAnimation() {
536
+        uut.ensureViewIsCreated();
537
+
538
+        child1.options.topBarOptions.visible = new Bool(false);
539
+        child2.options.animated = new Bool(false);
540
+        child1.ensureViewIsCreated();
541
+        uut.push(child1, new CommandListenerAdapter() {
542
+            @Override
543
+            public void onSuccess(String childId) {
544
+                uut.push(child2, new CommandListenerAdapter());
545
+                assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.VISIBLE);
546
+
547
+                uut.pop(new CommandListenerAdapter());
548
+                verify(uut.getTopBar(), times(0)).hideAnimate(child2.options.animationsOptions.pop.topBar);
549
+                assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
550
+            }
551
+        });
552
+    }
553
+
486
     @Test
554
     @Test
487
     public void popSpecific_CallsDestroyOnPoppedChild() {
555
     public void popSpecific_CallsDestroyOnPoppedChild() {
488
         child1 = spy(child1);
556
         child1 = spy(child1);
656
     }
724
     }
657
 
725
 
658
     private StackController createStackController(String id) {
726
     private StackController createStackController(String id) {
659
-        topBarController = spy(new TopBarController());
727
+        topBarController = spy(new TopBarController() {
728
+            @Override
729
+            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
730
+                TopBar topBar = spy(super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout));
731
+                return topBar;
732
+            }
733
+        });
660
         return new StackController(activity,
734
         return new StackController(activity,
661
-                new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
662
-                topBarController, id, new Options()) {
735
+                new TopBarButtonCreatorMock(),
736
+                new TitleBarReactViewCreatorMock(),
737
+                new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
738
+                topBarController,
739
+                id,
740
+                new Options()) {
663
             @Override
741
             @Override
664
             NavigationAnimator createAnimator() {
742
             NavigationAnimator createAnimator() {
665
                 animator = Mockito.mock(NavigationAnimator.class);
743
                 animator = Mockito.mock(NavigationAnimator.class);