Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FragNavController in Java #243

Open
GoriunovAlexandr opened this issue Sep 14, 2021 · 0 comments
Open

FragNavController in Java #243

GoriunovAlexandr opened this issue Sep 14, 2021 · 0 comments

Comments

@GoriunovAlexandr
Copy link

GoriunovAlexandr commented Sep 14, 2021

Could you please provide some implementation in java?
with some initialisation for FragNavController and some onBackPressed method?
In specialy I'm interested in back navigation. I can't implement a back navigation between root fragments. It pops up the fragment from current root, and doesn't move to prevoius root fragment. The app is simply closed.
I am using implementation 'com.ncapdevi:frag-nav:3.2.0' version

@Override
    public int getNumberOfRootFragments() {
        return 5;
    }

  fragNavController = new FragNavController(getSupportFragmentManager(), R.id.container);
  fragNavController.setRootFragments(fragmentList);
  //fragNavController.setRootFragmentListener(this);  here it gives a mistake when the app is lauched:  IllegalStateException: 
        //Shouldn't have both a rootFragmentListener and rootFragments set, this is clearly a mistake
        //fragNavController.setCreateEager(true); if this line is used the library moves to the 3-rd root fragment
        fragNavController.setFragmentHideStrategy(FragNavController.DETACH_ON_NAVIGATE_HIDE_ON_SWITCH);
        fragNavController.setNavigationStrategy(new UniqueTabHistoryStrategy((int i, @Nullable FragNavTransactionOptions 
   fragNavTransactionOptions) -> {
            bottomNavigation.setSelectedItemId(i);
        }));
        fragNavController.initialize(FragNavController.TAB1, savedInstanceState);
        if (savedInstanceState == null) bottomNavigation.setSelectedItemId(FragNavController.TAB1);
        
        
   @Override
public void onBackPressed() {
    if (!fragNavController.isRootFragment()) {
        fragNavController.popFragment();
    } else {
        super.onBackPressed();
    }
}

Will be very glad for some help!
Best regars, Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant