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

NavigatingMvvmFragment issue? #6

Open
paulwiik opened this issue May 5, 2017 · 0 comments
Open

NavigatingMvvmFragment issue? #6

paulwiik opened this issue May 5, 2017 · 0 comments

Comments

@paulwiik
Copy link

paulwiik commented May 5, 2017

Hi,

I was evaluating this, and stumbled across an issue (or I might not understand how to use the library)

I think there might be a problem in "NavigatingFragmentDelegate.java", that it only overrides the onCreate() method without parameters.

Since we need to start other fragments / activities from within fragments I tried to extend your sample app by :

  • Adding a button to "fragment_first.xml" with onClick bound to viewModel::gotoSecond
  • Changing FirstFragmentViewModel to extend from NavigatingViewModel
  • Adding the gotoSecond method to FirstFragmentViewModel:
    public void gotoSecond(View view){
    if (navigator != null) {
    navigator.gotoSecond();
    }
    }
  • Adding gotoSecond method in MainNavigator.
  • Changing FirstFragment to extend from NavigatingMvvmFragment<MainNavigator, FragmentFirstBinding, FirstFragmentViewModel>
  • implementing getNavigator override (returning new MainNavigator)

When running it did not work. Navigator was always being null in the gotoSecond method.
Debugging I found the problem where MvvmFragment.onCreate runs getMvvmDelegate().onCreate(savedInstanceState);

getMvvmDelegate() is correctly creating and returning a NavigatingFragmentDelegate, but when this call it tries to run onCreate it passes savedInstanceState, and since this does not match the signature of the onCreate override in NavigatingFragmentDelegate, it ends up running FragmentDelegate.onCreate, thus ending up with not creating the navigator.

I added an additional override in NavigatingFragmentDelegate.java like this, and then it worked as expected:
@OverRide
@callsuper
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (viewModel != null) {
viewModel.setNavigator(navigatingCallback.getNavigator());
}
}

Am I using it incorrectly or is this an issue with the library?

Best Regards,
Paul

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