-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve pane transitions in bank auth flow
- Loading branch information
1 parent
12f37a0
commit ae684c9
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ncial-connections/src/main/java/com/stripe/android/financialconnections/ui/Transitions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.stripe.android.financialconnections.ui | ||
|
||
import androidx.compose.animation.AnimatedContentTransitionScope | ||
import androidx.compose.animation.EnterTransition | ||
import androidx.compose.animation.ExitTransition | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.animation.slideInHorizontally | ||
import androidx.compose.animation.slideOutHorizontally | ||
import androidx.navigation.NavBackStackEntry | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsSessionManifest.Pane.ATTACH_LINKED_PAYMENT_ACCOUNT | ||
import com.stripe.android.financialconnections.navigation.pane | ||
|
||
private const val TransitionDurationMillis = 300 | ||
|
||
private val FADE_IN_TRANSITION = fadeIn( | ||
animationSpec = tween(TransitionDurationMillis) | ||
) | ||
|
||
private val FADE_OUT_TRANSITION = fadeOut( | ||
animationSpec = tween(TransitionDurationMillis) | ||
) | ||
|
||
internal fun enterTransition(): AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition { | ||
return { | ||
if (initialState.skipTransition) { | ||
FADE_IN_TRANSITION | ||
} else { | ||
FADE_IN_TRANSITION + slideInHorizontally( | ||
animationSpec = tween(TransitionDurationMillis), | ||
initialOffsetX = { fullWidth -> | ||
fullWidth / 2 | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal fun resumeTransition(): AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition { | ||
return { | ||
if (initialState.skipTransition) { | ||
FADE_IN_TRANSITION | ||
} else { | ||
FADE_IN_TRANSITION + slideInHorizontally( | ||
animationSpec = tween(TransitionDurationMillis), | ||
initialOffsetX = { fullWidth -> | ||
-fullWidth / 2 | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal fun pauseTransition(): AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition { | ||
return { | ||
if (initialState.skipTransition) { | ||
FADE_OUT_TRANSITION | ||
} else { | ||
FADE_OUT_TRANSITION + slideOutHorizontally( | ||
animationSpec = tween(TransitionDurationMillis), | ||
targetOffsetX = { fullWidth -> | ||
-fullWidth / 2 | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal fun exitTransition(): AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition { | ||
return { | ||
if (initialState.skipTransition) { | ||
FADE_OUT_TRANSITION | ||
} else { | ||
FADE_OUT_TRANSITION + slideOutHorizontally( | ||
animationSpec = tween(TransitionDurationMillis), | ||
targetOffsetX = { fullWidth -> | ||
fullWidth / 2 | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* We want to skip the transition for some screens and use a simple fade instead. This | ||
*/ | ||
private val NavBackStackEntry.skipTransition: Boolean | ||
get() = destination.pane == ATTACH_LINKED_PAYMENT_ACCOUNT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters