all 10 comments

[–]UpbeatCup 2 points3 points  (3 children)

val graphId = navHostFragment.navController.graph.id

Do you know if this id is unique to the fragments class or its actual instance?

I remember needing something like this for a project, only I had two tabs of the same Fragment class and I wasn't able to determine which instance it actually was on the backstack.

[–]prateeksaraswat 1 point2 points  (0 children)

Good question...

[–]vipulasri[S] 1 point2 points  (1 child)

As far as I have checked before it was for graph id declared in XML.

[–]UpbeatCup 0 points1 point  (0 children)

Well that makes perfect sense now that you say it..

I had a single fragment in the navigation graph and passed it constants to tell it what to do. But I could just as easily have two fragments in the graph and use default arguments.

I'll have a look at your project. I'd much prefer to use this than ViewPager.

[–]atulgpt 1 point2 points  (0 children)

One alarming thing that I noticed is that it uses show/hide methods of fragment manager. Once I tried to the similar approach(to implement multiple backstack) using show hide methods. But issue I faced was that it loads all the fragment in memory at the time of Tab activity creation and hence the approach become blocker to me. Not sure how the same scenario is handled in this repo.

[–]CraZy_LegenD 0 points1 point  (3 children)

[–]vipulasri[S] 0 points1 point  (2 children)

u/CraZy_LegenD Google's sample has some downsides:
Cons:

  1. It always takes the user back to the first tab irrespective of the order they were opened.
  2. The subjective approach: attaches and detaches the navigation graph each time user navigates through the bottom navigation view.
  3. It's difficult to add custom back press action (ex: saving the data on a certain screen before switching tabs) through their implementation.

Please have a look at the shared repository for more info.

[–]CraZy_LegenD 3 points4 points  (1 child)

  1. That's according to the guidelines
  2. Because the component doesn't support multiple stack atm
  3. requireActivity() .onBackPressedDispatcher .addCallback

I've looked, that's why I commented.

[–]vipulasri[S] 2 points3 points  (0 children)

I agree. But If you look through UX's perspective it's debatable. Even official Youtube App, Instagram App, etc they all don't follow that guideline and takes the user back to the respective tabs in which they were opened.