mirror of
https://github.com/BetterAndroid/compose-multiplatform-template.git
synced 2025-09-05 02:05:32 +08:00
refactor: merge to Flexi UI and new usage
This commit is contained in:
@@ -9,12 +9,10 @@
|
|||||||
|
|
||||||
一个快速生成 Android、iOS、Desktop (JVM) 的 Jetpack Compose 多平台项目模版。
|
一个快速生成 Android、iOS、Desktop (JVM) 的 Jetpack Compose 多平台项目模版。
|
||||||
|
|
||||||
<img width="1767" alt="SHOT" src="img-src/shot.png">
|
|
||||||
|
|
||||||
[English](README.md) | 简体中文
|
[English](README.md) | 简体中文
|
||||||
|
|
||||||
| <img src="https://github.com/BetterAndroid/.github/blob/main/img-src/logo.png?raw=true" width = "30" height = "30" alt="LOGO"/> | [BetterAndroid](https://github.com/BetterAndroid) |
|
| <img src="https://github.com/BetterAndroid/.github/blob/main/img-src/logo.png?raw=true" width = "30" height = "30" alt="LOGO"/> | [BetterAndroid](https://github.com/BetterAndroid) |
|
||||||
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
|
| ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
|
||||||
|
|
||||||
这个项目属于上述组织,**点击上方链接关注这个组织**,发现更多好项目。
|
这个项目属于上述组织,**点击上方链接关注这个组织**,发现更多好项目。
|
||||||
|
|
||||||
@@ -22,8 +20,9 @@
|
|||||||
|
|
||||||
这是一个快速生成 Android、iOS、Desktop (JVM) 的 Jetpack Compose 多平台项目模版。
|
这是一个快速生成 Android、iOS、Desktop (JVM) 的 Jetpack Compose 多平台项目模版。
|
||||||
|
|
||||||
Jetpack Compose 的跨平台能力为 Android 开发者将应用程序部署到多个平台提供了可能,这份模版修改自官方提供的 [compose-multiplatform-ios-android-template](https://github.com/JetBrains/compose-multiplatform-ios-android-template),
|
Jetpack Compose 的跨平台能力为 Android 开发者将应用程序部署到多个平台提供了可能,这份模版修改自官方提供的 [Kotlin Multiplatform Wizard](https://kmp.jetbrains.com/)。
|
||||||
它改进了项目结构并支持了桌面端 (JVM) 的跨平台能力。
|
|
||||||
|
这份模版集成了 [Flexi UI](https://github.com/BetterAndroid/FlexiUI) 和 [BetterAndroid](https://github.com/BetterAndroid/BetterAndroid),为多平台提供了更好的原生体验。
|
||||||
|
|
||||||
## 开始使用
|
## 开始使用
|
||||||
|
|
||||||
|
@@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
A Jetpack Compose Multiplatform project template that quickly generates Android, iOS, and Desktop (JVM).
|
A Jetpack Compose Multiplatform project template that quickly generates Android, iOS, and Desktop (JVM).
|
||||||
|
|
||||||
<img width="1767" alt="SHOT" src="img-src/shot.png">
|
|
||||||
|
|
||||||
English | [简体中文](README-zh-CN.md)
|
English | [简体中文](README-zh-CN.md)
|
||||||
|
|
||||||
| <img src="https://github.com/BetterAndroid/.github/blob/main/img-src/logo.png?raw=true" width = "30" height = "30" alt="LOGO"/> | [BetterAndroid](https://github.com/BetterAndroid) |
|
| <img src="https://github.com/BetterAndroid/.github/blob/main/img-src/logo.png?raw=true" width = "30" height = "30" alt="LOGO"/> | [BetterAndroid](https://github.com/BetterAndroid) |
|
||||||
@@ -24,8 +22,9 @@ This is a Jetpack Compose Multiplatform project template that quickly generates
|
|||||||
|
|
||||||
The cross-platform capability of Jetpack Compose provides Android developers with the possibility to deploy applications to multiple platforms.
|
The cross-platform capability of Jetpack Compose provides Android developers with the possibility to deploy applications to multiple platforms.
|
||||||
|
|
||||||
This template is modified from the official [compose-multiplatform-ios-android-template](https://github.com/JetBrains/compose-multiplatform-ios-android-template),
|
This template is modified from the official [Kotlin Multiplatform Wizard](https://kmp.jetbrains.com/).
|
||||||
it improves project structure and supports cross-platform capabilities on the desktop (JVM).
|
|
||||||
|
This template integrates [Flexi UI](https://github.com/BetterAndroid/FlexiUI) and [BetterAndroid](https://github.com/BetterAndroid/BetterAndroid) to provide a better native experience for multi-platforms.
|
||||||
|
|
||||||
## Get Started
|
## Get Started
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package __GROUP_NAME__
|
package __GROUP_NAME__
|
||||||
|
|
||||||
import MainView
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import com.highcapable.betterandroid.ui.component.activity.AppComponentActivity
|
import com.highcapable.betterandroid.ui.component.activity.AppComponentActivity
|
||||||
@@ -9,6 +8,6 @@ class MainActivity : AppComponentActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContent { MainView() }
|
setContent { App() }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -24,6 +24,6 @@ java {
|
|||||||
|
|
||||||
compose.desktop {
|
compose.desktop {
|
||||||
application {
|
application {
|
||||||
mainClass = "MainKt"
|
mainClass = "$group.MainKt"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,3 +1,5 @@
|
|||||||
|
package __GROUP_NAME__
|
||||||
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Window
|
import androidx.compose.ui.window.Window
|
||||||
import androidx.compose.ui.window.application
|
import androidx.compose.ui.window.application
|
||||||
@@ -8,5 +10,5 @@ fun main() = application {
|
|||||||
onCloseRequest = ::exitApplication,
|
onCloseRequest = ::exitApplication,
|
||||||
title = "__APP_NAME__",
|
title = "__APP_NAME__",
|
||||||
state = rememberWindowState(width = 550.dp, height = 450.dp)
|
state = rememberWindowState(width = 550.dp, height = 450.dp)
|
||||||
) { MainView() }
|
) { App() }
|
||||||
}
|
}
|
@@ -13,10 +13,12 @@ repositories:
|
|||||||
plugins:
|
plugins:
|
||||||
org.jetbrains.kotlin.multiplatform:
|
org.jetbrains.kotlin.multiplatform:
|
||||||
alias: kotlin-multiplatform
|
alias: kotlin-multiplatform
|
||||||
version: +
|
# Manually update this version visit https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html
|
||||||
|
version: 1.9.21
|
||||||
org.jetbrains.compose:
|
org.jetbrains.compose:
|
||||||
alias: jetbrains-compose
|
alias: jetbrains-compose
|
||||||
version: +
|
# Manually update this version visit https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html
|
||||||
|
version: 1.5.11
|
||||||
repositories:
|
repositories:
|
||||||
maven-central
|
maven-central
|
||||||
com.android.application:
|
com.android.application:
|
||||||
@@ -27,6 +29,12 @@ plugins:
|
|||||||
version-ref: android-application
|
version-ref: android-application
|
||||||
|
|
||||||
libraries:
|
libraries:
|
||||||
|
com.highcapable.flexiui:
|
||||||
|
core:
|
||||||
|
version: +
|
||||||
|
# Flexi UI is in alpha stage for now.
|
||||||
|
version-filter:
|
||||||
|
use-internal: false
|
||||||
com.highcapable.betterandroid:
|
com.highcapable.betterandroid:
|
||||||
ui-component:
|
ui-component:
|
||||||
version: +
|
version: +
|
||||||
@@ -46,9 +54,6 @@ libraries:
|
|||||||
androidx.core:
|
androidx.core:
|
||||||
core-ktx:
|
core-ktx:
|
||||||
version: +
|
version: +
|
||||||
com.google.android.material:
|
|
||||||
material:
|
|
||||||
version: +
|
|
||||||
androidx.test.ext:
|
androidx.test.ext:
|
||||||
junit:
|
junit:
|
||||||
version: +
|
version: +
|
||||||
|
@@ -8,8 +8,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
window = UIWindow(frame: UIScreen.main.bounds)
|
window = UIWindow(frame: UIScreen.main.bounds)
|
||||||
window?.rootViewController = App_iosKt.createUIViewController()
|
window?.rootViewController = MainViewControllerKt.createMainViewController()
|
||||||
window?.makeKeyAndVisible()
|
window?.makeKeyAndVisible()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,8 +4,6 @@ plugins {
|
|||||||
autowire(libs.plugins.jetbrains.compose)
|
autowire(libs.plugins.jetbrains.compose)
|
||||||
}
|
}
|
||||||
|
|
||||||
group = property.project.groupName
|
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
androidTarget()
|
androidTarget()
|
||||||
jvm("desktop")
|
jvm("desktop")
|
||||||
@@ -21,23 +19,17 @@ kotlin {
|
|||||||
}
|
}
|
||||||
jvmToolchain(17)
|
jvmToolchain(17)
|
||||||
sourceSets {
|
sourceSets {
|
||||||
all {
|
|
||||||
languageSettings {
|
|
||||||
optIn("androidx.compose.material3.ExperimentalMaterial3Api")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(compose.runtime)
|
implementation(compose.runtime)
|
||||||
implementation(compose.foundation)
|
implementation(compose.foundation)
|
||||||
implementation(compose.material3)
|
api(com.highcapable.flexiui.core)
|
||||||
implementation(com.highcapable.betterandroid.compose.extension)
|
api(com.highcapable.betterandroid.compose.extension)
|
||||||
implementation(com.highcapable.betterandroid.compose.multiplatform)
|
api(com.highcapable.betterandroid.compose.multiplatform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val androidMain by getting {
|
val androidMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
api(compose.foundation)
|
|
||||||
api(androidx.core.core.ktx)
|
api(androidx.core.core.ktx)
|
||||||
api(androidx.activity.activity)
|
api(androidx.activity.activity)
|
||||||
api(androidx.activity.activity.compose)
|
api(androidx.activity.activity.compose)
|
||||||
@@ -49,9 +41,6 @@ kotlin {
|
|||||||
val desktopMain by getting {
|
val desktopMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
api(compose.desktop.currentOs)
|
api(compose.desktop.currentOs)
|
||||||
api(compose.runtime)
|
|
||||||
api(compose.foundation)
|
|
||||||
api(compose.material3)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val iosX64Main by getting
|
val iosX64Main by getting
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
import androidx.compose.runtime.Composable
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MainView() = App()
|
|
@@ -1,13 +1,10 @@
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
package __GROUP_NAME__
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@@ -16,44 +13,70 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import com.highcapable.betterandroid.compose.multiplatform.systembar.PlatformSystemBarStyle
|
||||||
import com.highcapable.betterandroid.compose.multiplatform.systembar.PlatformSystemBars
|
import com.highcapable.betterandroid.compose.multiplatform.systembar.PlatformSystemBars
|
||||||
import com.highcapable.betterandroid.compose.multiplatform.systembar.rememberSystemBarsController
|
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
|
@Composable
|
||||||
fun App() {
|
fun App() {
|
||||||
MaterialTheme {
|
MyApplicationTheme {
|
||||||
|
MainScreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MainScreen() {
|
||||||
|
Scaffold(
|
||||||
|
appBar = {
|
||||||
|
PrimaryAppBar(
|
||||||
|
title = { Text("__APP_NAME__") }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { innerPadding ->
|
||||||
val systemBars = rememberSystemBarsController()
|
val systemBars = rememberSystemBarsController()
|
||||||
var hideOrShowBars by remember { mutableStateOf(false) }
|
var hideOrShowBars by remember { mutableStateOf(false) }
|
||||||
var greeting by remember { mutableStateOf("Hello world!") }
|
var greeting by remember { mutableStateOf("Hello World!") }
|
||||||
Column(modifier = Modifier.safeDrawingPadding()) {
|
AreaColumn(
|
||||||
Row(
|
modifier = Modifier.fillMaxWidth().padding(innerPadding),
|
||||||
modifier = Modifier.padding(15.dp),
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
verticalAlignment = Alignment.CenterVertically
|
) {
|
||||||
) {
|
Text(text = greeting)
|
||||||
Text(
|
NecessarySpacer()
|
||||||
text = "__APP_NAME__",
|
Button(
|
||||||
fontSize = 20.sp,
|
onClick = { greeting = "Hello Jetpack Compose Multiplatform!" }
|
||||||
fontWeight = FontWeight.Bold
|
) { Text(text = "Greeting") }
|
||||||
)
|
NecessarySpacer()
|
||||||
}
|
Button(
|
||||||
Column(
|
onClick = { hideOrShowBars = !hideOrShowBars }
|
||||||
modifier = Modifier.fillMaxSize(),
|
) { Text(text = "Trigger SystemBars") }
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
Text(text = greeting)
|
|
||||||
Spacer(Modifier.padding(15.dp))
|
|
||||||
Button(onClick = { greeting = "Hello Jetpack Compose Multiplatform!" }) {
|
|
||||||
Text(text = "Greeting")
|
|
||||||
}
|
|
||||||
Spacer(Modifier.padding(15.dp))
|
|
||||||
Button(onClick = { hideOrShowBars = !hideOrShowBars }) {
|
|
||||||
Text(text = "Trigger SystemBars")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LaunchedEffect(hideOrShowBars) {
|
LaunchedEffect(hideOrShowBars) {
|
||||||
if (hideOrShowBars)
|
if (hideOrShowBars)
|
||||||
@@ -61,4 +84,9 @@ fun App() {
|
|||||||
else systemBars.show(PlatformSystemBars.All)
|
else systemBars.show(PlatformSystemBars.All)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun NecessarySpacer() {
|
||||||
|
Spacer(Modifier.height(20.dp))
|
||||||
}
|
}
|
@@ -1,4 +0,0 @@
|
|||||||
import androidx.compose.runtime.Composable
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MainView() = App()
|
|
@@ -1,9 +0,0 @@
|
|||||||
@file:Suppress("unused")
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import com.highcapable.betterandroid.compose.multiplatform.platform.AppComponentUIViewController
|
|
||||||
|
|
||||||
fun createUIViewController() = AppComponentUIViewController { MainView() }
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MainView() = App()
|
|
6
shared/src/iosMain/kotlin/MainViewController.kt
Normal file
6
shared/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