Zoltan Demant
07/03/2025, 7:37 AMCheckable(x) { .. }
and that works great.
When I instead have if(x) Checkable(true) { .. } else Checkable(false) { .. }
then the Switch composable differs between the two and jumps between the states instead of animating.
I think I know why - the context in which the switch is rendered differs, both checked & the lambda differs - but how can I fix that?
data class Checkable(
val checked: Boolean,
val enabled: Boolean = true,
val onCheckedChanged: (Boolean) -> Unit,
) : SettingsAction {
override val onClick = {
onCheckedChanged(!checked)
}
@Composable
override fun RowScope.Render() {
Switch(
checked = checked,
enabled = enabled,
onCheckedChanged = onCheckedChanged,
)
}
}
Zoltan Demant
07/03/2025, 7:38 AMDavid
07/03/2025, 7:40 AMrender
or a onClick
in a data class
, that are suppose to contain data, but anyway:
> When I instead have if(x) Checkable(true) { .. } else Checkable(false) { .. }
then the Switch composable differs between the two and jumps between the states instead of animating.
You are switching between two composables instead of using the same one. You can simplify the logic by simply writing Checkable(x)
Zoltan Demant
07/03/2025, 7:41 AMDavid
07/03/2025, 7:45 AMZoltan Demant
07/03/2025, 7:46 AMZoltan Demant
07/03/2025, 7:48 AMDavid
07/03/2025, 7:49 AMY(x)
? 🙃 let doesn't add anything in that case.Zoltan Demant
07/03/2025, 7:50 AMCheckable(false) {
scope.launch {
loading = true
requester.authorize()?.let { account ->
emitter emit AuthorizedSync(account)
}
loading = false
}
}.let { Loadable(loading, it) } <--