ncapdevi/FragNav

Only one instance of a fragment in entire of the app

hosseinaminii opened this issue · 1 comments

Hello, I want to show only one instance of SearchFragment, so I wrote this code:

fragNavController.currentStack?.forEachWithIndex { index, it -> if (it.arguments?.get(ARGS_INSTANCE) == 123) { fragNavController.currentStack?.removeAt(index) } } fragNavController.pushFragment(SearchFragment.newInstance(123))

But it doesn't remove the previous instance of the SearchFragment.
How can I achieve it? Thanks

Hmm, that's a tough one. You shouldn't be modifying the stack directly, so the above won't work. I believe your use-case would be outside the library's scope unfortunately. Personally that UX seems a bit strange to me. A user navigating through and popping search onto the stack, and navigating to an item, pressing back, you would expect the search fragment again. Not sure what your particular use case, but it doesn't seem to follow android's guideline of a navigation https://developer.android.com/guide/navigation/navigation-principles#navigation_state_is_represented_as_a_stack_of_destinations