Skip to content

Commit f4e8ebe

Browse files
Align code snippets in readme.md (#131)
Code snippets in readme are misaligned which makes reading code snippets a bit harder.
1 parent a7fc9aa commit f4e8ebe

File tree

1 file changed

+81
-78
lines changed

1 file changed

+81
-78
lines changed

readme.md

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ Add this library dependency and KotlinX.Serialization support
2626

2727
```kotlin
2828
plugins {
29-
id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10"
29+
id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10"
3030
}
31+
3132
dependencies {
32-
implementation("com.kiwi.navigation-compose.typed:core:<version>")
33-
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.0")
33+
implementation("com.kiwi.navigation-compose.typed:core:<version>")
34+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.0")
3435
}
3536
```
3637

@@ -44,13 +45,14 @@ Create app's destinations
4445
import com.kiwi.navigationcompose.typed.Destination
4546

4647
sealed interface Destinations : Destination {
47-
@Serializable
48-
data object Home : Destinations
49-
50-
@Serializable
51-
data class Article(
52-
val id: String,
53-
) : Destinations
48+
49+
@Serializable
50+
data object Home : Destinations
51+
52+
@Serializable
53+
data class Article(
54+
val id: String,
55+
) : Destinations
5456
}
5557
```
5658

@@ -61,15 +63,15 @@ import com.kiwi.navigationcompose.typed.composable
6163
import com.kiwi.navigationcompose.typed.createRoutePattern
6264

6365
NavGraph(
64-
startDestination = createRoutePattern<Destinations.Home>(),
66+
startDestination = createRoutePattern<Destinations.Home>(),
6567
) {
66-
composable<Destinations.Home> {
67-
Home()
68-
}
69-
composable<Destinations.Article> {
70-
// this is Destinations.Article
71-
Article(id)
72-
}
68+
composable<Destinations.Home> {
69+
Home()
70+
}
71+
composable<Destinations.Article> {
72+
// this is Destinations.Article
73+
Article(id)
74+
}
7375
}
7476
```
7577

@@ -81,33 +83,33 @@ import com.kiwi.navigationcompose.typed.navigate
8183

8284
@Composable
8385
fun AppNavHost() {
84-
val navController = rememberNavController()
85-
NavGraph(
86-
navController = navController,
87-
) {
88-
composable<Destinations.Home> {
89-
Home(navController::navigate)
90-
}
91-
}
86+
val navController = rememberNavController()
87+
NavGraph(
88+
navController = navController,
89+
) {
90+
composable<Destinations.Home> {
91+
Home(navController::navigate)
92+
}
93+
}
9294
}
9395

9496
@Composable
9597
private fun Home(
96-
onNavigate: (Destination) -> Unit,
98+
onNavigate: (Destination) -> Unit,
9799
) {
98-
Home(
99-
onArticleClick = { id -> onNavigate(Destinations.Article(id)) },
100-
)
100+
Home(
101+
onArticleClick = { id -> onNavigate(Destinations.Article(id)) },
102+
)
101103
}
102104

103105
@Composable
104106
private fun Home(
105-
onArticleClick: (id: Int) -> Unit,
107+
onArticleClick: (id: Int) -> Unit,
106108
) {
107-
Column {
108-
Button(onClick = { onArticleClick(1) }) { Text("...") }
109-
Button(onClick = { onArticleClick(2) }) { Text("...") }
110-
}
109+
Column {
110+
Button(onClick = { onArticleClick(1) }) { Text("...") }
111+
Button(onClick = { onArticleClick(2) }) { Text("...") }
112+
}
111113
}
112114
```
113115

@@ -119,25 +121,25 @@ For example, in Koin:
119121

120122
```kotlin
121123
val KoinModule = module {
122-
viewModelOf(::DemoViewModel)
124+
viewModelOf(::DemoViewModel)
123125
}
124126

125127
fun DemoScreen(arguments: HomeDestinations.Demo) {
126-
val viewModel = getViewModel<DemoViewModel> { parametersOf(arguments) }
128+
val viewModel = getViewModel<DemoViewModel> { parametersOf(arguments) }
127129
}
128130

129131
class DemoViewModel(
130-
arguments: HomeDestinations.Demo,
132+
arguments: HomeDestinations.Demo,
131133
)
132134
```
133135

134136
Alternatively, you can read your destination from a `SavedStateHandle` instance:
135137

136138
```kotlin
137139
class DemoViewModel(
138-
state: SavedStateHandle,
140+
state: SavedStateHandle,
139141
) : ViewModel() {
140-
val arguments = state.decodeArguments<HomeDestinations.Demo>()
142+
val arguments = state.decodeArguments<HomeDestinations.Demo>()
141143
}
142144
```
143145

@@ -153,23 +155,23 @@ import com.kiwi.navigationcompose.typed.Destination
153155
import com.kiwi.navigationcompose.typed.registerDestinationType
154156

155157
private inline fun <reified T : Destination> NavGraphBuilder.bottomSheet(
156-
noinline content: @Composable T.(NavBackStackEntry) -> Unit,
158+
noinline content: @Composable T.(NavBackStackEntry) -> Unit,
157159
) {
158-
val serializer = serializer<T>()
159-
registerDestinationType(T::class, serializer)
160-
bottomSheet(
161-
route = createRoutePattern(serializer),
162-
arguments = createNavArguments(serializer),
163-
) {
164-
val arguments = decodeArguments(serializer, it)
165-
arguments.content(it)
166-
}
160+
val serializer = serializer<T>()
161+
registerDestinationType(T::class, serializer)
162+
bottomSheet(
163+
route = createRoutePattern(serializer),
164+
arguments = createNavArguments(serializer),
165+
) {
166+
val arguments = decodeArguments(serializer, it)
167+
arguments.content(it)
168+
}
167169
}
168170

169171
NavGraph {
170-
bottomSheet<Destinations.Article> {
171-
Article(id)
172-
}
172+
bottomSheet<Destinations.Article> {
173+
Article(id)
174+
}
173175
}
174176
```
175177

@@ -185,38 +187,39 @@ import com.kiwi.navigationcompose.typed.ResultDestination
185187
import com.kiwi.navigationcompose.typed.setResult
186188

187189
sealed interface Destinations : Destination {
188-
@Serializable
189-
data object Dialog : Destinations, ResultDestination<Dialog.Result> {
190-
@Serializable
191-
data class Result(
192-
val something: Int,
193-
)
194-
}
190+
191+
@Serializable
192+
data object Dialog : Destinations, ResultDestination<Dialog.Result> {
193+
@Serializable
194+
data class Result(
195+
val something: Int,
196+
)
197+
}
195198
}
196199

197200
@Composable
198201
fun Host(navController: NavController) {
199-
DialogResultEffect(navController) { result: Destinations.Dialog.Result ->
200-
println(result)
201-
// process the result
202-
}
203-
204-
Button(
205-
onClick = { navController.navigate(Destinations.Dialog) },
206-
) {
207-
Text("Open")
208-
}
202+
DialogResultEffect(navController) { result: Destinations.Dialog.Result ->
203+
println(result)
204+
// process the result
205+
}
206+
207+
Button(
208+
onClick = { navController.navigate(Destinations.Dialog) },
209+
) {
210+
Text("Open")
211+
}
209212
}
210213

211214
@Composable
212215
fun Dialog(navController: NavController) {
213-
Button(
214-
onClick = {
215-
navController.setResult(Destinations.Dialog.Result(something = 42))
216-
navController.popBackStack()
217-
}
218-
) {
219-
Text("Set and close")
220-
}
216+
Button(
217+
onClick = {
218+
navController.setResult(Destinations.Dialog.Result(something = 42))
219+
navController.popBackStack()
220+
}
221+
) {
222+
Text("Set and close")
223+
}
221224
}
222225
```

0 commit comments

Comments
 (0)