https://kotlinlang.org logo
#compose
Title
# compose
j

Jan Skrasek

01/29/2021, 11:45 PM
My function has an argument
error: @Composable (() -> Unit)? = null
i.e. a rendering lambda of the error or a null. I want to animate that rendering, so I need to postpone "nulling" the error until the hide animation finishes. How can I remember the composable result?
Copy code
Box(
    modifier = Modifier
        .alpha(errorAlpha.value)
) {
    if (error != null) {
        error()
    }
}
This did the trick for me:
Copy code
var errorState by remember { mutableStateOf(error) }
if (error == null) {
    LaunchedEffect(this) {
        delay(AnimationDuration.toLong())
        errorState = null
    }
} else {
    errorState = error
}
2 Views