Skip to content

Commit 96b7cec

Browse files
author
TEYSSANDIER Raphael
committed
feature: Nav3
1 parent a43176f commit 96b7cec

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
@@ -74,6 +74,9 @@ kotlin {
7474
implementation(projects.domain)
7575

7676
implementation(projects.library.designsystem)
77+
78+
implementation(projects.navigation)
79+
7780
implementation(libs.kermit)
7881
}
7982
commonTest.dependencies {

FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/App.kt

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import androidx.compose.foundation.layout.Box
44
import androidx.compose.foundation.layout.fillMaxSize
55
import androidx.compose.foundation.layout.safeContentPadding
66
import androidx.compose.runtime.Composable
7-
import androidx.compose.runtime.mutableStateListOf
8-
import androidx.compose.runtime.remember
9-
import androidx.compose.ui.Modifier
10-
import androidx.navigation3.runtime.rememberSavedStateNavEntryDecorator
11-
import androidx.navigation3.ui.NavDisplay
12-
import androidx.navigation3.ui.rememberSceneSetupNavEntryDecorator
7+
import androidx.compose.runtime.LaunchedEffect
138
import com.flocon.data.remote.dataRemoteModule
149
import io.github.openflocon.data.core.dataCoreModule
1510
import io.github.openflocon.data.local.dataLocalModule
@@ -19,14 +14,17 @@ import io.github.openflocon.flocondesktop.adb.AdbRepositoryImpl
1914
import io.github.openflocon.flocondesktop.app.AppViewModel
2015
import io.github.openflocon.flocondesktop.app.di.appModule
2116
import io.github.openflocon.flocondesktop.common.di.commonModule
22-
import io.github.openflocon.flocondesktop.common.ui.feedback.FeedbackDisplayerView
2317
import io.github.openflocon.flocondesktop.core.di.coreModule
2418
import io.github.openflocon.flocondesktop.features.featuresModule
19+
import io.github.openflocon.flocondesktop.features.network.NetworkRoute
20+
import io.github.openflocon.flocondesktop.features.network.networkNavigation
2521
import io.github.openflocon.flocondesktop.main.di.mainModule
26-
import io.github.openflocon.flocondesktop.main.ui.MainScreen
2722
import io.github.openflocon.library.designsystem.FloconTheme
28-
import io.github.openflocon.library.designsystem.components.FloconSurface
23+
import io.github.openflocon.navigation.FloconNavigation
24+
import io.github.openflocon.navigation.FloconNavigationState
25+
import io.github.openflocon.navigation.navigationModule
2926
import org.koin.compose.KoinApplication
27+
import org.koin.compose.koinInject
3028
import org.koin.compose.viewmodel.koinViewModel
3129
import org.koin.core.module.dsl.singleOf
3230
import org.koin.dsl.bind
@@ -46,6 +44,7 @@ fun App() {
4644
dataCoreModule,
4745
dataLocalModule,
4846
dataRemoteModule,
47+
navigationModule,
4948
// Temporary
5049
module {
5150
singleOf(::AdbRepositoryImpl) bind AdbRepository::class
@@ -55,37 +54,27 @@ fun App() {
5554
) {
5655
FloconTheme {
5756
val appViewModel: AppViewModel = koinViewModel()
57+
val navigationState = koinInject<FloconNavigationState>()
5858

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

63+
FloconNavigation {
64+
networkNavigation()
65+
}
66+
// Box(
67+
// Modifier
68+
// .safeContentPadding()
69+
// .fillMaxSize()
70+
// .background(FloconTheme.colorPalette.background),
71+
// ) {
72+
// MainScreen(
73+
// modifier = Modifier
74+
// .fillMaxSize(),
75+
// )
76+
// FeedbackDisplayerView()
77+
// }
78+
}
9079
}
9180
}
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
@@ -37,6 +37,7 @@ buildconfig = "5.6.8"
3737

3838
# TODO Sort
3939
nav3Core = "1.0.0-alpha08"
40+
navEvent = "1.0.0-alpha07"
4041
lifecycleViewmodelNav3 = "2.10.0-alpha03"
4142
kotlinxSerializationCore = "1.8.1"
4243

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

99+
androidx-navigationevent-core = { group = "androidx.navigationevent", name = "navigationevent", version.ref = "navEvent" }
100+
androidx-navigationevent-compose = { group = "androidx.navigationevent", name = "navigationevent-compose", version.ref = "navEvent" }
101+
98102
# Optional add-on libraries
99103
androidx-lifecycle-viewmodel-navigation3 = { module = "androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "lifecycleViewmodelNav3" }
100104
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)