Skip to content

Commit

Permalink
Updated sample-compose module
Browse files Browse the repository at this point in the history
  • Loading branch information
chRyNaN committed Mar 4, 2022
1 parent 4fcb2c5 commit 813bce5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.chrynan.navigation.sample.compose

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -19,13 +16,7 @@ import com.chrynan.navigation.compose.rememberNavigatorByKey
@Composable
fun App() {
val navigator = rememberNavigatorByKey(
initialContext = MainScope.HOME,
initialKeys = { scope ->
when (scope) {
MainScope.HOME -> NavKey.HOME
MainScope.SETTINGS -> NavKey.SETTINGS
}
},
initialContext = MainNavigationContext.HOME,
content = { key ->
Column(
modifier = Modifier.fillMaxSize(),
Expand All @@ -34,17 +25,20 @@ fun App() {
) {
when (key) {
NavKey.HOME -> {
Text("Home")
Text("Home", style = MaterialTheme.typography.h2)

Button(modifier = Modifier.padding(top = 20.dp), onClick = { navigator.goTo(NavKey.DETAILS) }) {
Button(
modifier = Modifier.padding(top = 20.dp),
onClick = { navigator.goTo(NavKey.DETAILS) }
) {
Text("Details")
}
}
NavKey.SETTINGS -> {
Text("Settings")
Text("Settings", style = MaterialTheme.typography.h2)
}
NavKey.DETAILS -> {
Text("Details")
Text("Details", style = MaterialTheme.typography.h2)
}
}
}
Expand All @@ -57,12 +51,12 @@ fun App() {
}

BottomNavigation {
MainScope.values().forEach { scope ->
MainNavigationContext.values().forEach { context ->
BottomNavigationItem(
selected = false,
onClick = { navigator.changeContext(scope) },
label = { Text(scope.title) },
icon = { Image(imageVector = scope.icon, contentDescription = null) }
onClick = { navigator.changeContext(context) },
label = { Text(context.title) },
icon = { Image(imageVector = context.icon, contentDescription = null) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Settings
import androidx.compose.ui.graphics.vector.ImageVector
import com.chrynan.navigation.NavigationContext

enum class MainScope(
enum class MainNavigationContext(
val title: String,
val icon: ImageVector
) {
) : NavigationContext<NavKey> {

HOME(title = "Home", icon = Icons.Default.Home),
SETTINGS(title = "Settings", icon = Icons.Default.Settings)

SETTINGS(title = "Settings", icon = Icons.Default.Settings);

override val initialKey: NavKey
get() = when (this) {
HOME -> NavKey.HOME
SETTINGS -> NavKey.SETTINGS
}
}

0 comments on commit 813bce5

Please sign in to comment.