mirror of
https://github.com/BetterAndroid/compose-multiplatform-template.git
synced 2025-09-05 10:15:24 +08:00
refactor: merge shared to composeApp
This commit is contained in:
78
composeApp/build.gradle.kts
Normal file
78
composeApp/build.gradle.kts
Normal file
@@ -0,0 +1,78 @@
|
||||
plugins {
|
||||
autowire(libs.plugins.kotlin.multiplatform)
|
||||
autowire(libs.plugins.android.library)
|
||||
autowire(libs.plugins.jetbrains.compose)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
androidTarget()
|
||||
jvm("desktop")
|
||||
listOf(
|
||||
iosX64(),
|
||||
iosArm64(),
|
||||
iosSimulatorArm64()
|
||||
).forEach { iosTarget ->
|
||||
iosTarget.binaries.framework {
|
||||
baseName = "ComposeApp"
|
||||
isStatic = true
|
||||
}
|
||||
}
|
||||
jvmToolchain(17)
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(compose.runtime)
|
||||
implementation(compose.foundation)
|
||||
api(com.highcapable.flexiui.core)
|
||||
api(com.highcapable.betterandroid.compose.extension)
|
||||
api(com.highcapable.betterandroid.compose.multiplatform)
|
||||
}
|
||||
}
|
||||
val androidMain by getting {
|
||||
dependencies {
|
||||
api(androidx.core.core.ktx)
|
||||
api(androidx.activity.activity)
|
||||
api(androidx.activity.activity.compose)
|
||||
api(com.highcapable.betterandroid.ui.component)
|
||||
api(com.highcapable.betterandroid.ui.extension)
|
||||
api(com.highcapable.betterandroid.system.extension)
|
||||
}
|
||||
}
|
||||
val desktopMain by getting {
|
||||
dependencies {
|
||||
api(compose.desktop.currentOs)
|
||||
}
|
||||
}
|
||||
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")
|
||||
sourceSets["main"].res.srcDirs("src/androidMain/res")
|
||||
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
|
||||
|
||||
defaultConfig {
|
||||
minSdk = property.project.android.minSdk
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
92
composeApp/src/commonMain/kotlin/App.kt
Normal file
92
composeApp/src/commonMain/kotlin/App.kt
Normal file
@@ -0,0 +1,92 @@
|
||||
package __GROUP_NAME__
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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
|
||||
import com.highcapable.betterandroid.compose.multiplatform.systembar.PlatformSystemBarStyle
|
||||
import com.highcapable.betterandroid.compose.multiplatform.systembar.PlatformSystemBars
|
||||
import com.highcapable.betterandroid.compose.multiplatform.systembar.rememberSystemBarsController
|
||||
import com.highcapable.betterandroid.compose.multiplatform.systembar.setStyle
|
||||
import com.highcapable.flexiui.FlexiTheme
|
||||
import com.highcapable.flexiui.component.AreaColumn
|
||||
import com.highcapable.flexiui.component.Button
|
||||
import com.highcapable.flexiui.component.PrimaryAppBar
|
||||
import com.highcapable.flexiui.component.Scaffold
|
||||
import com.highcapable.flexiui.component.Text
|
||||
import com.highcapable.flexiui.defaultColors
|
||||
|
||||
@Composable
|
||||
private fun MyApplicationTheme(content: @Composable () -> Unit) {
|
||||
val systemBars = rememberSystemBarsController()
|
||||
val currentDarkMode = isSystemInDarkTheme()
|
||||
val colorScheme = defaultColors(currentDarkMode)
|
||||
systemBars.setStyle(
|
||||
if (currentDarkMode)
|
||||
PlatformSystemBarStyle.DarkTransparent
|
||||
else PlatformSystemBarStyle.LightTransparent
|
||||
)
|
||||
// Customize Flexi UI theme styles.
|
||||
FlexiTheme(
|
||||
colors = colorScheme,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
// Generated by https://github.com/BetterAndroid/compose-multiplatform-template
|
||||
// You can visit https://github.com/BetterAndroid/FlexiUI to learn how to use Flexi UI.
|
||||
@Composable
|
||||
fun App() {
|
||||
MyApplicationTheme {
|
||||
MainScreen()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainScreen() {
|
||||
Scaffold(
|
||||
appBar = {
|
||||
PrimaryAppBar(
|
||||
title = { Text("__APP_NAME__") }
|
||||
)
|
||||
}
|
||||
) { innerPadding ->
|
||||
val systemBars = rememberSystemBarsController()
|
||||
var hideOrShowBars by remember { mutableStateOf(false) }
|
||||
var greeting by remember { mutableStateOf("Hello World!") }
|
||||
AreaColumn(
|
||||
modifier = Modifier.fillMaxWidth().padding(innerPadding),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = greeting)
|
||||
NecessarySpacer()
|
||||
Button(
|
||||
onClick = { greeting = "Hello Jetpack Compose Multiplatform!" }
|
||||
) { Text(text = "Greeting") }
|
||||
NecessarySpacer()
|
||||
Button(
|
||||
onClick = { hideOrShowBars = !hideOrShowBars }
|
||||
) { Text(text = "Trigger SystemBars") }
|
||||
}
|
||||
LaunchedEffect(hideOrShowBars) {
|
||||
if (hideOrShowBars)
|
||||
systemBars.hide(PlatformSystemBars.All)
|
||||
else systemBars.show(PlatformSystemBars.All)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NecessarySpacer() {
|
||||
Spacer(Modifier.height(20.dp))
|
||||
}
|
6
composeApp/src/iosMain/kotlin/MainViewController.kt
Normal file
6
composeApp/src/iosMain/kotlin/MainViewController.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import __GROUP_NAME__.App
|
||||
import com.highcapable.betterandroid.compose.multiplatform.platform.AppComponentUIViewController
|
||||
|
||||
fun createMainViewController() = AppComponentUIViewController { App() }
|
Reference in New Issue
Block a user