-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
222 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
sample-compose/src/main/java/com/chrynan/navigation/sample/compose/App.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
sample-compose/src/main/java/com/chrynan/navigation/sample/compose/Destination.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
sample-compose/src/main/java/com/chrynan/navigation/sample/compose/MainNavigationContext.kt
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
sample-compose/src/main/java/com/chrynan/navigation/sample/compose/NavigationComponents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.chrynan.navigation.sample.compose | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Home | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material.icons.filled.Settings | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import com.chrynan.navigation.NavigationContext | ||
|
||
sealed class AppDestination { | ||
|
||
object Home : AppDestination() | ||
|
||
object Search : AppDestination() | ||
|
||
object Settings : AppDestination() | ||
|
||
data class Details(val itemId: Int) : AppDestination() | ||
} | ||
|
||
enum class AppContext( | ||
val title: String, | ||
val icon: ImageVector, | ||
override val initialDestination: AppDestination | ||
) : NavigationContext<AppDestination> { | ||
|
||
HOME(title = "Home", icon = Icons.Default.Home, initialDestination = AppDestination.Home), | ||
|
||
SEARCH(title = "Search", icon = Icons.Default.Search, initialDestination = AppDestination.Search), | ||
|
||
SETTINGS(title = "Settings", icon = Icons.Default.Settings, initialDestination = AppDestination.Settings) | ||
} |
74 changes: 74 additions & 0 deletions
74
sample-compose/src/main/java/com/chrynan/navigation/sample/compose/composable/Items.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
@file:Suppress("FunctionName") | ||
|
||
package com.chrynan.navigation.sample.compose.composable | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.ListItem | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.unit.dp | ||
|
||
fun Items( | ||
modifier: Modifier = Modifier, | ||
onItemClick: (itemId: Int) -> Unit, | ||
header: (@Composable () -> Unit)? = null | ||
) { | ||
LazyColumn(modifier = modifier) { | ||
if (header != null) { | ||
item(key = "Header") { | ||
header.invoke() | ||
} | ||
} | ||
|
||
items( | ||
count = 10, | ||
key = { it } | ||
) { index -> | ||
Item( | ||
modifier = Modifier.fillMaxWidth(), | ||
title = "Item ${index + 1}", | ||
onClick = { | ||
onItemClick.invoke(index) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun Item( | ||
modifier: Modifier = Modifier, | ||
title: String, | ||
description: String? = null, | ||
icon: ImageVector? = null, | ||
onClick: () -> Unit | ||
) { | ||
ListItem( | ||
modifier = modifier.clickable { onClick.invoke() }, | ||
text = { | ||
Text(text = title) | ||
}, | ||
secondaryText = { | ||
if (description != null) { | ||
Text(text = description) | ||
} | ||
}, | ||
icon = { | ||
if (icon != null) { | ||
Icon( | ||
modifier = Modifier.size(24.dp), | ||
imageVector = icon, | ||
contentDescription = null | ||
) | ||
} | ||
} | ||
) | ||
} |
53 changes: 53 additions & 0 deletions
53
...pose/src/main/java/com/chrynan/navigation/sample/compose/example/MultipleContextSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.chrynan.navigation.sample.compose.example | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.chrynan.navigation.ExperimentalNavigationApi | ||
import com.chrynan.navigation.changeContext | ||
import com.chrynan.navigation.compose.NavigationContainer | ||
import com.chrynan.navigation.compose.rememberNavigator | ||
import com.chrynan.navigation.goTo | ||
import com.chrynan.navigation.sample.compose.AppContext | ||
import com.chrynan.navigation.sample.compose.AppDestination | ||
import com.chrynan.navigation.sample.compose.composable.Items | ||
|
||
@ExperimentalNavigationApi | ||
@Composable | ||
fun MultipleContextSample() { | ||
val navigator = rememberNavigator(initialContext = AppContext.HOME) | ||
|
||
Column { | ||
Box(modifier = Modifier.weight(1f)) { | ||
NavigationContainer(navigator = navigator) { context, destination -> | ||
when (destination) { | ||
is AppDestination.Home -> Items( | ||
modifier = Modifier.matchParentSize(), | ||
onItemClick = { | ||
navigator.goTo(destination = AppDestination.Details(itemId = it)) | ||
}, | ||
header = { | ||
Text(text = context.title, style = MaterialTheme.typography.h6) | ||
}) | ||
|
||
is AppDestination.Details -> Text("${context.title}: ${destination.itemId}") | ||
is AppDestination.Settings -> Text(context.title) | ||
is AppDestination.Search -> Text(context.title) | ||
} | ||
} | ||
} | ||
|
||
BottomNavigation { | ||
AppContext.values().forEach { context -> | ||
BottomNavigationItem( | ||
selected = false, | ||
onClick = { navigator.changeContext(context) }, | ||
label = { Text(context.title) }, | ||
icon = { Image(imageVector = context.icon, contentDescription = null) } | ||
) | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ompose/src/main/java/com/chrynan/navigation/sample/compose/example/SingleContextSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.chrynan.navigation.sample.compose.example | ||
|
||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import com.chrynan.navigation.ExperimentalNavigationApi | ||
import com.chrynan.navigation.compose.NavigationContainer | ||
import com.chrynan.navigation.compose.rememberNavigator | ||
import com.chrynan.navigation.goBack | ||
import com.chrynan.navigation.goTo | ||
import com.chrynan.navigation.sample.compose.AppDestination | ||
import com.chrynan.navigation.sample.compose.composable.Items | ||
|
||
@Composable | ||
@ExperimentalNavigationApi | ||
fun SingleContextSample() { | ||
val navigator = rememberNavigator<AppDestination>(initialDestination = AppDestination.Home) | ||
|
||
BackHandler { | ||
navigator.goBack() | ||
} | ||
|
||
NavigationContainer( | ||
navigator = navigator, | ||
modifier = Modifier.fillMaxSize() | ||
) { destination -> | ||
when (destination) { | ||
is AppDestination.Home -> Items( | ||
modifier = Modifier.matchParentSize(), | ||
onItemClick = { | ||
navigator.goTo(destination = AppDestination.Details(itemId = it)) | ||
}, | ||
header = { | ||
Text(text = "Home", style = MaterialTheme.typography.h6) | ||
}) | ||
|
||
is AppDestination.Details -> Column( | ||
modifier = Modifier.matchParentSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Text(text = "Details", style = MaterialTheme.typography.h6) | ||
|
||
Text(text = "Item ${destination.itemId}", style = MaterialTheme.typography.subtitle1) | ||
} | ||
|
||
else -> {} | ||
} | ||
} | ||
} |