Skip to content

Instantly share code, notes, and snippets.

@riggaroo
Last active December 27, 2024 08:07
Show Gist options
  • Save riggaroo/202fc73f7238a3dba4432731a2fe3d75 to your computer and use it in GitHub Desktop.
Save riggaroo/202fc73f7238a3dba4432731a2fe3d75 to your computer and use it in GitHub Desktop.
Simple Modifier.animateBounds() example
@OptIn(ExperimentalSharedTransitionApi::class)
@Preview
@Composable
private fun AnimateBoundsSimple() {
// We need the SharedTransitionLayout in order for the animateBounds modifier to have a
// lookaheadScope to use.
SharedTransitionLayout {
var position by remember {
mutableStateOf(true)
}
Box(modifier = Modifier
.fillMaxSize()
.padding(16.dp)) {
Box(
modifier = Modifier
.clickable {
position = !position
}
.align(if (position) Alignment.TopCenter else Alignment.BottomEnd)
// We add the animateBounds modifier passing in the lookaheadScope, and a
// custom boundsTransform to indicate how long it should take.
.animateBounds(
lookaheadScope = this@SharedTransitionLayout,
boundsTransform = { _, _ ->
tween(3000)
}
)
.size(50.dp)
.background(Color(0xFFF06292), CircleShape)
)
}
}
}
@riggaroo
Copy link
Author

animateBounds.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment