From e83535e8711f5778cb688c262284861a76c7c69e Mon Sep 17 00:00:00 2001 From: saddydead1 Date: Sat, 19 Jul 2025 02:22:26 +0300 Subject: [PATCH] loginscreen --- client/README.md | 18 ------- client/composeApp/build.gradle.kts | 3 ++ .../kotlin/su/sonoma/sclient/App.kt | 46 ++++------------- .../kotlin/su/sonoma/sclient/Greeting.kt | 9 ---- .../kotlin/su/sonoma/sclient/Navigation.kt | 26 ++++++++++ .../kotlin/su/sonoma/sclient/Platform.kt | 7 --- .../su/sonoma/sclient/screen/LoginScreen.kt | 50 +++++++++++++++++++ .../kotlin/su/sonoma/sclient/Platform.jvm.kt | 7 --- .../su/sonoma/sclient/Platform.wasmJs.kt | 7 --- 9 files changed, 89 insertions(+), 84 deletions(-) delete mode 100644 client/README.md delete mode 100644 client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Greeting.kt create mode 100644 client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Navigation.kt delete mode 100644 client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Platform.kt create mode 100644 client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/screen/LoginScreen.kt delete mode 100644 client/composeApp/src/desktopMain/kotlin/su/sonoma/sclient/Platform.jvm.kt delete mode 100644 client/composeApp/src/wasmJsMain/kotlin/su/sonoma/sclient/Platform.wasmJs.kt diff --git a/client/README.md b/client/README.md deleted file mode 100644 index 904c0f1..0000000 --- a/client/README.md +++ /dev/null @@ -1,18 +0,0 @@ -This is a Kotlin Multiplatform project targeting Web, Desktop. - -* `/composeApp` is for code that will be shared across your Compose Multiplatform applications. - It contains several subfolders: - - `commonMain` is for code that’s common for all targets. - - Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name. - For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app, - `iosMain` would be the right folder for such calls. - - -Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html), -[Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform/#compose-multiplatform), -[Kotlin/Wasm](https://kotl.in/wasm/)… - -We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web). -If you face any issues, please report them on [YouTrack](https://youtrack.jetbrains.com/newIssue?project=CMP). - -You can open the web application by running the `:composeApp:wasmJsBrowserDevelopmentRun` Gradle task. \ No newline at end of file diff --git a/client/composeApp/build.gradle.kts b/client/composeApp/build.gradle.kts index c4e7de2..343434f 100644 --- a/client/composeApp/build.gradle.kts +++ b/client/composeApp/build.gradle.kts @@ -7,6 +7,8 @@ plugins { alias(libs.plugins.composeMultiplatform) alias(libs.plugins.composeCompiler) alias(libs.plugins.composeHotReload) + + id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20" } kotlin { @@ -44,6 +46,7 @@ kotlin { implementation(compose.components.uiToolingPreview) implementation(libs.androidx.lifecycle.viewmodel) implementation(libs.androidx.lifecycle.runtimeCompose) + implementation("org.jetbrains.androidx.navigation:navigation-compose:2.9.0-beta03") } commonTest.dependencies { implementation(libs.kotlin.test) diff --git a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/App.kt b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/App.kt index ae61484..74ef0a8 100644 --- a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/App.kt +++ b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/App.kt @@ -1,44 +1,18 @@ package su.sonoma.sclient -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.safeContentPadding -import androidx.compose.material3.Button -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import org.jetbrains.compose.resources.painterResource +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.navigation.NavController import org.jetbrains.compose.ui.tooling.preview.Preview -import sclient.composeapp.generated.resources.Res -import sclient.composeapp.generated.resources.compose_multiplatform - @Composable @Preview -fun App() { - MaterialTheme { - var showContent by remember { mutableStateOf(false) } - Column( - modifier = Modifier - .safeContentPadding() - .fillMaxSize(), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - Button(onClick = { showContent = !showContent }) { - Text("Click me!") - } - AnimatedVisibility(showContent) { - val greeting = remember { Greeting().greet() } - Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { - Image(painterResource(Res.drawable.compose_multiplatform), null) - Text("Compose: $greeting") - } - } - } +fun App( + onNavHostReady: suspend (NavController) -> Unit = {} +) { + val navController = Navigation().getNavController() + + LaunchedEffect(navController) { + onNavHostReady(navController) } } \ No newline at end of file diff --git a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Greeting.kt b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Greeting.kt deleted file mode 100644 index 0841051..0000000 --- a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Greeting.kt +++ /dev/null @@ -1,9 +0,0 @@ -package su.sonoma.sclient - -class Greeting { - private val platform = getPlatform() - - fun greet(): String { - return "Hello, ${platform.name}!" - } -} \ No newline at end of file diff --git a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Navigation.kt b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Navigation.kt new file mode 100644 index 0000000..9b9ba66 --- /dev/null +++ b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Navigation.kt @@ -0,0 +1,26 @@ +package su.sonoma.sclient + +import androidx.compose.runtime.Composable +import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.rememberNavController +import kotlinx.serialization.Serializable +import su.sonoma.sclient.screen.LoginScreen + +@Serializable +class Navigation { + @Serializable + object Login + + @Composable + fun getNavController(): NavHostController { + val navController = rememberNavController() + + NavHost(navController = navController, startDestination = Login) { + composable { LoginScreen() } + } + + return navController + } +} \ No newline at end of file diff --git a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Platform.kt b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Platform.kt deleted file mode 100644 index 400279f..0000000 --- a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/Platform.kt +++ /dev/null @@ -1,7 +0,0 @@ -package su.sonoma.sclient - -interface Platform { - val name: String -} - -expect fun getPlatform(): Platform \ No newline at end of file diff --git a/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/screen/LoginScreen.kt b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/screen/LoginScreen.kt new file mode 100644 index 0000000..58c5fb4 --- /dev/null +++ b/client/composeApp/src/commonMain/kotlin/su/sonoma/sclient/screen/LoginScreen.kt @@ -0,0 +1,50 @@ +package su.sonoma.sclient.screen + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.safeContentPadding +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextField +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier + + +@Composable +fun LoginScreen() { + MaterialTheme { + Column( + modifier = Modifier + .safeContentPadding() + .fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + var login by remember { mutableStateOf("") } + var password by remember { mutableStateOf("") } + + TextField( + value = login, + onValueChange = { login = it}, + label = { Text("Login") } + ) + + TextField( + value = password, + onValueChange = { password = it }, + label = { Text("Password") } + ) + + Button( + onClick = { print("$login, $password") } + ) { + Text("Login") + } + } + } +} \ No newline at end of file diff --git a/client/composeApp/src/desktopMain/kotlin/su/sonoma/sclient/Platform.jvm.kt b/client/composeApp/src/desktopMain/kotlin/su/sonoma/sclient/Platform.jvm.kt deleted file mode 100644 index 91783c4..0000000 --- a/client/composeApp/src/desktopMain/kotlin/su/sonoma/sclient/Platform.jvm.kt +++ /dev/null @@ -1,7 +0,0 @@ -package su.sonoma.sclient - -class JVMPlatform: Platform { - override val name: String = "Java ${System.getProperty("java.version")}" -} - -actual fun getPlatform(): Platform = JVMPlatform() \ No newline at end of file diff --git a/client/composeApp/src/wasmJsMain/kotlin/su/sonoma/sclient/Platform.wasmJs.kt b/client/composeApp/src/wasmJsMain/kotlin/su/sonoma/sclient/Platform.wasmJs.kt deleted file mode 100644 index e877591..0000000 --- a/client/composeApp/src/wasmJsMain/kotlin/su/sonoma/sclient/Platform.wasmJs.kt +++ /dev/null @@ -1,7 +0,0 @@ -package su.sonoma.sclient - -class WasmPlatform: Platform { - override val name: String = "Web with Kotlin/Wasm" -} - -actual fun getPlatform(): Platform = WasmPlatform() \ No newline at end of file