Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

rjrjr/compose-backstack

Repository files navigation

compose-backstack

Simple library for Jetpack Compose for rendering backstacks of screens and animated transitions when the stack changes. It is not a navigation library, although it is meant to be easy to plug into your navigation library of choice (e.g. compose-router), or even just use on its own.

This library is compatible with Compose dev06.

Usage

The entry point to the library is the Backstack composable.

Example

 sealed class Screen {
   object ContactList: Screen()
   data class ContactDetails(val id: String): Screen()
   data class EditContact(val id: String): Screen()
 }

 data class Navigator(
   val push: (Screen) -> Unit,
   val pop: () -> Unit
 )

 @Composable fun App() {
   var backstack by state { listOf(Screen.ContactList) }
   val navigator = remember {
     Navigator(
       push = { backstack += it },
       pop = { backstack = backstack.dropLast(1) }
     )
   }

   Backstack(backstack) { screen ->
     when(screen) {
       Screen.ContactList -> ShowContactList(navigator)
       is Screen.ContactDetails -> ShowContact(screen.id, navigator)
       is Screen.EditContact -> ShowEditContact(screen.id, navigator)
     }
   }
 }

Samples

There is a sample app in the sample module that demonstrates various transition animations and the behavior with different backstacks.

Gradle

compose-backstack is available from Jitpack:

allprojects {
    repositories {
        …
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.zach-klippenstein:compose-backstack:0.1.0'
}

About

Simple composable for rendering transitions between backstacks.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors

Languages