Bläddra i källkod

Add previous screen to heirarchy before pop

Guy Carmeli 6 år sedan
förälder
incheckning
2e91f522d6

+ 14
- 10
lib/android/app/src/main/java/com/reactnativenavigation/anim/TopBarAnimator.java Visa fil

@@ -7,7 +7,6 @@ import android.animation.AnimatorSet;
7 7
 import android.animation.ObjectAnimator;
8 8
 import android.animation.TimeInterpolator;
9 9
 import android.view.View;
10
-import android.view.animation.AccelerateInterpolator;
11 10
 import android.view.animation.DecelerateInterpolator;
12 11
 import android.view.animation.LinearInterpolator;
13 12
 
@@ -21,13 +20,12 @@ public class TopBarAnimator {
21 20
     private static final int DEFAULT_COLLAPSE_DURATION = 100;
22 21
     private static final int DURATION_TOPBAR = 300;
23 22
     private final DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
24
-    private final AccelerateInterpolator accelerateInterpolator = new AccelerateInterpolator();
25 23
     private final LinearInterpolator linearInterpolator = new LinearInterpolator();
26 24
 
27 25
     private TopBar topBar;
28 26
     private String stackId;
29
-    private AnimatorSet hideAnimator;
30
-    private AnimatorSet showAnimator;
27
+    private Animator hideAnimator;
28
+    private Animator showAnimator;
31 29
 
32 30
     public TopBarAnimator(TopBar topBar) {
33 31
         this.topBar = topBar;
@@ -75,13 +73,13 @@ public class TopBarAnimator {
75 73
         if (options.hasValue() && (!options.id.hasValue() || options.id.get().equals(stackId))) {
76 74
             hideAnimator = options.getAnimation(topBar);
77 75
         } else {
78
-            hideAnimator = getDefaultHideAnimator(0, accelerateInterpolator, DURATION_TOPBAR);
76
+            hideAnimator = getDefaultHideAnimator(0, linearInterpolator, DURATION_TOPBAR);
79 77
         }
80 78
         hide(onAnimationEnd);
81 79
     }
82 80
 
83 81
     void hide(float startTranslation) {
84
-        hideAnimator = getDefaultHideAnimator(startTranslation, null, DEFAULT_COLLAPSE_DURATION);
82
+        hideAnimator = getDefaultHideAnimator(startTranslation, linearInterpolator, DEFAULT_COLLAPSE_DURATION);
85 83
         hide(() -> {});
86 84
     }
87 85
 
@@ -96,12 +94,18 @@ public class TopBarAnimator {
96 94
         hideAnimator.start();
97 95
     }
98 96
 
99
-    private AnimatorSet getDefaultHideAnimator(float startTranslation, TimeInterpolator interpolator, int duration) {
97
+    private Animator getDefaultHideAnimator(float startTranslation, TimeInterpolator interpolator, int duration) {
100 98
         ObjectAnimator hideAnimator = ObjectAnimator.ofFloat(topBar, View.TRANSLATION_Y, startTranslation, -1 * topBar.getMeasuredHeight());
101 99
         hideAnimator.setInterpolator(interpolator);
102 100
         hideAnimator.setDuration(duration);
103
-        AnimatorSet set = new AnimatorSet();
104
-        set.play(hideAnimator);
105
-        return set;
101
+        return hideAnimator;
102
+    }
103
+
104
+    public boolean isAnimatingHide() {
105
+        return hideAnimator != null && hideAnimator.isRunning();
106
+    }
107
+
108
+    public boolean isAnimatingShow() {
109
+         return showAnimator != null && showAnimator.isRunning();
106 110
     }
107 111
 }

+ 2
- 6
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java Visa fil

@@ -3,7 +3,6 @@ package com.reactnativenavigation.presentation;
3 3
 import android.app.Activity;
4 4
 import android.graphics.Color;
5 5
 
6
-import com.reactnativenavigation.interfaces.ChildDisappearListener;
7 6
 import com.reactnativenavigation.parse.AnimationsOptions;
8 7
 import com.reactnativenavigation.parse.Options;
9 8
 import com.reactnativenavigation.parse.OrientationOptions;
@@ -105,16 +104,13 @@ public class OptionsPresenter {
105 104
         if (topTabOptions.fontFamily != null) topBar.setTopTabFontFamily(topTabOptions.tabIndex, topTabOptions.fontFamily);
106 105
     }
107 106
 
108
-    public void onChildWillDisappear(Options disappearing, Options appearing, ChildDisappearListener childDisappearListener) {
107
+    public void onChildWillDisappear(Options disappearing, Options appearing) {
109 108
         if (disappearing.topBarOptions.visible.isTrueOrUndefined() && appearing.topBarOptions.visible.isFalse()) {
110 109
             if (disappearing.topBarOptions.animate.isTrueOrUndefined()) {
111
-                topBar.hideAnimate(disappearing.animationsOptions.pop.topBar, childDisappearListener::childDisappear);
110
+                topBar.hideAnimate(disappearing.animationsOptions.pop.topBar);
112 111
             } else {
113 112
                 topBar.hide();
114
-                childDisappearListener.childDisappear();
115 113
             }
116
-        } else {
117
-            childDisappearListener.childDisappear();
118 114
         }
119 115
     }
120 116
 

+ 2
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Visa fil

@@ -140,9 +140,8 @@ public class StackController extends ParentController<StackLayout> {
140 140
         final ViewController appearing = stack.peek();
141 141
         disappearing.onViewWillDisappear();
142 142
         appearing.onViewWillAppear();
143
-        getView().onChildWillDisappear(disappearing.options, appearing.options, () ->
144
-                getView().addView(appearing.getView())
145
-        );
143
+        getView().addView(appearing.getView(), 0);
144
+        getView().onChildWillDisappear(disappearing.options, appearing.options);
146 145
 
147 146
         if (disappearing.options.animated.isTrueOrUndefined()) {
148 147
             animator.pop(disappearing.getView(), () -> finishPopping(disappearing, listener));

+ 2
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java Visa fil

@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
4 4
 import android.content.Context;
5 5
 import android.widget.RelativeLayout;
6 6
 
7
-import com.reactnativenavigation.interfaces.ChildDisappearListener;
8 7
 import com.reactnativenavigation.parse.Options;
9 8
 import com.reactnativenavigation.presentation.OptionsPresenter;
10 9
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
@@ -41,8 +40,8 @@ public class StackLayout extends RelativeLayout {
41 40
         optionsPresenter.applyChildOptions(options, child);
42 41
     }
43 42
 
44
-    public void onChildWillDisappear(Options disappearing, Options appearing, ChildDisappearListener childDisappearListener) {
45
-        optionsPresenter.onChildWillDisappear(disappearing, appearing, childDisappearListener);
43
+    public void onChildWillDisappear(Options disappearing, Options appearing) {
44
+        optionsPresenter.onChildWillDisappear(disappearing, appearing);
46 45
     }
47 46
 
48 47
     public void mergeChildOptions(Options options, Component child) {

+ 5
- 4
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java Visa fil

@@ -1,6 +1,5 @@
1 1
 package com.reactnativenavigation.views.topbar;
2 2
 
3
-import android.animation.Animator.AnimatorListener;
4 3
 import android.annotation.SuppressLint;
5 4
 import android.content.Context;
6 5
 import android.graphics.Typeface;
@@ -180,7 +179,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
180 179
     }
181 180
 
182 181
     public void show() {
183
-        if (visible()) return;
182
+        if (visible() || animator.isAnimatingShow()) return;
184 183
         setVisibility(View.VISIBLE);
185 184
     }
186 185
 
@@ -189,12 +188,14 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
189 188
     }
190 189
 
191 190
     public void showAnimate(AnimationOptions options) {
192
-        if (visible()) return;
191
+        if (visible() || animator.isAnimatingShow()) return;
193 192
         animator.show(options);
194 193
     }
195 194
 
196 195
     public void hide() {
197
-        setVisibility(View.GONE);
196
+        if (!animator.isAnimatingHide()) {
197
+            setVisibility(View.GONE);
198
+        }
198 199
     }
199 200
 
200 201
     public void hideAnimate(AnimationOptions options) {

+ 17
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Visa fil

@@ -1,6 +1,7 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4
+import android.content.Context;
4 5
 import android.graphics.Color;
5 6
 import android.graphics.drawable.ColorDrawable;
6 7
 import android.view.View;
@@ -23,6 +24,9 @@ import com.reactnativenavigation.utils.CommandListenerAdapter;
23 24
 import com.reactnativenavigation.utils.ViewUtils;
24 25
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
25 26
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
27
+import com.reactnativenavigation.views.StackLayout;
28
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
29
+import com.reactnativenavigation.views.topbar.TopBar;
26 30
 import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
27 31
 
28 32
 import org.json.JSONObject;
@@ -53,9 +57,17 @@ public class OptionsApplyingTest extends BaseTest {
53 57
                 (activity1, componentId, componentName) -> view,
54 58
                 initialNavigationOptions
55 59
         );
56
-        stackController =
57
-                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
60
+        TopBarController topBarController = new TopBarController() {
61
+            @Override
62
+            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
63
+                TopBar topBar = super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout);
64
+                return topBar;
65
+            }
66
+        };
67
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), topBarController, "stack", new Options());
58 68
         stackController.ensureViewIsCreated();
69
+        stackController.getView().layout(0, 0, 1000, 1000);
70
+        stackController.getTopBar().layout(0, 0, 1000, 100);
59 71
         uut.setParentController(stackController);
60 72
     }
61 73
 
@@ -169,13 +181,13 @@ public class OptionsApplyingTest extends BaseTest {
169 181
         uut.options.topBarOptions.title.text = new Text("the title");
170 182
         uut.options.topBarOptions.drawBehind = new Bool(false);
171 183
         uut.ensureViewIsCreated();
184
+        stackController.ensureViewIsCreated();
172 185
         stackController.push(uut, new CommandListenerAdapter() {
173 186
             @Override
174 187
             public void onSuccess(String childId) {
175 188
                 uut.onViewAppeared();
176
-                RelativeLayout.LayoutParams uutLayoutParams =
177
-                        (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
178
-                assertThat(uutLayoutParams.getRule(BELOW)).isNotEqualTo(0);
189
+                RelativeLayout.LayoutParams uutLayoutParams = (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
190
+                assertThat(uutLayoutParams.topMargin).isNotEqualTo(0);
179 191
 
180 192
                 Options opts = new Options();
181 193
                 opts.topBarOptions.drawBehind = new Bool(true);

+ 8
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java Visa fil

@@ -152,8 +152,7 @@ public class StackControllerTest extends BaseTest {
152 152
                 uut.pop(new CommandListenerAdapter() {
153 153
                     @Override
154 154
                     public void onSuccess(String childId) {
155
-                        verify(stackLayout[0], times(1)).onChildWillDisappear(child2.options, child1.options, () -> {
156
-                        });
155
+                        verify(stackLayout[0], times(1)).onChildWillDisappear(child2.options, child1.options);
157 156
                     }
158 157
                 });
159 158
             }
@@ -471,11 +470,15 @@ public class StackControllerTest extends BaseTest {
471 470
         child1.onViewAppeared();
472 471
 
473 472
         assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
474
-        uut.push(child2, new CommandListenerAdapter());
475
-        uut.pop(new CommandListenerAdapter() {
473
+        uut.push(child2, new CommandListenerAdapter() {
476 474
             @Override
477 475
             public void onSuccess(String childId) {
478
-                verify(uut.getTopBar(), times(1)).hide();
476
+                uut.pop(new CommandListenerAdapter() {
477
+                    @Override
478
+                    public void onSuccess(String childId) {
479
+                        verify(uut.getTopBar(), times(1)).hide();
480
+                    }
481
+                });
479 482
             }
480 483
         });
481 484
     }