Zhuinden / simple-stack-extensions

Extensions for the simple-stack library.
Apache License 2.0
7 stars 1 forks source link

Potential issue with setHistory #9

Closed uberchilly closed 1 year ago

uberchilly commented 1 year ago

If you have a history of ScreenX and you run backstack.setHistory( History.of(ScreenX()), StateChange.REPLACE ) old fragment gets removed but the new one is not added.

Zhuinden commented 1 year ago

@uberchilly hello, according to the code in the fragment state changer, the Fragment should only be removed if the key is not found in the previous list.

if(!newKeys.contains(oldKey)) {

https://github.com/Zhuinden/simple-stack-extensions/blob/ed4a42b5cea31f24150cd908b5de7e0e76b240ee/fragments/src/main/java/com/zhuinden/simplestackextensions/fragments/DefaultFragmentStateChanger.java#L188

So I would double-check if the key has equals() implemented correctly. (is your ScreenX class a data class?)

uberchilly commented 1 year ago

It is not data class because it has no params. It is required for data class to have at least 1 primary constructor param.

uberchilly commented 1 year ago

It works when I set it to be data class @Parcelize data class ScreenX(val unused: String = "") : DefaultFragmentKey() tnx.

Zhuinden commented 1 year ago

Yeah it's unfortunate to have to specify that placeholder (I've been using the same approach for a long time now), I hear that data object will be supported eventually is supported in Kotlin 1.7.20, so if Compose isn't binding you to use 1.7.10, you can actually use 1.7.20 and data object instead of the unused param.