Closed asapha closed 2 years ago
Hmm, that's super weird. The checks for the VM being cleared happen when the VM's CoroutineScope
is cancelled (which is when the Androidx VM gets onCleared()
). I'm wondering if something with the navigation lib transitions would be the main culprit (leave a screen > VM gets cleared > during transition the TextField loses focus and attempts to call onValueChange
).
Regardless, it sounds like it would be better to make the trySend
method less strict, than trying to fight the navigation lib. If the VM is cleared, return a failed ChannelResult
rather than crashing. The vm.send()
should probably remain strict, but vm.trySend()
could be relaxed.
Could you open a PR to remove the check? Should be able to just remove the check from here
This fix has been released and is available in version 1.2.1. Thanks again for the PR to fix it!
Hi,
I'm seeing a few crashes from users exiting a specific screen. As the app uses Compose's
NavHost
, the culprit VM is scoped to aNavBackStackEntry
.I can't reproduce the crash on my devices but here's what I could gather:
OutlinedTextField
(uses aTextFieldValue
)checkValidState
To investigate, I've overridden my ViewModel's
onCleared
And added logs to onValueChange
Then, with a Pixel 4A 5G: It's possible to have
onValueChange
displayed afteronCleared
, but only if the cursor is not placed at the end of the OutlinedTextField. (Note that it doesn't crash for me asBallastViewModelImpl.onCleared
hasn't been called yet)But on a LGV30,
onValueChange
is never displayed afteronCleared
…Not sure if ballast is too strict or if compose doesn't respect some sort of contract here, what do you think?
Stacktrace:
ballast version
1.1.0
compose version:1.2.0-beta02