Browse Source

Add animation support for setStackRoot (#5357)

Fixed Android's native setStackRoot animation and added animation support for Android's setStackRoot.
Jasu 5 years ago
parent
commit
d0a17fabf4

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/AnimationsOptions.java View File

11
 
11
 
12
         options.push = NestedAnimationsOptions.parse(json.optJSONObject("push"));
12
         options.push = NestedAnimationsOptions.parse(json.optJSONObject("push"));
13
         options.pop = NestedAnimationsOptions.parse(json.optJSONObject("pop"));
13
         options.pop = NestedAnimationsOptions.parse(json.optJSONObject("pop"));
14
+        options.setStackRoot = NestedAnimationsOptions.parse(json.optJSONObject("setStackRoot"));
14
         options.setRoot = AnimationOptions.parse(json.optJSONObject("setRoot"));
15
         options.setRoot = AnimationOptions.parse(json.optJSONObject("setRoot"));
15
         options.showModal = AnimationOptions.parse(json.optJSONObject("showModal"));
16
         options.showModal = AnimationOptions.parse(json.optJSONObject("showModal"));
16
         options.dismissModal = AnimationOptions.parse(json.optJSONObject("dismissModal"));
17
         options.dismissModal = AnimationOptions.parse(json.optJSONObject("dismissModal"));
20
 
21
 
21
     public NestedAnimationsOptions push = new NestedAnimationsOptions();
22
     public NestedAnimationsOptions push = new NestedAnimationsOptions();
22
     public NestedAnimationsOptions pop = new NestedAnimationsOptions();
23
     public NestedAnimationsOptions pop = new NestedAnimationsOptions();
24
+    public NestedAnimationsOptions setStackRoot = new NestedAnimationsOptions();
23
     public AnimationOptions setRoot = new AnimationOptions();
25
     public AnimationOptions setRoot = new AnimationOptions();
24
     public AnimationOptions showModal = new AnimationOptions();
26
     public AnimationOptions showModal = new AnimationOptions();
25
     public AnimationOptions dismissModal = new AnimationOptions();
27
     public AnimationOptions dismissModal = new AnimationOptions();
28
         push.mergeWith(other.push);
30
         push.mergeWith(other.push);
29
         pop.mergeWith(other.pop);
31
         pop.mergeWith(other.pop);
30
         setRoot.mergeWith(other.setRoot);
32
         setRoot.mergeWith(other.setRoot);
33
+        setStackRoot.mergeWith(other.setStackRoot);
31
         showModal.mergeWith(other.showModal);
34
         showModal.mergeWith(other.showModal);
32
         dismissModal.mergeWith(other.dismissModal);
35
         dismissModal.mergeWith(other.dismissModal);
33
     }
36
     }
35
     void mergeWithDefault(AnimationsOptions defaultOptions) {
38
     void mergeWithDefault(AnimationsOptions defaultOptions) {
36
         push.mergeWithDefault(defaultOptions.push);
39
         push.mergeWithDefault(defaultOptions.push);
37
         pop.mergeWithDefault(defaultOptions.pop);
40
         pop.mergeWithDefault(defaultOptions.pop);
41
+        setStackRoot.mergeWithDefault(defaultOptions.setStackRoot);
38
         setRoot.mergeWithDefault(defaultOptions.setRoot);
42
         setRoot.mergeWithDefault(defaultOptions.setRoot);
39
         showModal.mergeWithDefault(defaultOptions.showModal);
43
         showModal.mergeWithDefault(defaultOptions.showModal);
40
         dismissModal.mergeWithDefault(defaultOptions.dismissModal);
44
         dismissModal.mergeWithDefault(defaultOptions.dismissModal);

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

183
 
183
 
184
     public void setRoot(List<ViewController> children, CommandListener listener) {
184
     public void setRoot(List<ViewController> children, CommandListener listener) {
185
         animator.cancelPushAnimations();
185
         animator.cancelPushAnimations();
186
+        final ViewController toRemove = stack.peek();
186
         IdStack stackToDestroy = stack;
187
         IdStack stackToDestroy = stack;
187
         stack = new IdStack<>();
188
         stack = new IdStack<>();
189
+
190
+        ViewController child = last(children);
188
         if (children.size() == 1) {
191
         if (children.size() == 1) {
189
-            backButtonHelper.clear(last(children));
190
-            push(last(children), new CommandListenerAdapter() {
191
-                @Override
192
-                public void onSuccess(String childId) {
193
-                    destroyStack(stackToDestroy);
194
-                    listener.onSuccess(childId);
195
-                }
196
-            });
192
+            backButtonHelper.clear(child);
197
         } else {
193
         } else {
198
-            backButtonHelper.addToPushedChild(last(children));
199
-            push(last(children), new CommandListenerAdapter() {
200
-                @Override
201
-                public void onSuccess(String childId) {
202
-                    destroyStack(stackToDestroy);
194
+            backButtonHelper.addToPushedChild(child);
195
+        }
196
+
197
+        child.setParentController(this);
198
+        stack.push(child.getId(), child);
199
+        Options resolvedOptions = resolveCurrentOptions(presenter.getDefaultOptions());
200
+        addChildToStack(child, child.getView(), resolvedOptions);
201
+
202
+        CommandListener listenerAdapter = new CommandListenerAdapter() {
203
+            @Override
204
+            public void onSuccess(String childId) {
205
+                destroyStack(stackToDestroy);
206
+                if (children.size() > 1) {
203
                     for (int i = 0; i < children.size() - 1; i++) {
207
                     for (int i = 0; i < children.size() - 1; i++) {
204
                         stack.set(children.get(i).getId(), children.get(i), i);
208
                         stack.set(children.get(i).getId(), children.get(i), i);
205
                         children.get(i).setParentController(StackController.this);
209
                         children.get(i).setParentController(StackController.this);
209
                             backButtonHelper.addToPushedChild(children.get(i));
213
                             backButtonHelper.addToPushedChild(children.get(i));
210
                         }
214
                         }
211
                     }
215
                     }
212
-                    listener.onSuccess(childId);
213
                 }
216
                 }
214
-            });
217
+                listener.onSuccess(childId);
218
+            }
219
+        };
220
+
221
+        if (toRemove != null && resolvedOptions.animations.setStackRoot.enabled.isTrueOrUndefined()) {
222
+            if (resolvedOptions.animations.setStackRoot.waitForRender.isTrue()) {
223
+                child.getView().setAlpha(0);
224
+                child.addOnAppearedListener(() -> animator.push(child.getView(), resolvedOptions.animations.setStackRoot, resolvedOptions.transitions, toRemove.getElements(), child.getElements(), () -> {
225
+                    listenerAdapter.onSuccess(child.getId());
226
+                }));
227
+            } else {
228
+                animator.push(child.getView(), resolvedOptions.animations.setStackRoot, () -> {
229
+                    listenerAdapter.onSuccess(child.getId());
230
+                });
231
+            }
232
+        } else {
233
+            listenerAdapter.onSuccess(child.getId());
215
         }
234
         }
216
     }
235
     }
217
 
236
 

+ 1
- 1
package.json View File

166
       }
166
       }
167
     }
167
     }
168
   }
168
   }
169
-}
169
+}