Skip to content

Commit dcebe83

Browse files
feature: Nav3
1 parent edad8ef commit dcebe83

File tree

13 files changed

+158
-125
lines changed

13 files changed

+158
-125
lines changed

FloconDesktop/composeApp/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ kotlin {
6666
implementation(projects.domain)
6767

6868
implementation(projects.library.designsystem)
69+
70+
implementation(projects.navigation)
71+
6972
implementation(libs.kermit)
7073
}
7174
commonTest.dependencies {
Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
package io.github.openflocon.flocondesktop
22

3-
import androidx.compose.foundation.background
4-
import androidx.compose.foundation.layout.Box
5-
import androidx.compose.foundation.layout.fillMaxSize
6-
import androidx.compose.foundation.layout.safeContentPadding
73
import androidx.compose.runtime.Composable
8-
import androidx.compose.runtime.mutableStateListOf
9-
import androidx.compose.runtime.remember
10-
import androidx.compose.ui.Modifier
11-
import androidx.navigation3.runtime.rememberSavedStateNavEntryDecorator
12-
import androidx.navigation3.ui.NavDisplay
13-
import androidx.navigation3.ui.rememberSceneSetupNavEntryDecorator
4+
import androidx.compose.runtime.LaunchedEffect
145
import com.flocon.data.remote.dataRemoteModule
156
import io.github.openflocon.data.core.dataCoreModule
167
import io.github.openflocon.data.local.dataLocalModule
@@ -20,13 +11,17 @@ import io.github.openflocon.flocondesktop.adb.AdbRepositoryImpl
2011
import io.github.openflocon.flocondesktop.app.AppViewModel
2112
import io.github.openflocon.flocondesktop.app.di.appModule
2213
import io.github.openflocon.flocondesktop.common.di.commonModule
23-
import io.github.openflocon.flocondesktop.common.ui.feedback.FeedbackDisplayerView
2414
import io.github.openflocon.flocondesktop.core.di.coreModule
2515
import io.github.openflocon.flocondesktop.features.featuresModule
16+
import io.github.openflocon.flocondesktop.features.network.NetworkRoute
17+
import io.github.openflocon.flocondesktop.features.network.networkNavigation
2618
import io.github.openflocon.flocondesktop.main.di.mainModule
27-
import io.github.openflocon.flocondesktop.main.ui.MainScreen
2819
import io.github.openflocon.library.designsystem.FloconTheme
20+
import io.github.openflocon.navigation.FloconNavigation
21+
import io.github.openflocon.navigation.FloconNavigationState
22+
import io.github.openflocon.navigation.navigationModule
2923
import org.koin.compose.KoinApplication
24+
import org.koin.compose.koinInject
3025
import org.koin.compose.viewmodel.koinViewModel
3126
import org.koin.core.module.dsl.singleOf
3227
import org.koin.dsl.bind
@@ -46,6 +41,7 @@ fun App() {
4641
dataCoreModule,
4742
dataLocalModule,
4843
dataRemoteModule,
44+
navigationModule,
4945
// Temporary
5046
module {
5147
singleOf(::AdbRepositoryImpl) bind AdbRepository::class
@@ -55,34 +51,27 @@ fun App() {
5551
) {
5652
FloconTheme {
5753
val appViewModel: AppViewModel = koinViewModel()
54+
val navigationState = koinInject<FloconNavigationState>()
5855

59-
Box(
60-
Modifier
61-
.safeContentPadding()
62-
.fillMaxSize()
63-
.background(FloconTheme.colorPalette.background),
64-
) {
65-
MainScreen(
66-
modifier = Modifier
67-
.fillMaxSize(),
68-
)
69-
FeedbackDisplayerView()
56+
LaunchedEffect(Unit) {
57+
navigationState.navigate(NetworkRoute)
7058
}
71-
}
72-
}
73-
}
74-
75-
@Composable
76-
private fun Navigation() {
77-
val backStack = remember { mutableStateListOf<Any>() }
78-
79-
NavDisplay(
80-
backStack = backStack,
81-
entryDecorators = listOf(
82-
rememberSceneSetupNavEntryDecorator(),
83-
rememberSavedStateNavEntryDecorator()
84-
)
85-
) {
8659

60+
FloconNavigation {
61+
networkNavigation()
62+
}
63+
// Box(
64+
// Modifier
65+
// .safeContentPadding()
66+
// .fillMaxSize()
67+
// .background(FloconTheme.colorPalette.background),
68+
// ) {
69+
// MainScreen(
70+
// modifier = Modifier
71+
// .fillMaxSize(),
72+
// )
73+
// FeedbackDisplayerView()
74+
// }
75+
}
8776
}
8877
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.openflocon.flocondesktop.features.network
2+
3+
import androidx.navigation3.runtime.EntryProviderBuilder
4+
import androidx.navigation3.runtime.entry
5+
import io.github.openflocon.flocondesktop.features.network.list.view.NetworkScreen
6+
import io.github.openflocon.navigation.FloconRoute
7+
import kotlinx.serialization.Serializable
8+
9+
@Serializable
10+
data object NetworkRoute : FloconRoute
11+
12+
fun EntryProviderBuilder<FloconRoute>.networkNavigation() {
13+
entry<NetworkRoute> {
14+
NetworkScreen()
15+
}
16+
}

FloconDesktop/gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ uiToolingPreviewDesktop = "1.8.2"
3636

3737
# TODO Sort
3838
nav3Core = "1.0.0-alpha08"
39+
navEvent = "1.0.0-alpha07"
3940
lifecycleViewmodelNav3 = "2.10.0-alpha03"
4041
kotlinxSerializationCore = "1.8.1"
4142

@@ -94,6 +95,9 @@ ui-tooling-preview-desktop = { module = "org.jetbrains.compose.ui:ui-tooling-pre
9495
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "nav3Core" }
9596
androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "nav3Core" }
9697

98+
androidx-navigationevent-core = { group = "androidx.navigationevent", name = "navigationevent", version.ref = "navEvent" }
99+
androidx-navigationevent-compose = { group = "androidx.navigationevent", name = "navigationevent-compose", version.ref = "navEvent" }
100+
97101
# Optional add-on libraries
98102
androidx-lifecycle-viewmodel-navigation3 = { module = "androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "lifecycleViewmodelNav3" }
99103
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerializationCore" }

FloconDesktop/navigation/build.gradle.kts

Lines changed: 26 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,47 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
2+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
3+
14
plugins {
25
alias(libs.plugins.kotlinMultiplatform)
3-
alias(libs.plugins.android.kotlin.multiplatform.library)
4-
alias(libs.plugins.android.lint)
5-
}
6-
7-
kotlin {
8-
9-
// Target declarations - add or remove as needed below. These define
10-
// which platforms this KMP module supports.
11-
// See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets
12-
androidLibrary {
13-
namespace = "io.github.openflocon.navigation"
14-
compileSdk = 36
15-
minSdk = 24
166

17-
withHostTestBuilder {
18-
}
7+
alias(libs.plugins.composeCompiler)
8+
alias(libs.plugins.composeMultiplatform)
199

20-
withDeviceTestBuilder {
21-
sourceSetTreeName = "test"
22-
}.configure {
23-
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
24-
}
25-
}
26-
27-
// For iOS targets, this is also where you should
28-
// configure native binary output. For more information, see:
29-
// https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks
30-
31-
// A step-by-step guide on how to include this library in an XCode
32-
// project can be found here:
33-
// https://developer.android.com/kotlin/multiplatform/migrate
34-
val xcfName = "navigationKit"
10+
alias(libs.plugins.kotlinx.serialization)
11+
}
3512

36-
iosX64 {
37-
binaries.framework {
38-
baseName = xcfName
39-
}
13+
kotlin {
14+
jvmToolchain(21)
15+
16+
compilerOptions {
17+
// Pour Kotlin 1.9+
18+
freeCompilerArgs.add("-opt-in=kotlin.time.ExperimentalTime")
19+
freeCompilerArgs.add("-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi")
20+
freeCompilerArgs.add("-Xcontext-parameters")
21+
freeCompilerArgs.add("-Xcontext-sensitive-resolution")
4022
}
4123

42-
iosArm64 {
43-
binaries.framework {
44-
baseName = xcfName
45-
}
24+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
25+
compilerOptions {
26+
languageVersion.set(KotlinVersion.KOTLIN_2_2)
4627
}
4728

48-
iosSimulatorArm64 {
49-
binaries.framework {
50-
baseName = xcfName
51-
}
52-
}
29+
jvm("desktop")
5330

5431
// Source set declarations.
5532
// Declaring a target automatically creates a source set with the same name. By default, the
5633
// Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is
5734
// common to share sources between related targets.
5835
// See: https://kotlinlang.org/docs/multiplatform-hierarchy.html
5936
sourceSets {
60-
commonMain {
61-
dependencies {
62-
implementation(libs.kotlin.stdlib)
63-
// Add KMP dependencies here
64-
}
65-
}
37+
commonMain.dependencies {
38+
implementation(projects.library.designsystem)
6639

67-
commonTest {
68-
dependencies {
69-
implementation(libs.kotlin.test)
70-
}
71-
}
72-
73-
androidMain {
74-
dependencies {
75-
// Add Android-specific dependencies here. Note that this source set depends on
76-
// commonMain by default and will correctly pull the Android artifacts of any KMP
77-
// dependencies declared in commonMain.
78-
}
79-
}
80-
81-
getByName("androidDeviceTest") {
82-
dependencies {
83-
implementation(libs.androidx.runner)
84-
implementation(libs.androidx.core)
85-
implementation(libs.androidx.testExt.junit)
86-
}
87-
}
40+
implementation(project.dependencies.platform(libs.koin.bom))
41+
implementation(libs.koin.core)
42+
implementation(libs.koin.compose.viewmodel)
8843

89-
iosMain {
90-
dependencies {
91-
// Add iOS-specific dependencies here. This a source set created by Kotlin Gradle
92-
// Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as
93-
// part of KMP’s default source set hierarchy. Note that this source set depends
94-
// on common by default and will correctly pull the iOS artifacts of any
95-
// KMP dependencies declared in commonMain.
96-
}
44+
api(libs.kotlinx.serialization.core)
9745
}
9846
}
9947

FloconDesktop/navigation/src/androidMain/kotlin/io/github/openflocon/navigation/Platform.android.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.openflocon.navigation
2+
3+
import org.koin.dsl.module
4+
5+
val navigationModule = module {
6+
// Add qualifier ?
7+
single { FloconNavigationState() }
8+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.github.openflocon.navigation
2+
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.remember
6+
import androidx.compose.ui.Modifier
7+
import androidx.navigation3.runtime.EntryProviderBuilder
8+
import androidx.navigation3.runtime.entry
9+
import androidx.navigation3.runtime.entryProvider
10+
import androidx.navigation3.ui.NavDisplay
11+
import androidx.navigationevent.NavigationEventDispatcher
12+
import androidx.navigationevent.NavigationEventDispatcherOwner
13+
import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner
14+
import androidx.navigationevent.compose.NavigationEventDispatcherOwner
15+
import org.koin.compose.koinInject
16+
17+
@Composable
18+
fun FloconNavigation(
19+
builder: EntryProviderBuilder<FloconRoute>.() -> Unit
20+
) {
21+
val navigationState = koinInject<FloconNavigationState>()
22+
val dispatcher = remember { NavigationEventDispatcher() }
23+
val parent = remember {
24+
object : NavigationEventDispatcherOwner {
25+
override val navigationEventDispatcher: NavigationEventDispatcher = dispatcher
26+
}
27+
}
28+
29+
LocalNavigationEventDispatcherOwner.provides(parent)
30+
31+
NavigationEventDispatcherOwner(parent = parent) {
32+
NavDisplay(
33+
backStack = navigationState.stack,
34+
entryDecorators = listOf(
35+
// rememberSceneSetupNavEntryDecorator(),
36+
// rememberSavedStateNavEntryDecorator()
37+
),
38+
onBack = { navigationState.back(it) },
39+
entryProvider = entryProvider {
40+
entry<LoadingRoute> {
41+
Box(Modifier)
42+
}
43+
builder()
44+
}
45+
)
46+
}
47+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.openflocon.navigation
2+
3+
class FloconNavigationState internal constructor() {
4+
5+
private val _stack = mutableListOf<FloconRoute>(LoadingRoute)
6+
val stack: List<FloconRoute> = _stack
7+
8+
fun navigate(route: FloconRoute) {
9+
_stack.add(route)
10+
}
11+
12+
fun back(count: Int = 1) {
13+
repeat(count) { _stack.removeLast() }
14+
}
15+
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.github.openflocon.navigation
2+
3+
import androidx.navigation3.runtime.NavKey
4+
5+
interface FloconRoute : NavKey

0 commit comments

Comments
 (0)