aartikov / Alligator

Alligator is Android navigation library that will help to organize your navigation code in clean and testable way.
MIT License
298 stars 17 forks source link

Nested fragment ScreenSwitcher #12

Closed DomiBlaze closed 6 years ago

DomiBlaze commented 6 years ago

Is it possible to implement nested FragmentScreenSwitcher? One of my fragments(let's call it HostFragment) has a bottom navigation implemented, and I want to use switchTo to switch betweed child fragments of HostFragment. Furthermore, I have AnotherHostFragment with different set of fragments. I want to solve this problem without additional activities, in a single activity app setup.

Thank you in advance

aartikov commented 6 years ago

You can extend FragmentScreenSwitcher to delegate switching of inner fragments to additional screen switchers. Like that:

public interface ScreenSwitcherProvider {
    ScreenSwitcher getScreenSwitcher();
}
public class MainScreenSwitcher extends FragmentScreenSwitcher {

    // constructors are ommited

    @Override
    public void switchTo(Screen screen, @Nullable AnimationData animationData) throws NavigationException {
        if (isInner(screen)) {
            ScreenSwitcher screenSwitcher = ((ScreenSwitcherProvider) getCurrentFragment()).getScreenSwitcher();
            screenSwitcher.switchTo(screen, animationData);
        } else {
            super.switchTo(screen, animationData);
        }
    }
}