All Projects → florent37 → Navigator

florent37 / Navigator

Licence: apache-2.0
Android Multi-module navigator, trying to find a way to navigate into a modularized android project

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Navigator

Inlineactivityresult
Receive the activity result directly after the startActivityForResult with InlineActivityResult
Stars: ✭ 264 (+101.53%)
Mutual labels:  intent, activity, fragment
Bundler
🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.
Stars: ✭ 195 (+48.85%)
Mutual labels:  intent, activity, fragment
kaptain
👨‍✈️ multi-module navigation on Android has never been so easier!
Stars: ✭ 24 (-81.68%)
Mutual labels:  navigation, navigator, activity
Androidnavigation
A library managing navigation, nested Fragment, StatusBar, Toolbar for Android
Stars: ✭ 636 (+385.5%)
Mutual labels:  navigation, fragment
Native Navigation
Native navigation library for React Native applications
Stars: ✭ 3,126 (+2286.26%)
Mutual labels:  navigation, navigator
Medusa
Android fragment stack controller
Stars: ✭ 395 (+201.53%)
Mutual labels:  navigation, fragment
universal-router
↩️ Router for every occasions
Stars: ✭ 64 (-51.15%)
Mutual labels:  modular, navigation
Thirtyinch
a MVP library for Android favoring a stateful Presenter
Stars: ✭ 1,052 (+703.05%)
Mutual labels:  activity, fragment
Jcnavigator
A decoupled navigator framework of jumping between modules or apps for iOS development.
Stars: ✭ 33 (-74.81%)
Mutual labels:  navigation, navigator
Re Navigate
Example of React Native Navigation with re-frame/re-natal
Stars: ✭ 61 (-53.44%)
Mutual labels:  navigation, navigator
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (-39.69%)
Mutual labels:  activity, fragment
Dart
Extras binding and intent builders for Android apps.
Stars: ✭ 1,203 (+818.32%)
Mutual labels:  intent, navigation
Flowr
FlowR is a wrapper class around the Fragment Manager.
Stars: ✭ 123 (-6.11%)
Mutual labels:  navigation, fragment
Hybrid Navigation
React Native Navigation that supports seamless navigation between Native and React.
Stars: ✭ 258 (+96.95%)
Mutual labels:  navigation, navigator
React Router Navigation
⛵️ A complete navigation library for React Native, React DOM and React Router
Stars: ✭ 498 (+280.15%)
Mutual labels:  navigation, navigator
RouterService
💉Type-safe Navigation/Dependency Injection Framework for Swift
Stars: ✭ 212 (+61.83%)
Mutual labels:  modular, navigation
Viewtooltip
A fluent tooltip for Android
Stars: ✭ 1,029 (+685.5%)
Mutual labels:  activity, fragment
Tieguanyin
Activity Builder.
Stars: ✭ 113 (-13.74%)
Mutual labels:  activity, fragment
Flow
Android wrapper to simplify process for start an Activity
Stars: ✭ 54 (-58.78%)
Mutual labels:  intent, activity
Androidpreferenceactivity
Provides an alternative implementation of Android's PreferenceActivity
Stars: ✭ 63 (-51.91%)
Mutual labels:  navigation, activity

Navigator

Android Multi-module navigator, trying to find a way to navigate into a modularized android multi module project

Import

implementation "com.github.florent37:navigator:1.0.0"

Multi module sample

project
  |
  \--app
  |
  \--routing
  |
  \--splash
  |
  \--home
  |
  \--user

And we want the next screen flow

app --[directly starts]--> Splash --> Home --[clicks on an user]--> User(id) 
  • splash should only know routing
  • home should only know routing
  • user should only know routing
  • app should only know routing to present the splash
  • routing should not know others modules

Define routes

In a dedicated module, created shared routes into a Route object

in module routing :

object Routes {

    object Splash : Route("/")
    
    object Home : Route("/home")
    
    object User : RouteWithParams<UserParams>("/user/{userId}") {
        class UserParams(val userId: String) : Param
    }
}

Bind routes

You need to associate an intent to each Route in your feature's module

in module splash :

Routes.Splash.register { context ->
     Intent(context, SplashActivity::class.java)
}

If you want an android module to register automatically its route, you can bind using applicationprovider's auto providers :

//automatically launched after application's onCreate()
class RouteProvider : Provider() {
    override fun provide() {
        Routes.Splash.register { context ->
            Intent(context, SplashActivity::class.java)
        }
    }
}

then declare it in your module's AndroidManifest.xml

<provider
      android:authorities="${applicationId}.splash.RouteProvider"
      android:name=".RouteProvider"/>

Navigation

Push

You can push a route from an activity (or fragment) using

Navigator.of(this).push(Routes.Home)

or by its path

Navigator.of(this).push("/home/")

Push

You can also change the route from anywhere (eg: an android ViewModel) using Navigator.current()

Navigator.current()?.push(Routes.Home)

A route with parameters

Navigating to a route with parameters forces to specify values

Navigator.of(this).push(Routes.User, UserParams(userId= "3"))

You can retrieve them using kotlin's delegated properties

class UserActivity : Activity {
    private val args by parameter<Routes.User.Params>()
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        val userId = args.userId

You can also call it by path's params

Navigator.of(this).push("/user/3")

It will use moshi to create the parameter from path params

Pop

Navigator.of(this).pop()

PushReplacement

If you want to replace the current screen

Navigator.current()?.pushReplacement(Routes.Splash)

Route Flavors

A flavor is an endpoint of a route, you can use them to navigate to an Activity's BottomNavigation item

object Home : Route("/home/") {
     object UserTabs : Flavor<Home>(this,"home/tabUsers")

     object PostsTabs : FlavorWithParams<Home, PostsTabs.Params>(this,"home/tabPosts") {
         class Params(val userId: Int?) : Parameter()
     }
}

You can push this like a route

Navigator.current()?.push(Routes.Home.UserTabs)

Push

And bind this into your Activity

class HomeActivity : AppCompatActivity(R.layout.activity_home) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewPager.adapter = ViewPagerAdapter(
            supportFragmentManager
        )

        bottomNav.setupWithViewPager(viewPager)

        bindFlavor(Routes.Home.UserTabs, intent)
            .withBottomNav(bottomNav, R.id.tabUsers)

        bindFlavor(Routes.Home.PostsTabs, intent)
            .withBottomNav(bottomNav, R.id.tabPosts)

    }
}

And to retrieve a flavor parameter

class PostsFragment : Fragment {
    private var args by optionalFlavorParameter<Routes.Home.PostsTabs.Params>()
    
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val userId = args.userId

Credits

Author: Florent Champigny http://www.florentchampigny.com/

License

Copyright 2019 Florent37, Inc.

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].