appyx icon indicating copy to clipboard operation
appyx copied to clipboard

NavKey navTarget parcelable is not enforced

Open LachlanMcKee opened this issue 3 years ago • 11 comments

At the moment the NavKey navTarget argument is not enforced to be parcelable. It uses @RawValue to avoid the compiler complaining.

Unfortunately this means it is possible to introduce code that will crash at runtime (there is currently an issue in the newly introduced IndexedBackStack causing a crash when the app is backgrounded.

By adding more constraints to the generics we can ensure that we have compile time safety.

LachlanMcKee avatar Jan 02 '23 17:01 LachlanMcKee

Maybe there are options not to use such a restriction? I would like to pass any models to the screen arguments

aaudin90 avatar Jan 09 '23 10:01 aaudin90

Hi @aaudin90, I'm currently looking into something along these lines.

At the moment if you don't make your model parcelable in some manner your app will crash.

Likely the approach in the short term will be a runtime check earlier to avoid things slipping into production

LachlanMcKee avatar Jan 09 '23 12:01 LachlanMcKee

I understand the solution to the current error. I may be wrong, but having to inherit from parcelable makes appyx less usable.

Is it possible to make a second implementation of BaseNavModel that is not tied to parcelable?

aaudin90 avatar Jan 09 '23 14:01 aaudin90

Will your Node not be persisting it's routing/state when a configuration change occurs?

LachlanMcKee avatar Jan 09 '23 14:01 LachlanMcKee

You can also get around this by storing the backstack in different stores.

aaudin90 avatar Jan 09 '23 15:01 aaudin90

I looked in Decompose, the arguments there must also be Parcelable, but it is possible to disable state saving. And transfer complex models under the annotation @IgnoredOnParcel

aaudin90 avatar Jan 10 '23 08:01 aaudin90

Thanks @aaudin90. I'll discuss this with the team, and come back to you :)

LachlanMcKee avatar Jan 10 '23 09:01 LachlanMcKee

I will be waiting for you)

aaudin90 avatar Jan 10 '23 09:01 aaudin90

Because of this, :sample:app keeps crashing whenever it goes background with home button or recents button(not back button).

It logs like below.

java.lang.RuntimeException: Parcel: unable to marshal value 0
at android.os.Parcel.writeValue(Parcel.java:1680)
at com.bumble.appyx.core.navigation.NavKey.writeToParcel(Unknown Source:7)
...

jeddchoi avatar Feb 26 '23 15:02 jeddchoi

@LachlanMcKee, Hi! Have any ideas?)

aaudin90 avatar Mar 09 '23 20:03 aaudin90

Perhaps it makes sense to open access to the creation of your own serializers/deserializers, so as not to get tied up in Perselable

aaudin90 avatar Mar 13 '23 10:03 aaudin90