Created
March 16, 2021 19:05
-
-
Save pauloaapereira/9c8540ba69d59ab277090ddbc7db07f8 to your computer and use it in GitHub Desktop.
Jetpack Compose — Drawer Pushing Content - 6
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 | |
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