refactor: merge to BetterAndroid

This commit is contained in:
2024-01-02 10:30:02 +08:00
parent 0304cab259
commit b8db594dae
10 changed files with 80 additions and 51 deletions

View File

@@ -31,6 +31,8 @@ kotlin {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(com.highcapable.betterandroid.compose.extension)
implementation(com.highcapable.betterandroid.compose.multiplatform)
}
}
val androidMain by getting {
@@ -39,6 +41,9 @@ kotlin {
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 {

View File

@@ -1,34 +1,64 @@
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
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.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.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.highcapable.betterandroid.compose.multiplatform.systembar.PlatformSystemBars
import com.highcapable.betterandroid.compose.multiplatform.systembar.rememberSystemBarsController
@Composable
fun App() {
MaterialTheme {
val systemBars = rememberSystemBarsController()
var hideOrShowBars by remember { mutableStateOf(false) }
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")
Column(modifier = Modifier.safeDrawingPadding()) {
Row(
modifier = Modifier.padding(15.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "__APP_NAME__",
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
}
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")
}
Spacer(Modifier.padding(15.dp))
Button(onClick = { hideOrShowBars = !hideOrShowBars }) {
Text(text = "Trigger SystemBars")
}
}
}
LaunchedEffect(hideOrShowBars) {
if (hideOrShowBars)
systemBars.hide(PlatformSystemBars.All)
else systemBars.show(PlatformSystemBars.All)
}
}
}

View File

@@ -1,9 +1,9 @@
@file:Suppress("unused")
import androidx.compose.runtime.Composable
import androidx.compose.ui.window.ComposeUIViewController
import com.highcapable.betterandroid.compose.multiplatform.platform.AppComponentUIViewController
fun createUIViewController() = ComposeUIViewController { MainView() }
fun createUIViewController() = AppComponentUIViewController { MainView() }
@Composable
fun MainView() = App()