• This repository has been archived on 23/Dec/2020
  • Stars
    star
    830
  • Rank 54,934 (Top 2 %)
  • Language
    Java
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simpler way for implementing the Bottom Navigation View on Android

Simple Bottom Navigation

Motivation

When using a TabLayout within your application, using a ViewPager along with an adapter offers an easy way to quickly link up your views for display. The FragmentAdapter class takes care of all the hard work for you when it comes to switching between the views as the user selected a different item in the TabLayout. This process is made up something a little like this:

This is great as it allows you to decouple this presentation logic from your activities or other classes. However, when it comes to implementing the BottomNavigationView from the design support library, we're not blessed with the same niceties. This requires your activity (or fragment) that is hosting the BottomNavigationView to house the logic used for the handling of such events. We can't use the ViewPager for Bottom Navigation as the way the view works breaks the design guidelines - so we created this library here to allow you to easily create an adapter for use with Bottom Navigation so that you can work with the view in a way in which you are familiar with when it comes to the ViewPager. This setup looks a little like this:

So, what is this library?

As mentioned, when using the Bottom Navigation View from the Android Support Library, there can be a lot of boilerplate code for the switching of views. Because of this, we took inspiration from the TabLayout setupWithViewPager() method and created a custom ViewSwapper component that can be attached to a Bottom Navigation View to simplify the management of view display. Within this library are three core components that you'll need to use:

  • AdaptableBottomNavigationView - The Bottom Navigation View for displaying navigation items in a bar at the bottom of the screen. This view extends the BottomNavigationView from the Design Support Library, so the two classes are easily interchangable in your projects.

  • ViewSwapper - The View Swapper is used to easily switch between fragments that you wish to display to the user. Unlike the View pager, views will not transition between pages and swiping is not possible - hence adhering to the Design Principles for the Bottom Navigation View. This view is essentially a tweaked version of the ViewPager component that you're probably familiar with already!

  • FragmentStateAdapter / FragmentAdapter - An abstract adapter that allows you to create an adapter for displaying fragments within the ViewSwapper. These classes are the same as the implementations found within the Android Framework, agan with a few tweaks to better match the behaviour of the View Swapper component.

But how's it different from using a ViewPager?

In the library you'll notice the ViewSwapper component. This is similar to the ViewPager except it has a view differences:

  • Unlike the viewpager, it doesn't draw all views within the component at once. The Views are simply added and removed as the item to be displayed has been selected

  • The ViewSwapper doesn't allow swiping between views - this allows us to adhere to the guidelines for not allowing the Bottom Navigation to be interacted with in this way

How to use

In order to use this ViewSwapper component you need to use our SimpleBottomNavigationView - this is simply an extension of the support library component with the added functionality of ViewSwapper attachment and elevation. This will look like so in your layout file:

<org.buffer.adaptablebottomnavigation.view.ViewSwapper
    android:id="@+id/view_swapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/view_bottom_navigation" />

<org.buffer.adaptablebottomnavigation.AdaptableBottomNavigationView
    android:id="@+id/view_bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/colorPrimary"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@drawable/selector_menu"
    app:itemTextColor="@drawable/selector_menu"
    app:menu="@menu/main" />

Next, you'll need to create an adapter using either the FragmentStateAdapter or FragmentAdapter classes from the library. These are the essentially the same as the corresponding adapter classes found in the Android Framework. This could look something like so:

public class ViewSwapperAdapter extends FragmentStateAdapter {

    private static final int INDEX_BUFFER = 0;
    private static final int INDEX_RETREAT = 1;
    private static final int INDEX_VALUES = 2;

    public ViewSwapperAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case INDEX_BUFFER:
                return ImageFragment.newInstance(R.drawable.cat);
            case INDEX_RETREAT:
                return ImageFragment.newInstance(R.drawable.buffer);
            case INDEX_VALUES:
                return ImageFragment.newInstance(R.drawable.android);
        }
        return ImageFragment.newInstance(R.drawable.cat);
    }

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

}

Now we have the views defined in our layout and the adapter to manage the display of our fragments (or views), we can go ahead and set the adapter for the View Swapper followed by attaching the View Swapper to the Bottom Navigation View:

e.g.

viewSwapper.setAdapter(viewSwapperAdapter);
bottomNavigationView.setupWithViewSwapper(viewSwapper);

More Repositories

1

android-clean-architecture-boilerplate

An android boilerplate project using clean architecture
Kotlin
3,651
star
2

clean-architecture-components-boilerplate

A fork of our clean architecture boilerplate, this time using the Android Architecture Components
Kotlin
1,277
star
3

BufferTextInputLayout

A simple customised version of the TextInputLayout from the Android Design Support Library ⌨️
Java
983
star
4

android-clean-architecture-mvi-boilerplate

A fork of our clean architecture boilerplate using the Model-View-Intent pattern
Kotlin
978
star
5

android-guidelines

Project Guidelines for the Android Buffer App
Shell
750
star
6

buffer-ios-image-viewer

The BFRImageViewer is a turnkey solution to present images within your iOS app πŸŽ‰!
Objective-C
399
star
7

clean-architecture-koin-boilerplate

A fork of our clean architecture boilerplate, this time using Koin
Kotlin
331
star
8

MultiActionSwipeHelper

An Android RecyclerView Swipe Helper for handling multiple actions per direction
Java
296
star
9

CounterView

A simple Android counter view for showing edittext character counts
Kotlin
176
star
10

Thumby

An Android video thumbnail picker
Kotlin
173
star
11

buffer-components

Buffer's shared collection of React UI components πŸ€œπŸ€›
JavaScript
139
star
12

ReactivePlayBilling

An RxJava wrapper for the Google Play Billing Library
Kotlin
117
star
13

buzzer

A little buzzer app for running your own quizzes or game shows!
JavaScript
94
star
14

buffer-chrome

Buffer for Chrome lets you easily add great articles, pictures and videos to your Buffer and we automagically share them for you through the day!
JavaScript
66
star
15

SocialLinkify

An Android library for linking @ mentions & Hashtags to their corresponding social network
Kotlin
65
star
16

BFRReorderTableView

The BFRTableReorder is an out of the box solution to add long press reordering to your ASDK apps
Objective-C
57
star
17

ui

✨ Buffer's UI Components library and Style Guide✨
TypeScript
51
star
18

old-diversity-dashboard

R
49
star
19

kiner

Python AWS Kinesis Producer with error handling and thread support.
Python
45
star
20

README

Welcome, friend! Here's an overview to our engineering team's documentation
Shell
43
star
21

sqs-worker-go

Go
38
star
22

code-of-conduct

Buffer's Employee Code of Conduct
36
star
23

diggdigg

DiggDigg is the floating all-in-one share bar for your WordPress website.
PHP
33
star
24

buffer-ios-sdk

Buffer iOS SDK
Objective-C
30
star
25

javascript-style-guide

Buffer's JavaScript style guide
24
star
26

Biscotti

A collection of Custom Actions and Matchers for Espresso Testing
Kotlin
23
star
27

buffer-blog-v2

Buffer Blog design starting July 2014
PHP
21
star
28

bootstrap-datepicker

Our own fork of eternicode's bootstrap datepicker that includes time selection.
21
star
29

buffer-extension-shared

Shared code between Buffer extensions
JavaScript
21
star
30

buffer-style

The Buffer Style Guide
JavaScript
20
star
31

EKG

Kubernetes Health And Liveness Check
JavaScript
20
star
32

android-components

Shared components for Buffer Android apps
Kotlin
19
star
33

carden

Service to save MongoDB Change Streams (oplog) records into Big Query
Python
19
star
34

buffer-php-style-guide

Buffer's PHP style guide
19
star
35

pylooker

A Python interface to Looker API
Python
16
star
36

lookerpy

A Python API client for Looker
Python
15
star
37

CustomViewIndicator

An Android ViewPager indicator that allows you to provide custom views for display
Kotlin
15
star
38

sharejs

Trigger the Buffer Share popup from any DOM element
JavaScript
14
star
39

Reactive-Pusher

An RxJava wrapper for the Pusher Java Library [Work in progress]
Kotlin
13
star
40

facebook-api-wrapper

Buffer's Facebook PHP API wrapper
PHP
13
star
41

churnado

Churn forecasting tool
R
13
star
42

buffer-redux-hover

Keep React component hover state in redux
JavaScript
12
star
43

omniauth-buffer2

Omniauth strategy to allow Ruby clients to easily use the Buffer API.
Ruby
12
star
44

k8s-jenkins-pipeline

Jenkins Pipeline Library for k8s Deployment Using Helm Chart
Groovy
11
star
45

stacklogging

Python logging integration with Google Cloud Stackdriver API.
Python
11
star
46

buffer-extensions

Main repo for extension code. Note: this has nested submodules
JavaScript
11
star
47

buffer-firefox

Buffer for Firefox
JavaScript
10
star
48

github-notify-client

Get system notifications when you get PRs assigned to you!
JavaScript
10
star
49

buffer-web-components

Buffer Dashboard Specific Components
JavaScript
10
star
50

buffer-sharekit

A Buffer plugin for your ShareKit sharing menu for iOS
Objective-C
9
star
51

rsdf

Some functions to help Pandas DataFrames communicate with Redshift
Python
9
star
52

twilio-to-slack

πŸ“²πŸ’¬ A simple app to forward SMS messages from a Twilio number to a Slack channel
JavaScript
9
star
53

restream

Replay Firehose Streams in Kinesis Streams!
Python
9
star
54

buffer-ruby-deprecated

Official Ruby API wrapper for Buffer
Ruby
9
star
55

dbt-bigquery-auditlog

Get an overview of all cost and performance data for your BigQuery project
9
star
56

BFRGIFRefreshControl

Objective-C
8
star
57

BufferSwiftKit

Swift based SDK to access the Buffer API. The main goal is to provide a simple and easy interface to use Buffer in your iOS apps.
Swift
8
star
58

micro-rpc

Async RPC microservices made easy
JavaScript
8
star
59

buffer-safari

Buffer for Safari
JavaScript
7
star
60

jquery-dragme

A super lightweight jQuery plugin for dragging elements using CSS3 Transforms
JavaScript
7
star
61

extender

Cross-Browser Extension library and build tool
Ruby
6
star
62

buffer-quality-dashboard

GitHub issue dashboard
JavaScript
6
star
63

css-style-guide

How we CSS at Buffer
6
star
64

kubesecret

A tool to manage secrets in kubernetes
JavaScript
6
star
65

tracking-plan-kit

Utilities for managing Buffer's Data Tracking Plan
Python
5
star
66

segment-config-api

A Python Wrapper for Segment's Config API
Python
4
star
67

buffer-talks

Bufferoo Talks - built on Jekyll and Remark
HTML
4
star
68

docker-demos

Intro to Docker: Images + Containers
Dockerfile
4
star
69

buffer-static-upload

πŸ“β†’β˜οΈπŸ€˜ Making it easy to upload your static assets
Go
4
star
70

aws-key-auditor

Get all keys from an AWS account and send an email if a key is getting old
JavaScript
4
star
71

app-shell

Buffer's shared App Shell for front-end applications
TypeScript
3
star
72

cerone

Extensible consumer made for applications using Amazon's Kinesis Python Client Library (KCL).
Python
3
star
73

mongoct

MongoDB Change Streams tracker.
Python
3
star
74

buffer-bot

DEPRECATED
CoffeeScript
3
star
75

buffer-scripts

⌨️ A collection of useful scripts for all sorts of manual tasks!
Shell
3
star
76

buffer-code-exercise-api

A small api server which will be used in the Buffer interview code exercise.
JavaScript
3
star
77

buffer-opensource

Buffer ❀️ Open Source. Static site generator for Buffer's Open Source Site (https://bufferapp.github.io/)
HTML
2
star
78

gprc-metrics-poc

gRPC-based Metrics Collection pipeline proof-of-concept monorepo
JavaScript
2
star
79

convoyslit

Streamlit app to quickly explore convoys models from BigQuery queries
Python
2
star
80

buffer-js-shutdown-helper

Shutdown your Express.js apps gracefully
JavaScript
2
star
81

buffer-icons

Custom Buffer fonts for all!
HTML
2
star
82

micro-rpc-client

Universal JS RPC Client https://github.com/bufferapp/micro-rpc/
JavaScript
2
star
83

helpscout-api

A Python interface to Helpscout's API
Python
2
star
84

stripe-pipeline

A simple data pipeline for Stripe API events to Redshift
Python
2
star
85

cricket

Your personal Jiminy Cricket when posting online.
Python
2
star
86

pipub

Pipe data from the command line to Google Pubsub.
Python
2
star
87

go-base-worker

Golang packages needed to build a consumers
Go
2
star
88

buffer-js-dragme

module for dragging components
JavaScript
2
star
89

streamlit-causal-impact

Streamlit app to run Causal Infence in your CSVs
Python
2
star
90

android-utils

Common utilities used in our android projects
Kotlin
2
star
91

manual-payments

R
2
star
92

bufferapp.github.io

Buffer's Development Driven Values
HTML
1
star
93

buffer-branding-2018

HTML
1
star
94

buffer-js-logger

Node.js logging for Buffer applications
JavaScript
1
star
95

buffer-update-converters

Convert statuses from Twitter, Facebook and Instagram into Buffer updates
PHP
1
star
96

php-bufflog

php logger for all PHP Buffer services
PHP
1
star
97

dd-tracing-logging-examples

JavaScript
1
star
98

buffer-js-request

JS interface to send requests – thin wrapper around fetch()
JavaScript
1
star
99

slack-channels

Analysis on Buffer's slack channels
Jupyter Notebook
1
star
100

buffer-standards

Standard configuration for shared packages/tools at Buffer
TypeScript
1
star