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

#260: bottom navigation demo #565

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.bluelinelabs.conductor.demo.controllers;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.bluelinelabs.conductor.Controller;
import com.bluelinelabs.conductor.Router;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.demo.R;
import com.bluelinelabs.conductor.demo.controllers.base.BaseController;
import com.bluelinelabs.conductor.demo.widget.NonScrollableViewPager;
import com.bluelinelabs.conductor.viewpager.RouterPagerAdapter;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import butterknife.BindView;

public class BottomNavigationController extends BaseController {

@BindView(R.id.view_pager) NonScrollableViewPager viewPager;
@BindView(R.id.navigation) BottomNavigationView navigation;

private final RouterPagerAdapter pagerAdapter;

public BottomNavigationController() {
pagerAdapter = new RouterPagerAdapter(this) {
@Override
public void configureRouter(@NonNull Router router, int position) {
if (!router.hasRootController()) {
Controller page = new NavigationDemoController(position * 10, NavigationDemoController.DisplayUpMode.HIDE);
router.setRoot(RouterTransaction.with(page));
}
}

@Override
public int getCount() {
return 4;
}

@Override
public CharSequence getPageTitle(int position) {
return "Tab " + position;
}
};
}

@Override
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
return inflater.inflate(R.layout.controller_bottom_navigation, container, false);
}

@Override
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
viewPager.setAdapter(pagerAdapter);
navigation.setOnNavigationItemSelectedListener(menuItem -> {
int index = 0;
switch (menuItem.getItemId()) {
case R.id.home:
index = 0;
break;
case R.id.places:
index = 1;
break;
case R.id.favorite:
index = 2;
break;
case R.id.settings:
index = 3;
break;
}
viewPager.setCurrentItem(index);
return true;
});
}

@Override
protected void onDestroyView(@NonNull View view) {
viewPager.setAdapter(null);
super.onDestroyView(view);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private enum DemoModel {
SHARED_ELEMENT_TRANSITIONS("Shared Element Demos", R.color.purple_300),
CHILD_CONTROLLERS("Child Controllers", R.color.orange_300),
VIEW_PAGER("ViewPager", R.color.green_300),
BOTTOM_NAVIGATION("Bottom Navigation", R.color.brown_300),
TARGET_CONTROLLER("Target Controller", R.color.pink_300),
MULTIPLE_CHILD_ROUTERS("Multiple Child Routers", R.color.deep_orange_300),
MASTER_DETAIL("Master Detail", R.color.grey_300),
Expand Down Expand Up @@ -186,6 +187,11 @@ void onModelRowClick(DemoModel model, int position) {
.pushChangeHandler(new FadeChangeHandler())
.popChangeHandler(new FadeChangeHandler()));
break;
case BOTTOM_NAVIGATION:
getRouter().pushController(RouterTransaction.with(new BottomNavigationController())
.pushChangeHandler(new FadeChangeHandler())
.popChangeHandler(new FadeChangeHandler()));
break;
case CHILD_CONTROLLERS:
getRouter().pushController(RouterTransaction.with(new ParentController())
.pushChangeHandler(new FadeChangeHandler())
Expand Down
Loading