Description
Reported by JCR:
- Remove a key inside the stack
val desiredKeyToRemove = backstack.getHistory<SimpleStackScreenKey>()
.firstOrNull { it::class == keyToReplace }
if (desiredKeyToRemove == null) {
return
} else {
backstack.setHistory(
History.builderFrom(backstack)
.remove(desiredKeyToRemove)
.build<Key>(),
REPLACE
)
}
- Don't trigger navigation action with this (top key does not change)
- Key is no longer in the stack the next time top key changes, so fragment does not get removed by DefaultFragmentStateChanger (stays detached)
Conclusion: SimpleStateChanger
contains the built-in check from the original square/flow
However in this case it doesn't work (as fragments have memory, while flow used to be used only with views (that have no memory)).
Proposal: what if
1.) SimpleStateChanger also calls "onNavigationEvent" when state change is not content equals (but top is the same)
2.) DefaultFragmentStateChanger does not apply animations for fragment transactions that don't change the top, but still applies the state changes themselves
However, the short-circuit for "is top the same" is very old. By making it "content equals", then if anyone ever relied on it actually always being "is top the same" would need to do the check themselves, which is behavior breaking change. 😓