ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

Added Hide/Show and Hide/Detach Show/Attach hybrid modes as option #115

Closed mateherber closed 6 years ago

mateherber commented 6 years ago

Added Hide/Show and Hide/Detach Show/Attach hybrid modes as option Added Eager mode to precreate all Root fragments initially Fixed several Kotlin nullability issues

Hi @ncapdevi, I've seen that FragNavController has not yet been transformed to Kotlin so I created the PR for the java but still on the kotlin branch. In this PR we added the possibility to change attach/detach (default) behavior to show/hide or a hybrid (we actually use in our app) when switching between tabs is really fast (every tab's topmost fragment is not detached but hidden) however navigation still happens with attach/detach.

The reason behind this is that while you have written in the readme that reconstructing the activity / fragment from state is pretty standard on Android we experienced lagging/bad user experience when we were rebuilding our more complex pages when the user was navigating between tabs (i.e. reloading a complex recycleview with all the dense data on cards is not something that can be done without drops in framerate).

We implemented this so when user is switching between tabs is blazing fast but we still don't hold everything in memory (just as many fragments as the number of our tabs).

We also added a so called eager mode (which makes sense for the two types of show/hide modes) where we initially create all root fragments so the UI won't glitch when the user first navigates to these screens.

I'll update the README for both this PR and the backstack navigation PR in a separate one. I'll also make special emphasis on that using these new add/remove methods you'll have to take care of fragment lifecycle manually (i.e. Show/Hide doesn't trigger any onPause/onStop/onStart/onResume cycle, neither creating new UI (with onCreateView). So this has to be used with additional care.

I hope all this makes sense.

ncapdevi commented 6 years ago

Hey, @mateherber . I like both ideas here, I'm going to go through and complete the PR today and hopefully get the Kotlin branch close to done today. Thanks!

ncapdevi commented 6 years ago

@mateherber This Kotlin transition is an opportunity to look at a fair amount of logic and modify any obvious improvements now. It'd be nice to chat back and forth about some of the changes. If you're by any chance on the http://android-united.community/ slack channel and are up for it, shoot me a message or you could always email me and we could figure out another way to communicate quicker