ncapdevi / FragNav

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

Clearing fragment manager #106

Closed carriehall closed 6 years ago

carriehall commented 6 years ago

https://github.com/ncapdevi/FragNav/blob/master/frag-nav/src/main/java/com/ncapdevi/fragnav/FragNavController.java#L162

It is currently not possible at startup to add a fragment outside of the library, as the library clears the fragment manager during initialisation.

If the app is a single activity app, what is the best approach to add a fragment that should exist outside of the switchable tab area?

ncapdevi commented 6 years ago

I'm sorry, but I'm having a little trouble fully understanding your question. Could you provide a use-case/example?

carriehall commented 6 years ago

Of course!

We have a single activity app, and now we are using FragNav to switch out the container fragment as you navigate around the app. However, the activity also has a persistent player view above the BottomNavigationView which is there at all times. We've implemented this as a fragment which is added in xml.

What seemed to be happening is that everything is inflated as expected, followed by initialising the FragNav, which then [cleared the fragment manager] (https://github.com/ncapdevi/FragNav/blob/master/frag-nav/src/main/java/com/ncapdevi/fragnav/FragNavController.java#L162)thereby removing the PlayerFragment we had inflated.

We've done a workaround now to ensure that the inflation happens after the FragNav initialise call which looks fine, so I'm happy to close this issue!