Coder Social home page Coder Social logo

miquido / android-navigation Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 160 KB

Compose Navigator library which provides possibility to Control AndroidX NavController from View Model's. The project was made by Miquido: https://www.miquido.com/

License: Apache License 2.0

Kotlin 100.00%
android-library androidx-navigation compose kotlin kotlin-android navigation

android-navigation's Introduction

Compose Navigator

Compose Navigator provides possibility to Control AndroidX NavController from View Model's.

The library facilitates the usage of a single NavHost controlled by one point of truth - Navigator. Provides a unified interface for providing results back between composables and receiving activity results.

Features

View Model's can use Navigator interface provided by navigation-runtime artifact to:

  • navigate forward to direction with optional NavOptions
  • navigate backward
  • provide result data to previous backstack entry
  • launch and receive activity results using ActivityResultContract

Warning: library is designed to work with a single NavHost. Using nested NavHost is not tested and can cause unexpected behavior.

Setup

Compose Navigator is available via maven central.

  1. Add dependency to to navigation-runtime
dependencies {
    implementation "com.miquido.android.navigation:navigation-runtime:[version]"
}
  1. Choose dependency injection integration used in your project navigation-hilt or navigation-koin
dependencies {
    implementation "com.miquido.android.navigation:navigation-hilt:[version]"
    // OR
    implementation "com.miquido.android.navigation:navigation-koin:[version]"
}

Note: that for multi-module project add this dependency only in application module.

  1. Pass NavController to NavigationHandler to start processing commands sent by Navigator in View Models.
import com.miquido.android.navigation.handler.NavigationHandler

@Composable
fun AppRoot() {
    // ...
    val navController = rememberNavController()
    
    NavigationHandler(
        navController = navController
    )
    
    NavHost(
        navController = navController,
        route = "root",
        startDestination = "start"
    ) {
        // build your NavGraph
    }
}
  1. Create View Model in composable using navEntryViewModel method.
import com.miquido.android.navigation.Navigator
import com.miquido.android.navigation.viewmodel.navEntryViewModel

@Composable
fun StartScreen(
    viewModel: StartViewModel = navEntryViewModel()
) 

Note: that all remaining dependency injection configuration (like using adding @HiltViewModel for Hilt or declaring module with viewModelOf for Koin) remains same as it was.

  1. (Optional) Add integration with Compose Destinations
dependencies {
    implementation "com.miquido.android.navigation:navigation-destinations:[version]"
}

Using this artifact provides additional kotlin extension methods for:

  • Navigator to avoid calling Direction#rote and Route#route when using provided API.
  • NavAction's to allow object creation using Direction / Route directly.

Samples

The repository contains few samples - showcasing:

About

The library is in the beta stage, which means contains a core feature set commonly used. Please do try it and open issues if you find any.

Any feedback and contributions are highly appreciated!

If you like the library, consider starring and sharing it with your colleagues.


About Miquido

android-navigation's People

Contributors

romansavka-mq avatar

Watchers

 avatar  avatar

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.