Closed mathemandy closed 5 years ago
This is the trickiest part in advancedscreenswitchersample.
When you press tab buttons FragmentScreenSwitcher
switches instances of TabFragment
in main_container. Each TabFragment
has its own fragment stack. To configure a fragment stack you need to bind NavigationContext
with a correct fragment manager and containerId. There only one active stack at any given time, so binding of NavigationContext
is called after each screen switching.
What kind of nested screens do you need?
Before meeting this Library, i used a Single Activity with 5 tabs and host containerId parentPannel
.
i call fragmentmanager.replace
to put my fragments in the container. This way i have one back stack for the activity. Here the back button clears the BackStack one by one.
WHAT I WANT TAB A ---> NEST A - - >NEST B --> NEST A2--> NEST A2-> NEST A2 ONBACKPRESS NEST A2 --->NEST A2 --->NEST A2 ---> NEST B ---> NEST A --->TAB A - close APP
CHALLENGE I FACE:
I notice that the fragment has its own FrameLayout that houses the nested Fragment
Question is there a way to continue using my existingContainner
for the nested screens or they need their own Container.
Leading Question if i need a new container, does it need to be in the fragment layout or i can i just declare two containers in the Activity layout.
I observe from your code that every tab Fragment needs to have its own container, because thats how you keep track of it.
I would love to discuss more with you on how i can fully use the Library :)
It depends on what result you want to achieve.
You described a simple fragment stack. You can do the same thing with Alligator. Just set a container to NavigationContext
and use goForward
and goBack
methods to push and pop fragments.
In my sample I use ScreenSwitcher
to create three separate fragment stacks. It gives another behavior. A user can switch to Tab A, add screens A1 and A2, switch to Tab B, add screens B1 and B2, then return back to Tab A, add screen A3 after A2 and so on. In other words it is three independent stacks, not single one.
i do not know what i am not getting right, but even as far forward i go. when i press the back Button. It closes the app with returning to the last item. Also I cannot seem to get the Screen from Navigator. It always returns null
It is hard to say what is a problem. Can you share the code?
I was able to replicate the issue in this Project as i am . unable to share the production code
https://github.com/mathemandy/Triviums.git
The app just shows you a list of items. when an item is selected, the new Fragment(newStageFragment)is show. ( but it shows with the old fragment.) Clicking the back button in the seconnd Fragment opens the app.
Your configuration differs from my sample. Take a closer look at it.
I use TabFragment
as a container for nested fragments. Try to do it in the same way.
Add HomeTabFragment
with just a FrameLayout. CategoryFragment
and newStageFragment
will be nested fragments.
There are also other fixes required: 1) Override onBackPressed like that
@Override
public void onBackPressed() {
mNavigator.goBack();
}
2) Unbind a navigation context in onPause
@Override
protected void onPause() {
mNavigationContextBinder.unbind();
super.onPause();
}
3) Implement equals and hashCode for tab screens.
okay, i think i missed the part of the Container. if i get you correctly, i would have
mTabScreenMap.put(R.id.navigation_home, new HomeTabScreen1("home"));
mTabScreenMap.put(R.id.navigation_profile, new HomeTabScreen2("profile"));
mTabScreenMap.put(R.id.navigation_leader, new HomeTabScreen3("Leader"));
Can you explain this Part of the code
Fragment fragment = mScreenSwitcher.getCurrentFragment(); if (fragment != null && fragment instanceof ContainerIdProvider) { builder.containerId(((ContainerIdProvider) fragment).getContainerId()) .fragmentManager(fragment.getChildFragmentManager()); // Use child fragment manager for nested navigation }
I am trying to play with nested screens but cannot get them to work when i press the back button