Skip to content

Instantly share code, notes, and snippets.

@pauloaapereira
Created March 16, 2021 19:05
Show Gist options
  • Save pauloaapereira/9c8540ba69d59ab277090ddbc7db07f8 to your computer and use it in GitHub Desktop.
Save pauloaapereira/9c8540ba69d59ab277090ddbc7db07f8 to your computer and use it in GitHub Desktop.
Jetpack Compose — Drawer Pushing Content - 6
@Composable
fun DrawerContainer(
modifier: Modifier = Modifier,
isDrawerOpened: Boolean = false,
drawerWidth: Dp = 200.dp,
onSwipe: (Boolean) -> Unit = {},
content: @Composable () -> Unit
) {
val transition = updateTransition(targetState = isDrawerOpened)
val collapseFraction =
transition.animateFloat(transitionSpec = { tween(durationMillis = 400) }) { state ->
when (state) {
false -> 0f
true -> 1f
}
}
Layout(
modifier = modifier.pointerInput(Unit) {
detectHorizontalDragGestures { _, dragAmount ->
if (!transition.isRunning) {
onSwipe(dragAmount > 0)
}
}
},
content = content
) { measurables, constraints ->
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment