Browse Source

Merge default options before resolving animation options

Command animations did not take default options into account when resolving animation options.
This commit fixes that, TopBar options still need to be addressed.
Guy Carmeli 6 years ago
parent
commit
2c54caa073

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

@@ -10,7 +10,6 @@ import android.view.View;
10 10
 import android.view.animation.AccelerateDecelerateInterpolator;
11 11
 import android.view.animation.DecelerateInterpolator;
12 12
 
13
-import com.reactnativenavigation.parse.AnimationsOptions;
14 13
 import com.reactnativenavigation.utils.UiUtils;
15 14
 
16 15
 import static android.view.View.ALPHA;
@@ -22,8 +21,6 @@ class BaseAnimator {
22 21
     private static final TimeInterpolator DECELERATE = new DecelerateInterpolator();
23 22
     private static final TimeInterpolator ACCELERATE_DECELERATE = new AccelerateDecelerateInterpolator();
24 23
 
25
-    protected AnimationsOptions options = new AnimationsOptions();
26
-
27 24
     private float translationY;
28 25
 
29 26
     BaseAnimator(Context context) {
@@ -52,8 +49,4 @@ class BaseAnimator {
52 49
         set.playTogether(translationY, alpha);
53 50
         return set;
54 51
     }
55
-
56
-    public void setOptions(AnimationsOptions options) {
57
-        this.options = options;
58
-    }
59 52
 }

+ 4
- 4
lib/android/app/src/main/java/com/reactnativenavigation/anim/ModalAnimator.java View File

@@ -16,14 +16,14 @@ public class ModalAnimator extends BaseAnimator {
16 16
         super(context);
17 17
     }
18 18
 
19
-    public void show(View view, AnimationOptions animation, AnimatorListenerAdapter listener) {
20
-        animator = animation.getAnimation(view, getDefaultPushAnimation(view));
19
+    public void show(View view, AnimationOptions show, AnimatorListenerAdapter listener) {
20
+        animator = show.getAnimation(view, getDefaultPushAnimation(view));
21 21
         animator.addListener(listener);
22 22
         animator.start();
23 23
     }
24 24
 
25
-    public void dismiss(View view, AnimatorListenerAdapter listener) {
26
-        animator = options.dismissModal.getAnimation(view, getDefaultPopAnimation(view));
25
+    public void dismiss(View view, AnimationOptions dismiss, AnimatorListenerAdapter listener) {
26
+        animator = dismiss.getAnimation(view, getDefaultPopAnimation(view));
27 27
         animator.addListener(listener);
28 28
         animator.start();
29 29
     }

+ 8
- 20
lib/android/app/src/main/java/com/reactnativenavigation/anim/NavigationAnimator.java View File

@@ -7,7 +7,8 @@ import android.animation.AnimatorSet;
7 7
 import android.content.Context;
8 8
 import android.view.View;
9 9
 
10
-import com.reactnativenavigation.parse.AnimationsOptions;
10
+import com.reactnativenavigation.parse.AnimationOptions;
11
+import com.reactnativenavigation.parse.NestedAnimationsOptions;
11 12
 
12 13
 @SuppressWarnings("ResourceType")
13 14
 public class NavigationAnimator extends BaseAnimator {
@@ -16,14 +17,9 @@ public class NavigationAnimator extends BaseAnimator {
16 17
         super(context);
17 18
     }
18 19
 
19
-    public NavigationAnimator(Context context, AnimationsOptions options) {
20
-        super(context);
21
-        this.options = options;
22
-    }
23
-
24
-    public void push(final View view, Runnable onAnimationEnd) {
20
+    public void push(View view, NestedAnimationsOptions push, Runnable onAnimationEnd) {
25 21
         view.setVisibility(View.INVISIBLE);
26
-        AnimatorSet set = options.push.content.getAnimation(view, getDefaultPushAnimation(view));
22
+        AnimatorSet set = push.content.getAnimation(view, getDefaultPushAnimation(view));
27 23
         set.addListener(new AnimatorListenerAdapter() {
28 24
             @Override
29 25
             public void onAnimationStart(Animator animation) {
@@ -38,8 +34,8 @@ public class NavigationAnimator extends BaseAnimator {
38 34
         set.start();
39 35
     }
40 36
 
41
-    public void pop(View view, Runnable onAnimationEnd) {
42
-        AnimatorSet set = options.pop.content.getAnimation(view, getDefaultPopAnimation(view));
37
+    public void pop(View view, NestedAnimationsOptions pop, Runnable onAnimationEnd) {
38
+        AnimatorSet set = pop.content.getAnimation(view, getDefaultPopAnimation(view));
43 39
         set.addListener(new AnimatorListenerAdapter() {
44 40
             @Override
45 41
             public void onAnimationEnd(Animator animation) {
@@ -49,9 +45,9 @@ public class NavigationAnimator extends BaseAnimator {
49 45
         set.start();
50 46
     }
51 47
 
52
-    public void animateStartApp(View view, AnimatorListener listener) {
48
+    public void animateStartApp(View view, AnimationOptions startApp, AnimatorListener listener) {
53 49
         view.setVisibility(View.INVISIBLE);
54
-        AnimatorSet set = options.startApp.getAnimation(view);
50
+        AnimatorSet set = startApp.getAnimation(view);
55 51
         set.addListener(new AnimatorListenerAdapter() {
56 52
             @Override
57 53
             public void onAnimationStart(Animator animation) {
@@ -65,12 +61,4 @@ public class NavigationAnimator extends BaseAnimator {
65 61
         });
66 62
         set.start();
67 63
     }
68
-
69
-    public void setOptions(AnimationsOptions options) {
70
-        this.options = options;
71
-    }
72
-
73
-    public void mergeOptions(AnimationsOptions options) {
74
-        this.options.mergeWith(options);
75
-    }
76 64
 }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java View File

@@ -159,7 +159,7 @@ public class LayoutFactory {
159 159
 
160 160
 	private ViewController createStack(LayoutNode node) {
161 161
         return new StackControllerBuilder(activity)
162
-                .setChildren(createChildredn(node.children))
162
+                .setChildren(createChildren(node.children))
163 163
                 .setChildRegistry(childRegistry)
164 164
                 .setTopBarButtonCreator(new TitleBarButtonCreator(reactInstanceManager))
165 165
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreator(reactInstanceManager))
@@ -172,7 +172,7 @@ public class LayoutFactory {
172 172
                 .build();
173 173
 	}
174 174
 
175
-    private List<ViewController> createChildredn(List<LayoutNode> children) {
175
+    private List<ViewController> createChildren(List<LayoutNode> children) {
176 176
         List<ViewController> result = new ArrayList<>();
177 177
         for (LayoutNode child : children) {
178 178
             result.add(create(child));

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

@@ -107,8 +107,8 @@ public class Navigator extends ParentController {
107 107
         root = viewController;
108 108
         contentLayout.addView(viewController.getView());
109 109
         if (viewController.options.animations.startApp.hasAnimation()) {
110
-            new NavigationAnimator(viewController.getActivity(), viewController.options.animations)
111
-                    .animateStartApp(viewController.getView(), new AnimatorListenerAdapter() {
110
+            new NavigationAnimator(viewController.getActivity())
111
+                    .animateStartApp(viewController.getView(), viewController.options.animations.startApp, new AnimatorListenerAdapter() {
112 112
                         @Override
113 113
                         public void onAnimationEnd(Animator animation) {
114 114
                             commandListener.onSuccess(viewController.getId());

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenter.java View File

@@ -67,7 +67,7 @@ public class ModalPresenter {
67 67
 
68 68
     public void dismissModal(ViewController toDismiss, CommandListener listener) {
69 69
         if (toDismiss.options.animations.dismissModal.enable.isTrueOrUndefined()) {
70
-            animator.dismiss(toDismiss.getView(), new AnimatorListenerAdapter() {
70
+            animator.dismiss(toDismiss.getView(), toDismiss.options.animations.dismissModal, new AnimatorListenerAdapter() {
71 71
                 @Override
72 72
                 public void onAnimationEnd(Animator animation) {
73 73
                     onDismissEnd(toDismiss, listener);

+ 6
- 8
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java View File

@@ -90,14 +90,12 @@ public class StackController extends ParentController<StackLayout> {
90 90
                         child
91 91
                 )
92 92
         );
93
-        animator.setOptions(options.animations);
94 93
     }
95 94
 
96 95
     @Override
97 96
     public void mergeChildOptions(Options options, Component child) {
98 97
         super.mergeChildOptions(options, child);
99 98
         presenter.mergeChildOptions(options, child);
100
-        animator.mergeOptions(options.animations);
101 99
         if (options.fabOptions.hasValue() && child instanceof ReactComponent) {
102 100
             fabOptionsPresenter.mergeOptions(options.fabOptions, (ReactComponent) child, getView());
103 101
         }
@@ -135,14 +133,14 @@ public class StackController extends ParentController<StackLayout> {
135 133
         addChildToStack(child, child.getView(), resolvedOptions);
136 134
 
137 135
         if (toRemove != null) {
138
-            if (child.options.animations.push.enable.isTrueOrUndefined()) {
136
+            if (resolvedOptions.animations.push.enable.isTrueOrUndefined()) {
139 137
                 if (resolvedOptions.animations.push.waitForRender.isTrue()) {
140
-                    child.setOnAppearedListener(() -> animator.push(child.getView(), () -> {
138
+                    child.setOnAppearedListener(() -> animator.push(child.getView(), resolvedOptions.animations.push, () -> {
141 139
                         getView().removeView(toRemove.getView());
142 140
                         listener.onSuccess(child.getId());
143 141
                     }));
144 142
                 } else {
145
-                    animator.push(child.getView(), () -> {
143
+                    animator.push(child.getView(), resolvedOptions.animations.push, () -> {
146 144
                         getView().removeView(toRemove.getView());
147 145
                         listener.onSuccess(child.getId());
148 146
                     });
@@ -194,16 +192,16 @@ public class StackController extends ParentController<StackLayout> {
194 192
         final ViewController appearing = stack.peek();
195 193
         disappearing.onViewWillDisappear();
196 194
         appearing.onViewWillAppear();
195
+        Options resolvedOptions = resolveCurrentOptions();
197 196
         ViewGroup appearingView = appearing.getView();
198 197
         if (appearingView.getLayoutParams() == null) {
199 198
             appearingView.setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
200
-            Options options = resolveCurrentOptions();
201
-            presenter.applyLayoutParamsOptions(options, appearingView);
199
+            presenter.applyLayoutParamsOptions(resolvedOptions, appearingView);
202 200
         }
203 201
         getView().addView(appearingView, 0);
204 202
         presenter.onChildWillAppear(appearing.options, disappearing.options);
205 203
         if (disappearing.options.animations.pop.enable.isTrueOrUndefined()) {
206
-            animator.pop(disappearing.getView(), () -> finishPopping(disappearing, listener));
204
+            animator.pop(disappearing.getView(), resolvedOptions.animations.pop, () -> finishPopping(disappearing, listener));
207 205
         } else {
208 206
             finishPopping(disappearing, listener);
209 207
         }

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalAnimatorMock.java View File

@@ -14,7 +14,7 @@ public class ModalAnimatorMock extends ModalAnimator {
14 14
     }
15 15
 
16 16
     @Override
17
-    public void show(View view, AnimationOptions animation, AnimatorListenerAdapter listener) {
17
+    public void show(View view, AnimationOptions show, AnimatorListenerAdapter listener) {
18 18
         try {
19 19
             listener.onAnimationStart(null);
20 20
             Thread.sleep(10);
@@ -25,7 +25,7 @@ public class ModalAnimatorMock extends ModalAnimator {
25 25
     }
26 26
 
27 27
     @Override
28
-    public void dismiss(View view, AnimatorListenerAdapter listener) {
28
+    public void dismiss(View view, AnimationOptions dismiss, AnimatorListenerAdapter listener) {
29 29
         try {
30 30
             listener.onAnimationStart(null);
31 31
             Thread.sleep(10);

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java View File

@@ -149,7 +149,7 @@ public class ModalPresenterTest extends BaseTest {
149 149
             }
150 150
         });
151 151
 
152
-        verify(animator, times(1)).dismiss(eq(modal1.getView()), any());
152
+        verify(animator, times(1)).dismiss(eq(modal1.getView()), eq(modal1.options.animations.dismissModal), any());
153 153
     }
154 154
 
155 155
     @Test
@@ -170,7 +170,7 @@ public class ModalPresenterTest extends BaseTest {
170 170
         uut.dismissTopModal(modal1, root, new CommandListenerAdapter());
171 171
         verify(modal1, times(1)).onViewDisappear();
172 172
         verify(modal1, times(1)).destroy();
173
-        verify(animator, times(0)).dismiss(any(), any());
173
+        verify(animator, times(0)).dismiss(any(), eq(modal1.options.animations.dismissModal), any());
174 174
     }
175 175
 
176 176
     @Test

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java View File

@@ -160,8 +160,8 @@ public class ModalStackTest extends BaseTest {
160 160
         CommandListener listener = spy(new CommandListenerAdapter());
161 161
         uut.dismissAllModals(listener, rootController);
162 162
         verify(presenter, times(1)).dismissTopModal(modal2, rootController, listener);
163
-        verify(animator, times(0)).dismiss(eq(view1), any());
164
-        verify(animator, times(1)).dismiss(eq(view2), any());
163
+        verify(animator, times(0)).dismiss(eq(view1), eq(modal1.options.animations.dismissModal), any());
164
+        verify(animator, times(1)).dismiss(eq(view2), eq(modal2.options.animations.dismissModal), any());
165 165
         assertThat(uut.size()).isEqualTo(0);
166 166
     }
167 167
 

+ 5
- 15
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java View File

@@ -166,7 +166,7 @@ public class StackControllerTest extends BaseTest {
166 166
         child2.options.animations.push.waitForRender = new Bool(true);
167 167
         uut.push(child2, new CommandListenerAdapter());
168 168
         verify(child2).setOnAppearedListener(any());
169
-        verify(animator, times(0)).push(eq(child1.getView()), any());
169
+        verify(animator, times(0)).push(eq(child1.getView()), eq(child1.options.animations.push), any());
170 170
     }
171 171
 
172 172
     @Test
@@ -484,9 +484,9 @@ public class StackControllerTest extends BaseTest {
484 484
                 uut.popTo(child2, new CommandListenerAdapter() {
485 485
                     @Override
486 486
                     public void onSuccess(String childId) {
487
-                        verify(animator, times(0)).pop(eq(child1.getView()), any());
488
-                        verify(animator, times(0)).pop(eq(child2.getView()), any());
489
-                        verify(animator, times(1)).pop(eq(child4.getView()), any());
487
+                        verify(animator, times(0)).pop(eq(child1.getView()), any(), any());
488
+                        verify(animator, times(0)).pop(eq(child2.getView()), any(), any());
489
+                        verify(animator, times(1)).pop(eq(child4.getView()), eq(child4.options.animations.push), any());
490 490
                     }
491 491
                 });
492 492
             }
@@ -530,7 +530,7 @@ public class StackControllerTest extends BaseTest {
530 530
                 uut.popToRoot(new CommandListenerAdapter() {
531 531
                     @Override
532 532
                     public void onSuccess(String childId) {
533
-                        verify(animator, times(1)).pop(eq(child3.getView()), any());
533
+                        verify(animator, times(1)).pop(eq(child3.getView()), eq(child3.options.animations.pop), any());
534 534
                     }
535 535
                 });
536 536
             }
@@ -789,16 +789,6 @@ public class StackControllerTest extends BaseTest {
789 789
         assertThat(captor.getValue().bottomTabsOptions.testId.get()).isEqualTo(optionsToMerge.bottomTabsOptions.testId.get());
790 790
     }
791 791
 
792
-    @Test
793
-    public void mergeChildOptions_mergeAnimationOptions() {
794
-        Options options = new Options();
795
-        Component component = mock(Component.class);
796
-
797
-        uut.mergeChildOptions(options, component);
798
-        verify(animator, times(0)).setOptions(options.animations);
799
-        verify(animator, times(1)).mergeOptions(options.animations);
800
-    }
801
-
802 792
     @Test
803 793
     public void mergeChildOptions_StackRelatedOptionsAreCleared() {
804 794
         uut.ensureViewIsCreated();