Last active
October 19, 2022 00:02
-
-
Save chenzhang2006/c227eed34c95b365a78759f406af81d8 to your computer and use it in GitHub Desktop.
Introductory Bounce Effect
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
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