mirror of
https://github.com/BetterAndroid/compose-multiplatform-template.git
synced 2025-09-09 12:04:08 +08:00
Initial commit
This commit is contained in:
1
shared/.gitignore
vendored
Normal file
1
shared/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
83
shared/build.gradle.kts
Normal file
83
shared/build.gradle.kts
Normal file
@@ -0,0 +1,83 @@
|
||||
plugins {
|
||||
autowire(libs.plugins.kotlin.multiplatform)
|
||||
autowire(libs.plugins.android.library)
|
||||
autowire(libs.plugins.jetbrains.compose)
|
||||
}
|
||||
|
||||
group = property.project.groupName
|
||||
|
||||
kotlin {
|
||||
androidTarget()
|
||||
jvm("desktop")
|
||||
listOf(
|
||||
iosX64(),
|
||||
iosArm64(),
|
||||
iosSimulatorArm64(),
|
||||
).forEach { iosTarget ->
|
||||
iosTarget.binaries.framework {
|
||||
baseName = "shared"
|
||||
isStatic = true
|
||||
}
|
||||
}
|
||||
jvmToolchain(17)
|
||||
sourceSets {
|
||||
all {
|
||||
languageSettings {
|
||||
optIn("androidx.compose.material3.ExperimentalMaterial3Api")
|
||||
}
|
||||
}
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(compose.runtime)
|
||||
implementation(compose.foundation)
|
||||
implementation(compose.material3)
|
||||
}
|
||||
}
|
||||
val androidMain by getting {
|
||||
dependencies {
|
||||
api(compose.foundation)
|
||||
api(androidx.core.core.ktx)
|
||||
api(androidx.appcompat.appcompat)
|
||||
api(androidx.activity.activity)
|
||||
api(androidx.activity.activity.compose)
|
||||
}
|
||||
}
|
||||
val desktopMain by getting {
|
||||
dependencies {
|
||||
api(compose.desktop.currentOs)
|
||||
api(compose.runtime)
|
||||
api(compose.foundation)
|
||||
api(compose.material3)
|
||||
}
|
||||
}
|
||||
val iosX64Main by getting
|
||||
val iosArm64Main by getting
|
||||
val iosSimulatorArm64Main by getting
|
||||
val iosMain by creating {
|
||||
dependsOn(commonMain)
|
||||
iosX64Main.dependsOn(this)
|
||||
iosArm64Main.dependsOn(this)
|
||||
iosSimulatorArm64Main.dependsOn(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = property.project.groupName
|
||||
compileSdk = property.project.android.compileSdk
|
||||
|
||||
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
|
||||
|
||||
defaultConfig {
|
||||
minSdk = property.project.android.minSdk
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
4
shared/src/androidMain/kotlin/App.android.kt
Normal file
4
shared/src/androidMain/kotlin/App.android.kt
Normal file
@@ -0,0 +1,4 @@
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun MainView() = App()
|
34
shared/src/commonMain/kotlin/App.kt
Normal file
34
shared/src/commonMain/kotlin/App.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
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
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun App() {
|
||||
MaterialTheme {
|
||||
var greeting by remember { mutableStateOf("Hello world!") }
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = greeting)
|
||||
Spacer(Modifier.padding(15.dp))
|
||||
Button(onClick = { greeting = "Hello Jetpack Compose Multiplatform!" }) {
|
||||
Text(text = "Greeting")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
shared/src/desktopMain/kotlin/App.desktop.kt
Normal file
4
shared/src/desktopMain/kotlin/App.desktop.kt
Normal file
@@ -0,0 +1,4 @@
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun MainView() = App()
|
9
shared/src/iosMain/kotlin/App.ios.kt
Normal file
9
shared/src/iosMain/kotlin/App.ios.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.window.ComposeUIViewController
|
||||
|
||||
fun createUIViewController() = ComposeUIViewController { MainView() }
|
||||
|
||||
@Composable
|
||||
fun MainView() = App()
|
Reference in New Issue
Block a user