Skip to content

Commit 32dd354

Browse files
mrousavyguyca
andauthored
Fix default alpha animation being reversed (#6709)
If you comment out [these](https://github.com/wix/react-native-navigation/blob/master/playground/src/screens/sharedElementTransition/CocktailsListScreen.tsx#L51-L57) and [these](https://github.com/wix/react-native-navigation/blob/master/playground/src/screens/sharedElementTransition/CocktailsListScreen.tsx#L93-L99) lines in the playground demo, then test the Cocktails screen and select your favourite gin cocktail (@danilobuerger !!!!), you can notice that on popping the alpha animation is reversed. You'd expect it to go from visible (opacity of `1`) to invisible (opacity of `0`), but instead it jumps to `0` and then goes to `1` making it look really weird. This PR changes this default behavior to reverse the default `FadeAnimation` on pop. Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
1 parent d66b97f commit 32dd354

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/android/app/src/main/java/com/reactnativenavigation/options/FadeAnimation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import org.json.JSONObject;
55

66
public class FadeAnimation extends NestedAnimationsOptions {
7-
public FadeAnimation() {
7+
public FadeAnimation(boolean reversed) {
88
try {
99
JSONObject alpha = new JSONObject();
10-
alpha.put("from", 0);
11-
alpha.put("to", 1);
10+
alpha.put("from", reversed ? 1 : 0);
11+
alpha.put("to", reversed ? 0 : 1);
1212
alpha.put("duration", 300);
1313

1414
JSONObject content = new JSONObject();
@@ -21,4 +21,8 @@ public FadeAnimation() {
2121
e.printStackTrace();
2222
}
2323
}
24+
25+
public FadeAnimation() {
26+
this(false);
27+
}
2428
}

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackAnimator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ open class StackAnimator @JvmOverloads constructor(
7373
}
7474

7575
private suspend fun popWithElementTransitions(appearing: ViewController<*>, disappearing: ViewController<*>, pop: NestedAnimationsOptions, set: AnimatorSet) {
76-
val fade = if (pop.content.isFadeAnimation()) pop else FadeAnimation()
76+
val fade = if (pop.content.isFadeAnimation()) pop else FadeAnimation(true)
7777
val transitionAnimators = transitionAnimatorCreator.create(pop, fade.content, disappearing, appearing)
7878
set.playTogether(fade.content.getAnimation(disappearing.view), transitionAnimators)
7979
transitionAnimators.listeners.forEach { listener: Animator.AnimatorListener -> set.addListener(listener) }

0 commit comments

Comments
 (0)