Brick
Take control of your apps
Brick is a lightweight library to make navigation.
Features
- Framework free (Router can be injected in any layer of project. Navigate from any place you want. Example: UI-navigation or business logic navigation)
- Child screen navigation (easy BottomSheet navigation, Tab navigation, Dialogs navigation)
- Nested navigation
- Lifecycle
- Multi-module navigation (provide router instance from any module to any module or just implement all app navigation inside one module or something else)
- Deep-link support
- Arguments support
- Screens communication support
- Current screen check
- Transition animations
- Overlay navigation
Samples
Overlay sample | Transition Animation | Small sample | Large sample |
Desktop sample |
Installation
Add repository in your project
repositories {
mavenCentral()
maven {
url "https://maven.pkg.jetbrains.space/public/p/compose/dev"
}
}
Add the dependency in your build.gradle
dependencies {
//Brick
implementation 'io.github.alphicc:brick:1.0.0-rc01'
}
Android: Set jvmTarget in your build.gradle
kotlinOptions {
jvmTarget = '11'
}
Thats all!
Usage
- Create Router in any place of your project (Note: router contains all information about screen. Router destroyed = all navigation/screens data destroyed).
val router: TreeRouter = TreeRouter.new()
- Create Screen. Screen != UI. Screen has lifecycle, channels to communicate between other screens. Screen can live without UI. UI - part of Screen.
val screen1 = Screen<Unit>(
key = "1",
content = { SimpleScreen(1, "new") { smallSampleRouter.addScreen(screen2) } } // content - ui
)
- Provide ContainerConnector to %PLATFORM%AnimatedScreensContainer or %PLATFORM%ScreensContainer . Your Router implements ContainerConnector.
class SmallSampleActivity : ComponentActivity() {
val containerConnector: ContainerConnector = ... //inject or provide from application class
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AndroidScreensContainer(containerConnector)
}
}
}
- Navigate!
Work representation
Integration schema
Work schema
Lifecycle sample
Multistack navigation
- Create nested router using branch method.
//Screens.bottomMenuScreen.key - screen key that contains nested container
private val firstMenuRouter = mainRouter.branch(Screens.bottomMenuScreen.key).apply {
addScreen(Screens.innerNavigationScreen, this)//initial navigation sample
}
- Pass created nested router to your nested %PLATFORM%ScreensContainer.
//inside your composable function
%PLATFORM%AnimatedScreensContainer(firstMenuRouter)
- Use your nested router to make nested navigation!
Multistack graph sample (simple)
Multistack graph sample (extended)
Navigation methods list
- currentScreenKey
- backScreen
- backToScreen
- replaceScreen
- addScreen
- lastChildKey
- backChild
- backToChild
- replaceChild
- addChild
- cleanRouter
- setOverlay
- removeOverlay
- newRootScreen