From 8fac1c6f1238783ccf70a9642c20bc9d0ad69ccb Mon Sep 17 00:00:00 2001 From: seanamos Date: Tue, 14 Oct 2025 22:03:46 -0400 Subject: [PATCH 1/2] Interrupt magellan transition animation when navigating between pages to ensure intercept touch events is set and reset properly. --- .../wealthfront/magellan/navigation/NavigationDelegate.kt | 3 +++ .../wealthfront/magellan/transitions/DefaultTransition.kt | 8 ++++---- .../java/com/wealthfront/magellan/sample/IntroStep.kt | 3 +++ magellan-sample/src/main/res/layout/learn_more.xml | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt b/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt index 35e63f1e..fd1159ed 100644 --- a/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt +++ b/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt @@ -29,6 +29,7 @@ public open class NavigationDelegate( public var currentNavigableSetup: ((NavigableCompat) -> Unit)? = null + private var activeTransition: MagellanTransition? = null private var templatedViewMap = HashMap() protected var containerView: ScreenContainer? = null @@ -75,6 +76,7 @@ public open class NavigationDelegate( direction: Direction, backStackOperation: (Deque) -> MagellanTransition ) { + activeTransition?.interrupt() containerView?.setInterceptTouchEvents(true) navigationPropagator.beforeNavigation() val oldBackStack = backStack.map { it.navigable } @@ -140,6 +142,7 @@ public open class NavigationDelegate( } else { NoAnimationTransition() } + activeTransition = transition transition.animate(from, to, direction) { if (context != null && containerView != null) { containerView!!.removeView(from) diff --git a/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt b/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt index 7e2ca88b..91081ead 100644 --- a/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt +++ b/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt @@ -21,7 +21,7 @@ public class DefaultTransition : MagellanTransition { private var animator: Animator? = null override fun interrupt() { - animator?.end() + animator?.cancel() } override fun animate( @@ -48,15 +48,15 @@ public class DefaultTransition : MagellanTransition { ): AnimatorSet { val sign = direction.sign() val axis: Property = View.TRANSLATION_X - val toTranslation = sign * to.width + val toTranslation = sign * to.width + (from?.translationX ?: 0f) val set = AnimatorSet() if (from != null) { val fromTranslation = sign * -from.width - val fromAnimation = ObjectAnimator.ofFloat(from, axis, 0f, fromTranslation.toFloat()) + val fromAnimation = ObjectAnimator.ofFloat(from, axis, from.translationX, fromTranslation.toFloat()) set.play(fromAnimation) } - val toAnimation = ObjectAnimator.ofFloat(to, axis, toTranslation.toFloat(), 0f) + val toAnimation = ObjectAnimator.ofFloat(to, axis, toTranslation, 0f) set.play(toAnimation) set.interpolator = FastOutSlowInInterpolator() return set diff --git a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt index 118a1144..5da33ec2 100644 --- a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt +++ b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt @@ -9,7 +9,10 @@ internal class IntroStep( ) : Step(IntroBinding::inflate) { override fun onShow(context: Context, binding: IntroBinding) { + binding.root.tag = "IntroStep" binding.learnMore.setOnClickListener { + println("viewBinding: $viewBinding") + viewBinding!! goToLearnMore() } } diff --git a/magellan-sample/src/main/res/layout/learn_more.xml b/magellan-sample/src/main/res/layout/learn_more.xml index 88ef302d..7dad975e 100644 --- a/magellan-sample/src/main/res/layout/learn_more.xml +++ b/magellan-sample/src/main/res/layout/learn_more.xml @@ -6,6 +6,7 @@ android:layout_height="match_parent" android:background="@color/colorCyan" android:orientation="vertical" + android:tag="LearnMore" tools:ignore="Overdraw" > From 55c9bd7fd83ed2c544746dd5d06a38859094d885 Mon Sep 17 00:00:00 2001 From: seanamos Date: Wed, 15 Oct 2025 09:41:16 -0400 Subject: [PATCH 2/2] Clear transition after animation end. Also adjust transition duration as a function of the distance the from / to views need to travel. --- .../com/wealthfront/magellan/navigation/NavigationDelegate.kt | 2 ++ .../com/wealthfront/magellan/transitions/DefaultTransition.kt | 1 + .../src/main/java/com/wealthfront/magellan/sample/IntroStep.kt | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt b/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt index fd1159ed..839d6e30 100644 --- a/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt +++ b/magellan-library/src/main/java/com/wealthfront/magellan/navigation/NavigationDelegate.kt @@ -65,6 +65,7 @@ public open class NavigationDelegate( override fun onHide(context: Context) { containerView = null templatedViewMap.clear() + activeTransition = null } override fun onDestroy(context: Context) { @@ -149,6 +150,7 @@ public open class NavigationDelegate( currentNavigable!!.transitionFinished() navigationPropagator.afterNavigation() containerView!!.setInterceptTouchEvents(false) + activeTransition = null } } } diff --git a/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt b/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt index 91081ead..d5128fab 100644 --- a/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt +++ b/magellan-library/src/main/java/com/wealthfront/magellan/transitions/DefaultTransition.kt @@ -54,6 +54,7 @@ public class DefaultTransition : MagellanTransition { val fromTranslation = sign * -from.width val fromAnimation = ObjectAnimator.ofFloat(from, axis, from.translationX, fromTranslation.toFloat()) set.play(fromAnimation) + set.duration = (300 * (1.0f - (from.translationX / from.width))).toLong() } val toAnimation = ObjectAnimator.ofFloat(to, axis, toTranslation, 0f) diff --git a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt index 5da33ec2..8e755037 100644 --- a/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt +++ b/magellan-sample/src/main/java/com/wealthfront/magellan/sample/IntroStep.kt @@ -11,8 +11,6 @@ internal class IntroStep( override fun onShow(context: Context, binding: IntroBinding) { binding.root.tag = "IntroStep" binding.learnMore.setOnClickListener { - println("viewBinding: $viewBinding") - viewBinding!! goToLearnMore() } }