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.
The entry point to the library is the Backstack composable.
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)
}
}
}There is a sample app in the sample module that demonstrates various transition animations and
the behavior with different backstacks.
compose-backstack is available from Jitpack:
allprojects {
repositories {
…
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.zach-klippenstein:compose-backstack:0.1.0'
}