Skip to content

Commit

Permalink
Add animation support for setStackRoot (#5357)
Browse files Browse the repository at this point in the history
Fixed Android's native setStackRoot animation and added animation support for Android's setStackRoot.
  • Loading branch information
Jazqa authored and guyca committed Sep 3, 2019
1 parent aef5b2e commit d0a17fa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static AnimationsOptions parse(JSONObject json) {

options.push = NestedAnimationsOptions.parse(json.optJSONObject("push"));
options.pop = NestedAnimationsOptions.parse(json.optJSONObject("pop"));
options.setStackRoot = NestedAnimationsOptions.parse(json.optJSONObject("setStackRoot"));
options.setRoot = AnimationOptions.parse(json.optJSONObject("setRoot"));
options.showModal = AnimationOptions.parse(json.optJSONObject("showModal"));
options.dismissModal = AnimationOptions.parse(json.optJSONObject("dismissModal"));
Expand All @@ -20,6 +21,7 @@ public static AnimationsOptions parse(JSONObject json) {

public NestedAnimationsOptions push = new NestedAnimationsOptions();
public NestedAnimationsOptions pop = new NestedAnimationsOptions();
public NestedAnimationsOptions setStackRoot = new NestedAnimationsOptions();
public AnimationOptions setRoot = new AnimationOptions();
public AnimationOptions showModal = new AnimationOptions();
public AnimationOptions dismissModal = new AnimationOptions();
Expand All @@ -28,13 +30,15 @@ public void mergeWith(AnimationsOptions other) {
push.mergeWith(other.push);
pop.mergeWith(other.pop);
setRoot.mergeWith(other.setRoot);
setStackRoot.mergeWith(other.setStackRoot);
showModal.mergeWith(other.showModal);
dismissModal.mergeWith(other.dismissModal);
}

void mergeWithDefault(AnimationsOptions defaultOptions) {
push.mergeWithDefault(defaultOptions.push);
pop.mergeWithDefault(defaultOptions.pop);
setStackRoot.mergeWithDefault(defaultOptions.setStackRoot);
setRoot.mergeWithDefault(defaultOptions.setRoot);
showModal.mergeWithDefault(defaultOptions.showModal);
dismissModal.mergeWithDefault(defaultOptions.dismissModal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,27 @@ private void addChildToStack(ViewController child, View view, Options resolvedOp

public void setRoot(List<ViewController> children, CommandListener listener) {
animator.cancelPushAnimations();
final ViewController toRemove = stack.peek();
IdStack stackToDestroy = stack;
stack = new IdStack<>();

ViewController child = last(children);
if (children.size() == 1) {
backButtonHelper.clear(last(children));
push(last(children), new CommandListenerAdapter() {
@Override
public void onSuccess(String childId) {
destroyStack(stackToDestroy);
listener.onSuccess(childId);
}
});
backButtonHelper.clear(child);
} else {
backButtonHelper.addToPushedChild(last(children));
push(last(children), new CommandListenerAdapter() {
@Override
public void onSuccess(String childId) {
destroyStack(stackToDestroy);
backButtonHelper.addToPushedChild(child);
}

child.setParentController(this);
stack.push(child.getId(), child);
Options resolvedOptions = resolveCurrentOptions(presenter.getDefaultOptions());
addChildToStack(child, child.getView(), resolvedOptions);

CommandListener listenerAdapter = new CommandListenerAdapter() {
@Override
public void onSuccess(String childId) {
destroyStack(stackToDestroy);
if (children.size() > 1) {
for (int i = 0; i < children.size() - 1; i++) {
stack.set(children.get(i).getId(), children.get(i), i);
children.get(i).setParentController(StackController.this);
Expand All @@ -209,9 +213,24 @@ public void onSuccess(String childId) {
backButtonHelper.addToPushedChild(children.get(i));
}
}
listener.onSuccess(childId);
}
});
listener.onSuccess(childId);
}
};

if (toRemove != null && resolvedOptions.animations.setStackRoot.enabled.isTrueOrUndefined()) {
if (resolvedOptions.animations.setStackRoot.waitForRender.isTrue()) {
child.getView().setAlpha(0);
child.addOnAppearedListener(() -> animator.push(child.getView(), resolvedOptions.animations.setStackRoot, resolvedOptions.transitions, toRemove.getElements(), child.getElements(), () -> {
listenerAdapter.onSuccess(child.getId());
}));
} else {
animator.push(child.getView(), resolvedOptions.animations.setStackRoot, () -> {
listenerAdapter.onSuccess(child.getId());
});
}
} else {
listenerAdapter.onSuccess(child.getId());
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@
}
}
}
}
}

0 comments on commit d0a17fa

Please sign in to comment.