Skip to content

Instantly share code, notes, and snippets.

@chenzhang2006
Last active October 19, 2022 00:02
Show Gist options
  • Save chenzhang2006/c227eed34c95b365a78759f406af81d8 to your computer and use it in GitHub Desktop.
Save chenzhang2006/c227eed34c95b365a78759f406af81d8 to your computer and use it in GitHub Desktop.
Introductory Bounce Effect
val backdropState = rememberBackdropScaffoldState(Revealed)
var offset by (backdropState.offset as MutableState)
// Optional conditions: ex. should-bounce flag, data-loading finished, etc.
if (backdropState.isRevealed) {
// remember the original offset position to go back to
val revealedOffset = remember { backdropState.offset.value }
// value holder Animatable for the actual offset
val offsetAnimatable = remember { Animatable(revealedOffset) }
LaunchedEffect(Unit) {
// lift up by 150 pixels with tween animation spec
offsetAnimatable.animateTo(
targetValue = revealedOffset - 150,
animationSpec = tween(800)
)
// drop down back to original offset with spring animation spec
offsetAnimatable.animateTo(
targetValue = revealedOffset,
animationSpec = spring(
dampingRatio = 0.4f,
stiffness = Spring.StiffnessLow
)
)
}
// drive offset mutableState with Animatable values
offset = offsetAnimatable.value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment