Giter Site home page Giter Site logo

wwdablu / lottiebottomnav Goto Github PK

View Code? Open in Web Editor NEW
297.0 6.0 28.0 3.96 MB

An android library that allows to use Lottie and create the bottom navigation.

License: MIT License

Java 100.00%
android android-library lottie-android bottomnavigationview bottom-navigation

lottiebottomnav's Introduction

LottieBottomNav

Library which allows to create a bottom navigation view allowing the usage of Lottie views.

Gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}  

dependencies {
    implementation 'com.github.wwdablu:lottiebottomnav:x.y.z'
}

Declare in XML

<com.wwdablu.soumya.lottiebottomnav.LottieBottomNav
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/bottom_nav"
    android:layout_alignParentBottom="true"
    android:background="@android:color/white"
    app:menu_selected_height="48dp"
    app:menu_selected_width="48dp"
    app:menu_unselected_height="40dp"
    app:menu_unselected_width="40dp"
    app:menu_text_show_on_unselected="true"
    />

This would create the LottieBottomNav control. Using it the width and height of the menu items in selected and unselected state of the menu item can be controlled. Also as to whether the text for the menu item will be used for the unselected items can also be controlled using the property menu_text_show_on_unselected.

Creating Menu Items

The LottieBottomNav contains an array of menu items. The process to create a menu item is:

MenuItem homeItem = MenuItemBuilder.create("home.json", MenuItem.Source.Assets, fontItem, "dashboard")
    .pausedProgress(1f)
    .loop(false)
    .build();

This allows us to create a menu with both the selected and unselected states. The other way to create is from an existing menu item object and then modifying any existing property. Note: Only tag property is not copied.

MenuItem settings = MenuItemBuilder.createFrom(homeItem)
    .selectedLottieName("settings.json")
    .unSelectedLottieName("settings.json")
    .tag("settings")
    .build();

In the above approach properties like autoPlay and loop are of the same value from which it is created.

Creating Text Menu Items

These are used to display the text on the menu item. Now, we can also specify custom fonts too.

FontItem fontItem = FontBuilder.create("Dashboard")
    .selectedTextColor(Color.BLACK)
    .unSelectedTextColor(Color.GRAY)
    .selectedTextSize(16) //SP
    .unSelectedTextSize(12) //SP
    .setTypeface(Typeface.createFromAsset(getAssets(), "coffeesugar.ttf"))
    .build();

Update a particular menu item

To update a particular menu item with different properties of the menu item, the following approach is needed.

MenuItem cupidMessage = MenuItemBuilder.createFrom(bottomNav.getMenuItemFor(index))
    .selectedLottieName("message_cupid.json")
    .tag("cupid")
    .build();

bottomNav.updateMenuItemFor(index, cupidMessage);

This would change the lottie used for the menu item in index and update it to use cupid lottie.

Callback

The following callbacks are provided for each of the menu items.

void onMenuSelected(int oldIndex, int newIndex, MenuItem menuItem);
void onAnimationStart(int index, MenuItem menuItem);
void onAnimationEnd(int index, MenuItem menuItem);
void onAnimationCancel(int index, MenuItem menuItem);

It should be noted that if autoPlay is enabled, then it must be noted that onMenuSelected will call onAnimationStart immediately. So it is better to perform quick tasks in these callback and move heavy tasks in separate threads.

Demo

The demo video is present inside the demo folder.

Demo

Lottie Files
The lottie files used have been taken from https://www.lottiefiles.com/. The lotties files have been developed by the respective developers and I have not created them.

Font
The font has been downloaded from https://www.1001fonts.com/coffee-with-sugar-font.html. I have used them for the purpose of demo.

lottiebottomnav's People

Contributors

micoder-dev avatar wwdablu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lottiebottomnav's Issues

Update the readme file

The readme needs to be updated to use the new grade kts approach:

pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven(url="https://jitpack.io")
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven(url="https://jitpack.io")
}
}

DataBinderMapperImpl & JSON parser issue

Hey!

DataBinding issue when using the library with AndroidX in Kotlin.
Failed resolution of: Landroidx/databinding/DataBinderMapperImpl;

When dataBinding { enabled = true } then it rises Unable to parse composition

Also reporter on lottie-android (might be related to JSON reader)

Change text size and font.

Is your feature request related to a problem? Please describe.
App always need to implement new fonts and font sizes accordingly. And it is too bad when there is great work of someone like this library is but have no way to edit font.

Describe the solution you'd like
I would love to have following options when creating MenuItem:

  • .setFont()
  • .setSelectedTextSize(20f)
  • .setUnselectedTextSize(15f)

App Crashing At "bottomNav.setMenuItemList(list);"

I copied the entire code solved some basic errors and when I tried to build the Apk the app is crashing at "bottomNav.setMenuItemList(list);" and No further information mentioned in Android Studio.

Kindly tell me the solution for it

implementation error

  1. Implemented the dependency in Gradle.
  2. Error:
    - Failed to resolve: com.github.wwdablu:lottiebottomnav:1.2.0
    - Show in Project Structure dialog
    - Affected Modules: app

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.