Android Router Documentation
GitHubDiscussionsIssues
  • Overview
  • Setup
  • Navigation
    • Dialogs
    • BottomSheets
    • Tabs
    • SingleTop
  • ViewModel
  • Platforms
    • Fragments
      • Dialogs
      • BottomSheets
      • Tabs
    • Compose
      • Dialogs
      • BottomSheets
      • Tabs
    • Mixed
  • RouteController
    • RouteController
    • RouteControllerC
    • RouteControllerVM
    • RouteControllerVMC
  • Result API
  • Middleware
  • Chains
  • Injection
    • Dagger
    • Hilt
  • Animation
  • Deep links
Powered by GitBook
On this page

Was this helpful?

Chains

PreviousMiddlewareNextInjection

Last updated 11 months ago

Was this helpful?

A chain is a sequence of screens connected by specific logic. It can represent a wizard with steps like step0, step1, step2, and so on. When the close method is invoked by any of the entries, the entire chain closes.

You can define a chain of screens in the RouteController using the @Chain annotation. It has one parameter that specifies the paths which close the chain.

It's important to note that calling the back method doesn't close a chain.

data class ChainPath(val step: Int): RoutePathResult<Int>

@Chain([ChainStepPath::class])
@Route
abstract class ChainRouteController: RouteControllerApp<ChainPath, ChainViewModel, ChainFragment>()
{
    override fun onCreateViewModel(modelProvider: AndroidViewModelProvider, path: ChainPath): ChainViewModel =
        modelProvider.getViewModel { ChainViewModel(path.step, it) }
}

If you want to explore a comprehensive example, you can refer to the sample-fragment package. It provides a detailed illustration of the concepts discussed, allowing you to see the implementation in action.

Scheme

Short scheme of how chain works