From ce79a8fc4dca3e8fcc6e12af1ea552ca6ffd5e70 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Tue, 5 Mar 2024 22:51:16 -0600 Subject: [PATCH] Introduce Voyager lib and configure basic Navigation. - Voyager is a navigation library that allows us to navigate between Composable screens. - I created basic LicenseScreen and HomeScreen. --- composeApp/build.gradle.kts | 9 +++-- .../kotlin/net/agorise/kee/MainActivity.kt | 13 ++----- .../agorise/kee/ui/screen/home/HomeScreen.kt | 13 +++++++ .../kee/ui/screen/license/LicenseScreen.kt | 37 +++++++++++++++++++ .../kotlin/net/agorise/kee/main.kt | 12 ++---- .../src/iosMain/kotlin/MainViewController.kt | 5 ++- gradle/libs.versions.toml | 20 ++-------- 7 files changed, 67 insertions(+), 42 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 5d47776..d1b62aa 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -36,12 +36,13 @@ kotlin { implementation(libs.androidx.activity.compose) } commonMain.dependencies { - implementation(compose.runtime) - implementation(compose.foundation) - implementation(compose.material3) - implementation(compose.ui) implementation(compose.components.resources) implementation(compose.components.uiToolingPreview) + implementation(compose.foundation) + implementation(compose.material3) + implementation(compose.runtime) + implementation(compose.ui) + implementation(libs.voyager.navigator) implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1") } desktopMain.dependencies { diff --git a/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt b/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt index cf74021..9802518 100644 --- a/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/net/agorise/kee/MainActivity.kt @@ -1,24 +1,17 @@ package net.agorise.kee -import App import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.runtime.Composable -import androidx.compose.ui.tooling.preview.Preview +import cafe.adriel.voyager.navigator.Navigator +import net.agorise.kee.ui.screen.license.LicenseScreen class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - App() + Navigator(LicenseScreen()) } } } - -@Preview -@Composable -fun AppAndroidPreview() { - App() -} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt new file mode 100644 index 0000000..935366c --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/home/HomeScreen.kt @@ -0,0 +1,13 @@ +package net.agorise.kee.ui.screen.home + +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import cafe.adriel.voyager.core.screen.Screen + +class HomeScreen : Screen { + + @Composable + override fun Content() { + Text("Welcome to Home Screen") + } +} diff --git a/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt new file mode 100644 index 0000000..2937ea7 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/net/agorise/kee/ui/screen/license/LicenseScreen.kt @@ -0,0 +1,37 @@ +package net.agorise.kee.ui.screen.license + +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import cafe.adriel.voyager.core.screen.Screen +import cafe.adriel.voyager.navigator.LocalNavigator +import cafe.adriel.voyager.navigator.currentOrThrow +import net.agorise.kee.ui.screen.home.HomeScreen +import org.jetbrains.compose.ui.tooling.preview.Preview + +class LicenseScreen : Screen { + + @Composable + override fun Content() { + HomeScreenContent() + } +} + +@Composable +fun HomeScreenContent() { + val navigator = LocalNavigator.currentOrThrow + + Column { + Text("Welcome to License Screen") + Button(onClick = { navigator.replace(HomeScreen()) }) { + Text("Accept") + } + } +} + +@Preview +@Composable +fun HomeScreenContentPreview() { + HomeScreenContent() +} diff --git a/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt b/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt index afeeed8..842c13b 100644 --- a/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt +++ b/composeApp/src/desktopMain/kotlin/net/agorise/kee/main.kt @@ -1,13 +1,13 @@ package net.agorise.kee -import androidx.compose.runtime.Composable import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Window import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.application import androidx.compose.ui.window.rememberWindowState -import org.jetbrains.compose.ui.tooling.preview.Preview +import cafe.adriel.voyager.navigator.Navigator +import net.agorise.kee.ui.screen.license.LicenseScreen fun main() = application { val state = rememberWindowState( @@ -15,12 +15,6 @@ fun main() = application { position = WindowPosition(300.dp, 300.dp) ) Window(title = "Kee", onCloseRequest = ::exitApplication, state = state) { - App() + Navigator(LicenseScreen()) } } - -@Preview -@Composable -fun AppAndroidPreview() { - App() -} diff --git a/composeApp/src/iosMain/kotlin/MainViewController.kt b/composeApp/src/iosMain/kotlin/MainViewController.kt index fcf5eba..10867f4 100644 --- a/composeApp/src/iosMain/kotlin/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/MainViewController.kt @@ -1,4 +1,5 @@ import androidx.compose.ui.window.ComposeUIViewController -import net.agorise.kee.App +import cafe.adriel.voyager.navigator.Navigator +import net.agorise.kee.ui.screen.license.LicenseScreen -fun MainViewController() = ComposeUIViewController { App() } +fun MainViewController() = ComposeUIViewController { Navigator(LicenseScreen()) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 617447b..fd0bbc3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,33 +4,19 @@ android-compileSdk = "34" android-minSdk = "24" android-targetSdk = "34" androidx-activityCompose = "1.8.2" -androidx-appcompat = "1.6.1" -androidx-constraintlayout = "2.1.4" -androidx-core-ktx = "1.12.0" -androidx-espresso-core = "3.5.1" -androidx-material = "1.11.0" -androidx-test-junit = "1.1.5" compose = "1.6.2" compose-plugin = "1.6.0" -junit = "4.13.2" kotlin = "1.9.22" +voyager = "1.0.0" [libraries] -kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } -kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } -junit = { group = "junit", name = "junit", version.ref = "junit" } -androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core-ktx" } -androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" } -androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidx-espresso-core" } -androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" } -androidx-material = { group = "com.google.android.material", name = "material", version.ref = "androidx-material" } -androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } +voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } androidLibrary = { id = "com.android.library", version.ref = "agp" } jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } -kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } \ No newline at end of file +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }