Last active
December 27, 2024 08:07
-
-
Save riggaroo/202fc73f7238a3dba4432731a2fe3d75 to your computer and use it in GitHub Desktop.
Simple Modifier.animateBounds() example
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
@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) | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
animateBounds.mp4