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

Overview

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.
You might also like...
🛸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.

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

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

Navigation Drawer Bottom Navigation View
Navigation Drawer Bottom Navigation View

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

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

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

🎉 [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

CustomNavigationDrawer - Custom Navigation Drawer with compose
CustomNavigationDrawer - Custom Navigation Drawer with compose

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

Navigation for compose multiplatform

Navigation for compose multiplatform

Releases(1.3.0)
  • 1.3.0(Nov 24, 2022)

  • 1.2.0(Aug 15, 2022)

    Improvements

    • Improved state saving. Now your screens will not be lost even if the activity recreates.

    Changes

    • Updated compose to version 1.2.1
    • Update Kotlin to version 1.7.10
    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Aug 7, 2022)

    Additions

    • A new replace() method to BackstackNavigator, which replaces the current destination with a new one, without altering previous destinations. (#2)
      • Updated sample to reflect this change.

    Changes

    • Updated compose to 1.2.0.
    • Updated Kotlin to 1.7.0.
    • Updated docs.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jun 15, 2022)

Owner
Xinto
You have no idea how much I love Kotlin.
Xinto
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).

Kaustubh Patange 88 Dec 11, 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

Abhishesh 21 Feb 6, 2021
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

Joery 1.2k Dec 30, 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.

Joery Droppers 1000 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 This is simple

Shruti Patel 1 Jul 11, 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

Vitali Olshevski 290 Dec 29, 2022
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

Jeziel Lago 21 Dec 10, 2022
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

Arvind Meshram 5 Nov 24, 2022
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

Artur Artikov 290 Dec 9, 2022
Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps. The extension provides handy methods and properties to change the behaviour as well as the appearance of the navigation bar.

Zain Ul Hassan 4 Nov 30, 2022