Mark
07/30/2023, 9:01 AMgetViewModel()
from within a compose Dialog
. Since the viewmodel is scoped to the fragment, the same viewmodel instance is returned each time (furthermore, this is regardless of any parametersOf
args). So, how are we supposed to deal with this? I want to get a new instance every time the user taps on whatever to bring up the Dialog
. Only the same instance should be returned with there is a config change etc. This is particularly an issue when the dialog contains a text field, because consider when the user makes some edit to the text and then hits cancel. By default, the dialog will show the old cancelled text when next invoked, unless we take care to reset all relevant MutableState
which seems like something we shouldn’t need to handle.
I know this has been asked previously, but I haven’t seen any proper solution.Mark
07/30/2023, 10:08 AMkey
at the moment the click (to bring up dialog) is handled, and then pass that key
to the getViewModel
call. But this feels very hacky.arnaud.giuliani
07/31/2023, 8:17 AMMark
07/31/2023, 8:17 AMDialog
to have its own ViewModelStore