mirror of
https://github.com/BetterAndroid/compose-multiplatform-template.git
synced 2025-09-06 10:45:49 +08:00
refactor: merge to BetterAndroid
This commit is contained in:
@@ -2,10 +2,10 @@ package __GROUP_NAME__
|
|||||||
|
|
||||||
import MainView
|
import MainView
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
|
import com.highcapable.betterandroid.ui.component.activity.AppComponentActivity
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : AppComponentActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@@ -4,6 +4,7 @@ android.useAndroidX=true
|
|||||||
android.nonTransitiveRClass=true
|
android.nonTransitiveRClass=true
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin.incremental.useClasspathSnapshot=true
|
kotlin.incremental.useClasspathSnapshot=true
|
||||||
|
kotlin.mpp.applyDefaultHierarchyTemplate=false
|
||||||
org.jetbrains.compose.experimental.uikit.enabled=true
|
org.jetbrains.compose.experimental.uikit.enabled=true
|
||||||
# Project Configuration
|
# Project Configuration
|
||||||
project.name=__PROJECT_NAME__
|
project.name=__PROJECT_NAME__
|
||||||
|
@@ -27,6 +27,17 @@ plugins:
|
|||||||
version-ref: android-application
|
version-ref: android-application
|
||||||
|
|
||||||
libraries:
|
libraries:
|
||||||
|
com.highcapable.betterandroid:
|
||||||
|
ui-component:
|
||||||
|
version: +
|
||||||
|
ui-extension:
|
||||||
|
version: +
|
||||||
|
system-extension:
|
||||||
|
version: +
|
||||||
|
compose-extension:
|
||||||
|
version: +
|
||||||
|
compose-multiplatform:
|
||||||
|
version: +
|
||||||
androidx.activity:
|
androidx.activity:
|
||||||
activity:
|
activity:
|
||||||
version: +
|
version: +
|
||||||
|
@@ -9,16 +9,14 @@
|
|||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
|
058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
|
||||||
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
|
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
|
||||||
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
|
508B32322B43A12E0061B326 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508B32312B43A12E0061B326 /* AppDelegate.swift */; };
|
||||||
7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
|
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||||
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
|
508B32312B43A12E0061B326 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
7555FF7B242A565900829871 /* My application.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "My application.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
7555FF7B242A565900829871 /* My application.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = "My application.app"; path = "compose-multiplatform-demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
|
||||||
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
@@ -71,10 +69,9 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
058557BA273AAA24004C7B11 /* Assets.xcassets */,
|
058557BA273AAA24004C7B11 /* Assets.xcassets */,
|
||||||
7555FF82242A565900829871 /* ContentView.swift */,
|
|
||||||
7555FF8C242A565B00829871 /* Info.plist */,
|
7555FF8C242A565B00829871 /* Info.plist */,
|
||||||
2152FB032600AC8F00CF470E /* iOSApp.swift */,
|
|
||||||
058557D7273AAEEB004C7B11 /* Preview Content */,
|
058557D7273AAEEB004C7B11 /* Preview Content */,
|
||||||
|
508B32312B43A12E0061B326 /* AppDelegate.swift */,
|
||||||
);
|
);
|
||||||
path = iosApp;
|
path = iosApp;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -179,8 +176,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
|
508B32322B43A12E0061B326 /* AppDelegate.swift in Sources */,
|
||||||
7555FF83242A565900829871 /* ContentView.swift in Sources */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
15
iosApp/iosApp/AppDelegate.swift
Normal file
15
iosApp/iosApp/AppDelegate.swift
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import UIKit
|
||||||
|
import shared
|
||||||
|
|
||||||
|
@UIApplicationMain
|
||||||
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
|
||||||
|
var window: UIWindow?
|
||||||
|
|
||||||
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
|
window = UIWindow(frame: UIScreen.main.bounds)
|
||||||
|
window?.rootViewController = App_iosKt.createUIViewController()
|
||||||
|
window?.makeKeyAndVisible()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
@@ -1,19 +0,0 @@
|
|||||||
import UIKit
|
|
||||||
import SwiftUI
|
|
||||||
import shared
|
|
||||||
|
|
||||||
struct ComposeView: UIViewControllerRepresentable {
|
|
||||||
func makeUIViewController(context: Context) -> UIViewController {
|
|
||||||
let viewController = App_iosKt.createUIViewController()
|
|
||||||
return viewController
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ContentView: View {
|
|
||||||
var body: some View {
|
|
||||||
ComposeView()
|
|
||||||
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct iOSApp: App {
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup {
|
|
||||||
ContentView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -31,6 +31,8 @@ kotlin {
|
|||||||
implementation(compose.runtime)
|
implementation(compose.runtime)
|
||||||
implementation(compose.foundation)
|
implementation(compose.foundation)
|
||||||
implementation(compose.material3)
|
implementation(compose.material3)
|
||||||
|
implementation(com.highcapable.betterandroid.compose.extension)
|
||||||
|
implementation(com.highcapable.betterandroid.compose.multiplatform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val androidMain by getting {
|
val androidMain by getting {
|
||||||
@@ -39,6 +41,9 @@ kotlin {
|
|||||||
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)
|
||||||
|
api(com.highcapable.betterandroid.ui.component)
|
||||||
|
api(com.highcapable.betterandroid.ui.extension)
|
||||||
|
api(com.highcapable.betterandroid.system.extension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val desktopMain by getting {
|
val desktopMain by getting {
|
||||||
|
@@ -1,34 +1,64 @@
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
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.Button
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
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.PlatformSystemBars
|
||||||
|
import com.highcapable.betterandroid.compose.multiplatform.systembar.rememberSystemBarsController
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun App() {
|
fun App() {
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
|
val systemBars = rememberSystemBarsController()
|
||||||
|
var hideOrShowBars by remember { mutableStateOf(false) }
|
||||||
var greeting by remember { mutableStateOf("Hello world!") }
|
var greeting by remember { mutableStateOf("Hello world!") }
|
||||||
Column(
|
Column(modifier = Modifier.safeDrawingPadding()) {
|
||||||
modifier = Modifier.fillMaxSize(),
|
Row(
|
||||||
verticalArrangement = Arrangement.Center,
|
modifier = Modifier.padding(15.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(text = greeting)
|
Text(
|
||||||
Spacer(Modifier.padding(15.dp))
|
text = "__APP_NAME__",
|
||||||
Button(onClick = { greeting = "Hello Jetpack Compose Multiplatform!" }) {
|
fontSize = 20.sp,
|
||||||
Text(text = "Greeting")
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,9 +1,9 @@
|
|||||||
@file:Suppress("unused")
|
@file:Suppress("unused")
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
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
|
@Composable
|
||||||
fun MainView() = App()
|
fun MainView() = App()
|
Reference in New Issue
Block a user