Last active
February 18, 2024 23:08
-
-
Save rmyhal/491f384b722568a1340f122a7c372f95 to your computer and use it in GitHub Desktop.
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
@Composable | |
private fun FabContainer( | |
modifier: Modifier = Modifier, | |
) { | |
var containerState by remember { mutableStateOf(ContainerState.Fab) } | |
val transition = updateTransition(targetState = containerState) | |
val backgroundColor by transition.animateColor { state -> | |
when (state) { | |
ContainerState.Fab -> Colors.fabContainerColor | |
ContainerState.Fullscreen -> Colors.surface | |
} | |
} | |
val cornerRadius by transition.animateDp { state -> | |
when (state) { | |
ContainerState.Fab -> 22.dp | |
ContainerState.Fullscreen -> 0.dp | |
} | |
} | |
val elevation by transition.animateDp { ... } | |
val padding by transition.animateDp { ... } | |
transition.AnimatedContent( | |
modifier = modifier | |
// padding, shadow, and backgroundColor are shared between composables | |
.padding(end = padding, bottom = padding) | |
.shadow( | |
elevation = elevation, | |
shape = RoundedCornerShape(cornerRadius) | |
) | |
.drawBehind { drawRect(backgroundColor) } | |
) { state -> | |
when (state) { | |
ContainerState.Fab -> Fab() | |
ContainerState.Fullscreen -> AddContentScreen() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment