diff --git a/Android/app/src/main/kotlin/hello/skip/Main.kt b/Android/app/src/main/kotlin/hello/skip/Main.kt index 71eb6d4..2e872dc 100644 --- a/Android/app/src/main/kotlin/hello/skip/Main.kt +++ b/Android/app/src/main/kotlin/hello/skip/Main.kt @@ -5,14 +5,6 @@ import skip.model.* import skip.foundation.* import skip.ui.* -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.Saver -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue - import android.Manifest import android.app.Application import androidx.activity.compose.setContent @@ -20,15 +12,10 @@ import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.Box -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.darkColorScheme -import androidx.compose.material3.dynamicDarkColorScheme -import androidx.compose.material3.dynamicLightColorScheme -import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable import androidx.compose.runtime.saveable.rememberSaveableStateHolder import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext import androidx.core.app.ActivityCompat internal val logger: SkipLogger = SkipLogger(subsystem = "hello.skip", category = "HelloSkip") @@ -59,7 +46,7 @@ open class MainActivity: AppCompatActivity { setContent { val saveableStateHolder = rememberSaveableStateHolder() saveableStateHolder.SaveableStateProvider(true) { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { MaterialThemedRootView() } + PresentationRootView(ComposeContext()) } } @@ -123,14 +110,12 @@ open class MainActivity: AppCompatActivity { } @Composable -internal fun MaterialThemedRootView() { - val context = LocalContext.current.sref() - val darkMode = isSystemInDarkTheme() - // Dynamic color is available on Android 12+ - val dynamicColor = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S - - val colorScheme = if (dynamicColor) (if (darkMode) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)) else (if (darkMode) darkColorScheme() else lightColorScheme()) - - MaterialTheme(colorScheme = colorScheme) { RootView().Compose() } +internal fun PresentationRootView(context: ComposeContext) { + val colorScheme = if (isSystemInDarkTheme()) ColorScheme.dark else ColorScheme.light + PresentationRoot(defaultColorScheme = colorScheme, context = context) { ctx -> + val contentContext = ctx.content() + Box(modifier = ctx.modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + RootView().Compose(context = contentContext) + } + } } - diff --git a/Package.swift b/Package.swift index 6db40ae..ae44256 100644 --- a/Package.swift +++ b/Package.swift @@ -19,8 +19,8 @@ let package = Package( .library(name: "HelloSkipApp", type: .dynamic, targets: ["HelloSkip"]), ], dependencies: [ - .package(url: "https://source.skip.tools/skip.git", from: "0.8.25"), - .package(url: "https://source.skip.tools/skip-ui.git", from: "0.5.19") + .package(url: "https://source.skip.tools/skip.git", from: "0.8.26"), + .package(url: "https://source.skip.tools/skip-ui.git", from: "0.6.0") ], targets: [ .target(name: "HelloSkip", dependencies: (zero ? [] : [.product(name: "SkipUI", package: "skip-ui")]), resources: [.process("Resources")], plugins: skipstone), diff --git a/Sources/HelloSkip/ContentView.swift b/Sources/HelloSkip/ContentView.swift index 9e176fc..d092a81 100644 --- a/Sources/HelloSkip/ContentView.swift +++ b/Sources/HelloSkip/ContentView.swift @@ -3,7 +3,7 @@ import SwiftUI public struct ContentView: View { @AppStorage("tab") var tab = Tab.welcome @AppStorage("name") var name = "Skipper" - @State var mode = false + @State var appearance = "" @State var isBeating = false public init() { @@ -43,8 +43,10 @@ public struct ContentView: View { NavigationStack { Form { TextField("Name", text: $name) - Toggle("Mode", isOn: $mode).onChange(of: mode) { _ in - logger.log("Toggled mode to: \(mode)") + Picker("Appearance", selection: $appearance) { + Text("System").tag("") + Text("Light").tag("light") + Text("Dark").tag("dark") } HStack { #if SKIP @@ -57,13 +59,13 @@ public struct ContentView: View { Text("Powered by \(androidSDK != nil ? "Jetpack Compose" : "SwiftUI")") } .foregroundStyle(.gray) - .bold(mode) } .navigationTitle("Settings") } .tabItem { Label("Settings", systemImage: "gearshape.fill") } .tag(Tab.settings) } + .preferredColorScheme(appearance == "dark" ? .dark : appearance == "light" ? .light : nil) } } diff --git a/Sources/HelloSkip/Resources/Localizable.xcstrings b/Sources/HelloSkip/Resources/Localizable.xcstrings index aadf83e..3dacac5 100644 --- a/Sources/HelloSkip/Resources/Localizable.xcstrings +++ b/Sources/HelloSkip/Resources/Localizable.xcstrings @@ -1,6 +1,62 @@ { "sourceLanguage" : "en", "strings" : { + "Appearance" : { + "localizations" : { + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "Apariencia" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Apparence" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "外観" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "外观" + } + } + } + }, + "Dark" : { + "localizations" : { + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "Oscuro" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Sombre" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "ダーク" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "暗黑" + } + } + } + }, "Hello %@!" : { "localizations" : { "es" : { @@ -85,30 +141,30 @@ } } }, - "Mode" : { + "Light" : { "localizations" : { "es" : { "stringUnit" : { "state" : "translated", - "value" : "Modo" + "value" : "Claro" } }, "fr" : { "stringUnit" : { "state" : "translated", - "value" : "Mode" + "value" : "Clair" } }, "ja" : { "stringUnit" : { "state" : "translated", - "value" : "モード" + "value" : "ライト" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "模式" + "value" : "明亮" } } } @@ -225,6 +281,34 @@ } } }, + "System" : { + "localizations" : { + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "Sistema" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Système" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "システム" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "系统颜" + } + } + } + }, "Welcome" : { "localizations" : { "es" : { @@ -255,4 +339,4 @@ } }, "version" : "1.0" -} \ No newline at end of file +}