adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.38k stars 115 forks source link

multiplatform state restoration #290

Open diegoberaldin opened 6 months ago

diegoberaldin commented 6 months ago

I am using Voyager in a multiplatform project to share screens and screen models and, in order to have state restoration properly working, I followed the guide in the documentation which worked seamlessly. Some of my users reported that this approach is not going to work with the K2 Kotlin compiler because the frontend is run just once on the common code and typealiases are not going to work.

See this issue and this other issue.

Unfortunately Jetbrains it definitely not going to change its compiler for us so we have to find another way. An option would be to pass only strings as screen arguments and deserialize them manually with kotlinx.serialization. Are there any options that come to your mind?

Syer10 commented 6 months ago

The typealias can just be changed to

actual interface JavaSerializable : java.io.Serializable
diegoberaldin commented 6 months ago

The first time you try to reference a type which is a subtype of that interface from common code it breaks everything apparently.

Cannot access "JavaSerializable' which is a supertype of 'X'. Check your module classpath for missing or conflicting dependencies.

MV-GH commented 6 months ago

That approach won't work at all and any similar hacks for K2.

see this issue that goes in depth

diegoberaldin commented 6 months ago

Even if client apps can adopt workarounds to avoid non-primitive arguments to screens, since the library is using it internally I expect that unless something gets done we'll have to switch to something else.

DevSrSouza commented 5 months ago

We accept suggestion. I will investigate that.

DevSrSouza commented 5 months ago

About Kotlinx.serialization and voyager state restauration, this is something I din't have time to write a proof of concept, but it is on my todo list.

diegoberaldin commented 5 months ago

There are still some months ahead (but this needs to be considered for the 2024 roadmap anyway). Please consider me in case I can be of any help, I like the library and I would be glad to contribute in some way.

cryptrr commented 5 months ago

Screen state restoration is broken as of now.

terrakok commented 3 weeks ago

I see the documentation says that users need to restore a state on JVM platforms only but it is not true. The library has to provide an easy way to restore the state on the iOS side too

https://medium.com/swift-india/app-state-restoration-in-ios-1-bbc903f17a46

Moreover, at the moment the approach seems as a something extra and need to be implemented in a manual mode. It does the library not so stunning for new users