Closed uvaysss closed 3 years ago
Quick question: so you have multiple fragments, only one of them has 2+ bottom tabs on which BottomNavigationView should be available, and each tab requires its own history management (so isn't just 1 root fragment per tab)?
Correct. I have a parent flow of fullscreen fragments and then 1 fragment will contain tabs with their own stack of fragments.
@uvaysss I added a sample that shows how you can create a multi-stack inside a fragment using nested backstacks.
https://github.com/Zhuinden/simple-stack/commit/c64bd3a2f8a56ba765392bc0b195727a1b7188f3 😉
Did that help?
Wow, that was quick! Thank a lot for the sample! I didn't have time to checkout the sample yet. I will give you a feedback later. Thank you again!
As the fact that this sample exists now (and is, as far as I'm aware, a complete solution to the multistack problem) is a pretty big deal, I'll have an article up here explaining how it works: https://medium.com/@Zhuinden/creating-a-bottomnavigation-multi-stack-using-child-fragments-with-simple-stack-c73c1ca3bbd4
Did a quick checkout of the sample and already implemented in a demo app. So far it just works. Thank you!
But I was wondering what would be the right solution to "fix" the fragment view recreation problem. Well I could replace the attach and detach methods with show and hide, but I'm not sure if in this case it's okay to do so. Maybe just keep a reference to the created view.
You can override isNotShowing, showFragment, hideFragment in DefaultFragmentStateChanger to use show/hide instead of attach/detach, a key difference though is that hidden fragments don't become stopped.
Wait, you mean for the FragmentStackHostFragments. Yes, you can replace the detach/attach with hide/show. Same principles for not being stopped apply, you might need to also override onHiddenChanged to decide that the fragment isn't available for handling back.
You can use setMaxLifecycle(STARTED) to make onPause work
Did not really get the part with setMaxLifecycle(STARTED), but with show/hide and just onHiddenChanged is working fine.
Also, would be great to hear your opinion about the "solution" of fragment view recreation with holding a reference to that view.
I hear retaining the view despite the Fragment expecting it to be dead can break things so I'd advise against doing that.
But I'm not entirely sure on the exact issues that can arise.
I mostly just mentioned setMaxLifecycle because the code for FragmentStackHostFragment was using onResume/onPause to decide if it's eligible for back, the benefit to that is that setMaxLifecycle(STARTED) (and of course, RESUMED with show) combined with hide/show can eliminate the need for using the separate onHiddenChanged.
Hi, thank your for this library!
I'm currently trying to implement single activity navigation on fragments, but having trouble with a multistack screen. In the sample the host for multistack is an Activity, but I need it for a fragment. The problem is that I don't know what the fragment alternative would be for
onRetainCustomNonConfigurationInstance()
andgetSystemService()
.Maybe you could give a hint?