Shubham Singh
05/27/2025, 1:23 PM@Composable
fun MyTextField(errorMessage: (@Composable () -> Unit)? = null) {
var value by remember { mutableStateOf("") }
Column {
TextField(value = value, onValueChanged = { value = it })
// Here, the enter animation works as expected, but as soon as `errorMessage`
// becomes null, the `errorMessage` composable just snaps away instead of
// gracefully going out.
AnimatedVisibility(errorMessage != null) {
errorMessage?.invoke()
}
}
}
Seri
05/27/2025, 2:59 PMerrorMessage?.invoke()
. As soon as your error message goes null, there is no longer any content to display inside of your AnimatedVisibility block. The AnimatedVisibility is correctly animating and playing the exit, but the content inside of it snaps to nothing.Seri
05/27/2025, 3:01 PMerrorMessage == null
by showing a cache of what the message was before it became nullGrigory Panko
05/27/2025, 6:26 PMCrossfade
which doesn't have this problem (it composes each input individually)Shubham Singh
05/27/2025, 7:15 PMbrandonmcansh
05/27/2025, 7:51 PMerrorMessage
as the targetStateShubham Singh
05/28/2025, 5:50 AMShould also be able to use AnimatedContent withDoesn't work unfortunately :(( I tried both AnimatedContent and AnimatedVisibility Seri'sas the targetStateerrorMessage
cache
point makes sense, I was hoping compose would do it out of the box (like Flutter does) but maybe this is something I ought to take care of in Compose.brandonmcansh
05/28/2025, 10:43 AMIan Lake
05/28/2025, 10:13 PMShubham Singh
05/29/2025, 3:48 AMIan Lake
05/29/2025, 4:52 AMShubham Singh
05/29/2025, 5:35 AMString?
instead of (@Composable () -> Unit)?
doesn't help either. It produces the same animation effect. Only one of the animations work (either enter or exit, never both).
By any chance, do you have any example that has already implemented something like this?