A small navigation library for Jetpack Compose with state saving, backstack and animations support.

Last update: Jun 15, 2022

Taxi

A small navigation library for Jetpack Compose with state saving, backstack and animations support.

Quick Setup

Installation

Add JitPack repository to root build.gradle

allprojects {
    repositories {
        ...
        maven(url = "https://jitpack.io")
    }
}

Add Taxi dependency to app build.gradle

dependencies {
    implementation("com.github.X1nto:Taxi:1.0.0")
}

Basic Usage

Taxi( modifier = Modifier.fillMaxSize().padding(paddingValues), navigator = navigator, transitionSpec = { fadeIn() with fadeOut() } ) { destination -> when (destination) { is AppDestination.Home -> { Home() } is AppDestination.Settings -> { Settings() } } } } }">
sealed interface AppDestination : Destination {
    
    @Parcelize
    object Home : AppDestination
    
    @Parcelize
    object Settings : AppDestination
    
}

@Composable
fun BackstackApp() {
    val navigator = rememberBackstackNavigator<AppDestination>(initial = AppDestination.Home)
    
    BackHandler {
        //Check if the navigator can pop
        if (!navigator.pop()) {
            finish() //Finish the activity if the backstack was empty
        }
    }
    
    Taxi(
        modifier = Modifier.filLMaxSize(),
        navigator = navigator,
        transitionSpec = { fadeIn() with fadeOut() }
    ) { destination ->
        when (destination) {
            is AppDestination.Home -> {
                Home(onSettingsClick = {
                    navigator.push(AppDestination.Settings)
                })
            }
            is AppDestination.Settings -> {
                Settings(onBackClick = {
                    navigator.pop()
                })
            }
        }
    }
}

@Composable
fun NavbarApp() {
    val navigator = rememberNavigator<AppDestination>(initial = AppDestination.Home)

    Scaffold(
        modifier = Modifier.fillMaxSize(),
        bottomBar = {
            NavigationBar(modifier = Modifier.fillMaxWidth()) {
                NavigationBarItem(
                    selected = navigator.currentDestination is AppDestination.Home,
                    onClick = { 
                        navigator.replace(AppDestination.Home)
                    },
                    label = {
                        Text("Home")
                    }
                )
                NavigationBarItem(
                    selected = navigator.currentDestination is AppDestination.Settings,
                    onClick = { 
                        navigator.replace(AppDestination.Settings)
                    },
                    label = {
                        Text("Settings")
                    }
                )
            }
        }
    ) { paddingValues ->
        Taxi(
            modifier = Modifier.fillMaxSize().padding(paddingValues),
            navigator = navigator,
            transitionSpec = { fadeIn() with fadeOut() }
        ) { destination ->
            when (destination) {
                is AppDestination.Home -> {
                    Home()
                }
                is AppDestination.Settings -> {
                    Settings()
                }
            }
        }
    }
}

See the sample app for better examples.

License

Copyright (C) 2022 X1nto.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

GitHub

https://github.com/X1nto/Taxi
You might also like...

DSC Moi University session on using Navigation components to simplify creating navigation flow in our apps to use best practices recommended by the Google Android Team

Navigation Components Navigate between destination using safe args How to use the navigation graph and editor How send data between destinations Demo

Feb 3, 2022

Navigation Component: THE BEST WAY to create navigation flows for your app

Navigation Component: THE BEST WAY to create navigation flows for your app

LIVE #017 - Navigation Component: A MELHOR FORMA de criar fluxos de navegação para o seu app! Código fonte do projeto criado na live #017, ensinando c

Jun 15, 2022

Navigation Drawer Bottom Navigation View

Navigation Drawer Bottom Navigation View

LIVE #019 - Toolbar, Navigation Drawer e BottomNavigationView com Navigation Com

Jun 15, 2022

A library that you can use for bottom navigation bar. Written with Jetpack Compose

A library that you can use for bottom navigation bar. Written with Jetpack Compose

FancyBottomNavigationBar A library that you can use for bottom navigation bar. W

Dec 27, 2021

Implementing bottom navigation in jetpack compose

Compose-Bottom-Navigation Implementing bottom navigation in jetpack compose Add the Navigation dependency Open the app's build file, found at app/buil

Dec 26, 2021

🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.

🎉 [Android Library] A light-weight library to easily make beautiful Navigation Bar with ton of 🎨 customization option.

Bubble Navigation 🎉 A light-weight library to easily make beautiful Navigation Bars with a ton of 🎨 customization options. Demos FloatingTopBarActiv

Jun 21, 2022

Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jun 22, 2022

CustomNavigationDrawer - Custom Navigation Drawer with compose

CustomNavigationDrawer - Custom Navigation Drawer with compose

An easy sample to explore navigation component and navigation drawer from Jetpac

Jan 4, 2022

Navigation for compose multiplatform

Navigation for compose multiplatform

Apr 11, 2022
A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).
A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

Jun 21, 2022
Memory efficient android library for managing individual fragment backstack.

fragstack : Android library for managing individual fragment backstack. An Easy to use library for managing individual fragment back stack as Instagra

Feb 6, 2021
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

AnimatedBottomBar A customizable and easy to use bottom bar view with sleek animations. Examples Playground app Download the playground app from Googl

Jun 23, 2022
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

Dec 5, 2021
Bottom-App-Bar-with-Bottom-Navigation-in-Jetpack-compose-Android - Bottom App Bar with Bottom Navigation in Jetpack compose
Bottom-App-Bar-with-Bottom-Navigation-in-Jetpack-compose-Android - Bottom App Bar with Bottom Navigation in Jetpack compose

Bottom-App-Bar-with-Bottom-Navigation-in-Jetpack-compose-Android This is simple

Jun 14, 2022
A small and simple, yet fully fledged and customizable navigation library for Jetpack Compose
A small and simple, yet fully fledged and customizable navigation library for Jetpack Compose

A small and simple, yet fully fledged and customizable navigation library for Jetpack Compose

Jun 20, 2022
Android multi-module navigation built on top of Jetpack Navigation Compose
Android multi-module navigation built on top of Jetpack Navigation Compose

MultiNavCompose Android library for multi-module navigation built on top of Jetpack Navigation Compose. The goal of this library is to simplify the se

Apr 16, 2022
New style for app design simple bottom navigation with side navigation drawer UI made in Jetpack Compose.😉😎
New style for app design simple bottom navigation with side navigation drawer UI made in Jetpack Compose.😉😎

BottomNavWithSideDrawer New style for app design simple bottom navigtaion with side navigation drawer UI made in Jetpack Compose. ?? ?? (Navigation Co

Dec 23, 2021
Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way.

Alligator Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way. Features Any app

Jun 18, 2022
🛸Voyager is a pragmatic navigation library built for, and seamlessly integrated with, Jetpack Compose.
🛸Voyager is a pragmatic navigation library built for, and seamlessly integrated with, Jetpack Compose.

Voyager is a pragmatic navigation library built for, and seamlessly integrated with, Jetpack Compose.

Jun 17, 2022