kotlin is here #3
@ -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.
|
|
||||||
@ -7,6 +7,8 @@ plugins {
|
|||||||
alias(libs.plugins.composeMultiplatform)
|
alias(libs.plugins.composeMultiplatform)
|
||||||
alias(libs.plugins.composeCompiler)
|
alias(libs.plugins.composeCompiler)
|
||||||
alias(libs.plugins.composeHotReload)
|
alias(libs.plugins.composeHotReload)
|
||||||
|
|
||||||
|
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20"
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
@ -44,6 +46,7 @@ kotlin {
|
|||||||
implementation(compose.components.uiToolingPreview)
|
implementation(compose.components.uiToolingPreview)
|
||||||
implementation(libs.androidx.lifecycle.viewmodel)
|
implementation(libs.androidx.lifecycle.viewmodel)
|
||||||
implementation(libs.androidx.lifecycle.runtimeCompose)
|
implementation(libs.androidx.lifecycle.runtimeCompose)
|
||||||
|
implementation("org.jetbrains.androidx.navigation:navigation-compose:2.9.0-beta03")
|
||||||
}
|
}
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
implementation(libs.kotlin.test)
|
implementation(libs.kotlin.test)
|
||||||
|
|||||||
@ -1,44 +1,18 @@
|
|||||||
package su.sonoma.sclient
|
package su.sonoma.sclient
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.navigation.NavController
|
||||||
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 org.jetbrains.compose.ui.tooling.preview.Preview
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
|
|
||||||
import sclient.composeapp.generated.resources.Res
|
|
||||||
import sclient.composeapp.generated.resources.compose_multiplatform
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
@Preview
|
||||||
fun App() {
|
fun App(
|
||||||
MaterialTheme {
|
onNavHostReady: suspend (NavController) -> Unit = {}
|
||||||
var showContent by remember { mutableStateOf(false) }
|
) {
|
||||||
Column(
|
val navController = Navigation().getNavController()
|
||||||
modifier = Modifier
|
|
||||||
.safeContentPadding()
|
LaunchedEffect(navController) {
|
||||||
.fillMaxSize(),
|
onNavHostReady(navController)
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,9 +0,0 @@
|
|||||||
package su.sonoma.sclient
|
|
||||||
|
|
||||||
class Greeting {
|
|
||||||
private val platform = getPlatform()
|
|
||||||
|
|
||||||
fun greet(): String {
|
|
||||||
return "Hello, ${platform.name}!"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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<Login> { LoginScreen() }
|
||||||
|
}
|
||||||
|
|
||||||
|
return navController
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +0,0 @@
|
|||||||
package su.sonoma.sclient
|
|
||||||
|
|
||||||
interface Platform {
|
|
||||||
val name: String
|
|
||||||
}
|
|
||||||
|
|
||||||
expect fun getPlatform(): Platform
|
|
||||||
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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()
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
package su.sonoma.sclient
|
|
||||||
|
|
||||||
class WasmPlatform: Platform {
|
|
||||||
override val name: String = "Web with Kotlin/Wasm"
|
|
||||||
}
|
|
||||||
|
|
||||||
actual fun getPlatform(): Platform = WasmPlatform()
|
|
||||||
Reference in New Issue
Block a user