Skip to content

Instantly share code, notes, and snippets.

@pauloaapereira
Last active March 18, 2021 19:24
Show Gist options
  • Save pauloaapereira/0baccd08045ef2f325cd985ee5067b1f to your computer and use it in GitHub Desktop.
Save pauloaapereira/0baccd08045ef2f325cd985ee5067b1f to your computer and use it in GitHub Desktop.
AndroidDevChallenge_Week4_JetWeatherfy_5
@Composable
fun Curtain(
isOpenedFromOutside: Boolean? = null,
foldingDuration: Int = 250,
mainCell: @Composable () -> Unit,
foldCells: List<@Composable () -> Unit>
) {
var isOpened by remember { mutableStateOf(false) }
var isTransitionRunning by remember { mutableStateOf(false) }
val foldScope = rememberCoroutineScope()
fun toggleCurtain() {
if (!isTransitionRunning) {
isTransitionRunning = true
isOpened = !isOpened
foldScope.launch {
delay(foldingDuration.toLong() * foldCells.size)
isTransitionRunning = false
}
}
}
if (isOpenedFromOutside != null) {
isOpened = isOpenedFromOutside
}
Box(
modifier = Modifier.curtainModifier(isOpenedFromOutside != null, onClick = { toggleCurtain() })
) {
...
}
}
private fun Modifier.curtainModifier(externalControl: Boolean = false, onClick: () -> Unit): Modifier {
val modifier = wrapContentSize()
return if (!externalControl) modifier.clickable { onClick() } else modifier
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment