Fix issues with bottom navigation

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-12-29 00:47:50 +01:00
parent bf71a90b8c
commit baa317f6cf
2 changed files with 18 additions and 32 deletions

View File

@ -73,15 +73,4 @@ public class MagicBottomNavigationController extends BottomNavigationController
}
return controller;
}
/**
* Supplied Controller must match a MenuItemId as defined in {@link BottomNavigationMenuItem} or
* an {@link IllegalArgumentException} will be thrown.
*
* @param controller
*/
public void navigateTo(Controller controller) {
BottomNavigationMenuItem item = BottomNavigationMenuItem.getEnum(controller.getClass());
navigateTo(item.getMenuResId(), controller);
}
}

View File

@ -123,6 +123,20 @@ public abstract class BottomNavigationController extends BaseController {
/* Setup the BottomNavigationView with the constructor supplied Menu resource */
bottomNavigationView.inflateMenu(getMenuResource());
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
navigateTo(item.getItemId(), getControllerFor(item.getItemId()));
return true;
}
});
}
@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
/* Fresh start, setup everything */
if (routerSavedStateBundles == null) {
Menu menu = bottomNavigationView.getMenu();
@ -154,21 +168,6 @@ public abstract class BottomNavigationController extends BaseController {
childRouter.rebindIfNeeded();
lastActiveChildRouter = childRouter;
}
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (currentlySelectedItemId != item.getItemId()) {
BottomNavigationController.this.destroyChildRouter(BottomNavigationController.this.getChildRouter(currentlySelectedItemId), currentlySelectedItemId);
currentlySelectedItemId = item.getItemId();
BottomNavigationController.this.configureRouter(BottomNavigationController.this.getChildRouter(currentlySelectedItemId), currentlySelectedItemId);
} else {
BottomNavigationController.this.resetCurrentBackstack();
}
return true;
}
});
}
/**
@ -219,11 +218,9 @@ public abstract class BottomNavigationController extends BaseController {
* BottomNavigationController#getControllerFor(int)}, using a {@link FadeChangeHandler}.
*/
protected void resetCurrentBackstack() {
if (lastActiveChildRouter != null) {
lastActiveChildRouter.setRoot(RouterTransaction.with(this.getControllerFor(currentlySelectedItemId))
.pushChangeHandler(new FadeChangeHandler())
.popChangeHandler(new FadeChangeHandler()));
}
lastActiveChildRouter.setRoot(RouterTransaction.with(this.getControllerFor(currentlySelectedItemId))
.pushChangeHandler(new FadeChangeHandler())
.popChangeHandler(new FadeChangeHandler()));
}
/**
@ -350,7 +347,7 @@ public abstract class BottomNavigationController extends BaseController {
* The childRouter should handleBack,
* as this BottomNavigationController doesn't have a back step sensible to the user.
*/
return lastActiveChildRouter != null && lastActiveChildRouter.handleBack();
return lastActiveChildRouter.handleBack();
}
/**