For those using Voyager: is there any way to disab...
# multiplatform
j
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
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
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
Oh okay, it's navigator scoped screenmodel. Thanks. I thought you were mentioning about a dependency injection solution 😅
🙂 1
j
I like Koin 🙂
o
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
Hm, I haven't tried more complicated scoping than the thing mentioned above yet
o
🙏
j
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
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