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

Jacob Ras

12/04/2023, 11:48 PM
For those using Voyager: is there any way to disable the default behaviour where every view model is being serialized? I'd rather do my own state handling instead of seeing complete repositories being serialized (and hunting crashes without a clear stack trace isn't very easy too). Or maybe I'm using it wrong and I shouldn't inject repositories/use cases into the screen models? Edit: fixed
j

Jacob Ras

12/05/2023, 9:24 AM
Ah, I found it! I had a
Tab
in which I passed down my
MainScreenModel
. I didn't see
Tab
was a
Screen
to, so that's why it was serializing it. I now use the navigator scoped inject for it and it works. Thanks a lot @Mitchell Syer!
🎉 1
o

Osman Saral

12/05/2023, 10:52 AM
Hi @Jacob Ras, What is navigator scoped inject? how did you implement it?
j
So before I passed my screen model down into the Tab's constructor but now I just inject it. Scoped on the navigator to get the same instance in all the tabs.
o

Osman Saral

12/05/2023, 10:59 AM
Oh okay, it's navigator scoped screenmodel. Thanks. I thought you were mentioning about a dependency injection solution 😅
🙂 1
j

Jacob Ras

12/05/2023, 11:00 AM
I like Koin 🙂
o

Osman Saral

12/05/2023, 11:00 AM
there is also this pr for viewmodel's.
I use Koin too. But I couldn't scope the ViewModel to a group of screens. Tried scoped injection but it didn't work out well
j

Jacob Ras

12/05/2023, 11:03 AM
Hm, I haven't tried more complicated scoping than the thing mentioned above yet
o

Osman Saral

12/05/2023, 11:03 AM
🙏
j

Jacob Ras

12/05/2023, 3:53 PM
Hm, I think I actually run into the same issue. The navigator scoped one doesn't work well in my situation, it gets a different instance inside the tabs than outside. I've now resorted to making my
MainScreenModel
a singleton. There will always be one of that in my app anyway, so luckily that works for me.
o

Osman Saral

12/06/2023, 6:36 AM
I've binded my androidx ViewModel to the lifecycle of the activity. Maybe you can do the same with the Voyager ScreenModel. I'm not sure what difference it will make though
16 Views