Skip to content

Commit

Permalink
Match latest template
Browse files Browse the repository at this point in the history
  • Loading branch information
aabewhite committed Mar 29, 2024
1 parent 953ba4c commit 4223325
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 37 deletions.
35 changes: 10 additions & 25 deletions Android/app/src/main/kotlin/hello/skip/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,17 @@ 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
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")
Expand Down Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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)
}
}
}

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 6 additions & 4 deletions Sources/HelloSkip/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down
96 changes: 90 additions & 6 deletions Sources/HelloSkip/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -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" : {
Expand Down Expand Up @@ -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" : "明亮"
}
}
}
Expand Down Expand Up @@ -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" : {
Expand Down Expand Up @@ -255,4 +339,4 @@
}
},
"version" : "1.0"
}
}

0 comments on commit 4223325

Please sign in to comment.