voyager icon indicating copy to clipboard operation
voyager copied to clipboard

multiplatform state restoration

Open diegoberaldin opened this issue 1 year ago • 9 comments

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?

diegoberaldin avatar Dec 29 '23 11:12 diegoberaldin

The typealias can just be changed to

actual interface JavaSerializable : java.io.Serializable

Syer10 avatar Dec 29 '23 19:12 Syer10

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.

diegoberaldin avatar Dec 29 '23 20:12 diegoberaldin

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

see this issue that goes in depth

MV-GH avatar Dec 30 '23 13:12 MV-GH

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.

diegoberaldin avatar Dec 30 '23 14:12 diegoberaldin

We accept suggestion. I will investigate that.

DevSrSouza avatar Jan 02 '24 22:01 DevSrSouza

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.

DevSrSouza avatar Jan 02 '24 22:01 DevSrSouza

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.

diegoberaldin avatar Jan 03 '24 09:01 diegoberaldin

Screen state restoration is broken as of now.

cryptrr avatar Jan 07 '24 14:01 cryptrr

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

terrakok avatar Jun 03 '24 11:06 terrakok