architecture-components-samples icon indicating copy to clipboard operation
architecture-components-samples copied to clipboard

Advance navigation sample: Reset to startDestination

Open deckyfx opened this issue 6 years ago • 7 comments

I need case where when tab selected, it always go to navController.startDestination, any ideas how to do this?

deckyfx avatar May 22 '19 07:05 deckyfx

Interested too, any solution ?

I trick with this before " if (firstFragmentTag != newlySelectedItemTag) {"

  // When item in bottom nav changed, need to reset the graph of the tab we are leaving
val previousFragment = fragmentManager.findFragmentByTag(selectedItemTag) as NavHostFragment
 previousFragment.navController.let { it.popBackStack(it.graph.startDestination, true) }

It works but with shared elements it is not working .

PierreFourreau avatar Feb 21 '20 15:02 PierreFourreau

I am also interested in this. If any one has any insight.

JLoutris avatar Mar 10 '20 13:03 JLoutris

I add onItemClickedListener and everytime user navigate away, before returning the boolean, the bottom nav clear the stack of the previous selected tab.

deckyfx avatar Mar 13 '20 14:03 deckyfx

I add onItemClickedListener and everytime user navigate away, before returning the boolean, the bottom nav clear the stack of the previous selected tab.

Some code please ? :)

PierreFourreau avatar Mar 13 '20 16:03 PierreFourreau

This is how I work around this ExtendedBottomNavigationView.kt Sorry I can't be more specific since I already quit my previous job and lost access to their repository

on a side note: What the... I can't embed gist link in Github issue comment?

deckyfx avatar Mar 13 '20 23:03 deckyfx

I did it but checking for the start id of each the bottom nav graph in activity onBackPressed, then do following: super.onBackPressed() currentLiveNavController?.value?.popBackStack(R.id.fragment_home, false)

JLoutris avatar Mar 26 '20 04:03 JLoutris

The problem with this popToBackStack is that parent previous fragment is recreated (the popped fragment)

😕

PierreFourreau avatar Nov 24 '20 22:11 PierreFourreau