You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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 :
public void gotoSecond(View view){
if (navigator != null) {
navigator.gotoSecond();
}
}
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
The text was updated successfully, but these errors were encountered: