mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-02 03:02:20 +00:00
Design system improvements (#45)
* Improve DesignSystem Apply Theme to all connected windows * Only use UIKit when available
This commit is contained in:
parent
6ccd27b2e5
commit
c304b3eefe
2 changed files with 71 additions and 13 deletions
|
@ -33,14 +33,12 @@ struct IceCubesApp: App {
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
appView
|
appView
|
||||||
.tint(theme.tintColor)
|
.applyTheme(theme)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
setNewClientsInEnv(client: appAccountsManager.currentClient)
|
setNewClientsInEnv(client: appAccountsManager.currentClient)
|
||||||
setBarsColor(color: theme.primaryBackgroundColor)
|
|
||||||
setupRevenueCat()
|
setupRevenueCat()
|
||||||
refreshPushSubs()
|
refreshPushSubs()
|
||||||
}
|
}
|
||||||
.preferredColorScheme(theme.selectedScheme == ColorScheme.dark ? .dark : .light)
|
|
||||||
.environmentObject(appAccountsManager)
|
.environmentObject(appAccountsManager)
|
||||||
.environmentObject(appAccountsManager.currentClient)
|
.environmentObject(appAccountsManager.currentClient)
|
||||||
.environmentObject(quickLook)
|
.environmentObject(quickLook)
|
||||||
|
@ -52,18 +50,15 @@ struct IceCubesApp: App {
|
||||||
.environmentObject(PushNotificationsService.shared)
|
.environmentObject(PushNotificationsService.shared)
|
||||||
.quickLookPreview($quickLook.url, in: quickLook.urls)
|
.quickLookPreview($quickLook.url, in: quickLook.urls)
|
||||||
}
|
}
|
||||||
.onChange(of: scenePhase, perform: { scenePhase in
|
.onChange(of: scenePhase) { scenePhase in
|
||||||
handleScenePhase(scenePhase: scenePhase)
|
handleScenePhase(scenePhase: scenePhase)
|
||||||
})
|
}
|
||||||
.onChange(of: appAccountsManager.currentClient) { newClient in
|
.onChange(of: appAccountsManager.currentClient) { newClient in
|
||||||
setNewClientsInEnv(client: newClient)
|
setNewClientsInEnv(client: newClient)
|
||||||
if newClient.isAuth {
|
if newClient.isAuth {
|
||||||
watcher.watch(streams: [.user, .direct])
|
watcher.watch(streams: [.user, .direct])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: theme.primaryBackgroundColor) { newValue in
|
|
||||||
setBarsColor(color: newValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
|
@ -143,11 +138,6 @@ struct IceCubesApp: App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setBarsColor(color: Color) {
|
|
||||||
UINavigationBar.appearance().isTranslucent = true
|
|
||||||
UINavigationBar.appearance().barTintColor = UIColor(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func setupRevenueCat() {
|
private func setupRevenueCat() {
|
||||||
Purchases.logLevel = .error
|
Purchases.logLevel = .error
|
||||||
Purchases.configure(withAPIKey: "appl_JXmiRckOzXXTsHKitQiicXCvMQi")
|
Purchases.configure(withAPIKey: "appl_JXmiRckOzXXTsHKitQiicXCvMQi")
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
import SwiftUI
|
||||||
|
#if canImport(UIKit)
|
||||||
|
import UIKit
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public extension View {
|
||||||
|
func applyTheme(_ theme: Theme) -> some View {
|
||||||
|
modifier(ThemeApplier(theme: theme))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ThemeApplier: ViewModifier {
|
||||||
|
@ObservedObject var theme: Theme
|
||||||
|
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
content
|
||||||
|
.tint(theme.tintColor)
|
||||||
|
.preferredColorScheme(theme.selectedScheme == ColorScheme.dark ? .dark : .light)
|
||||||
|
#if canImport(UIKit)
|
||||||
|
.onAppear {
|
||||||
|
setWindowTint(theme.tintColor)
|
||||||
|
setWindowUserInterfaceStyle(theme.selectedScheme)
|
||||||
|
setBarsColor(theme.primaryBackgroundColor)
|
||||||
|
}
|
||||||
|
.onChange(of: theme.tintColor) { newValue in
|
||||||
|
setWindowTint(newValue)
|
||||||
|
}
|
||||||
|
.onChange(of: theme.selectedScheme) { newValue in
|
||||||
|
setWindowUserInterfaceStyle(newValue)
|
||||||
|
}
|
||||||
|
.onChange(of: theme.primaryBackgroundColor) { newValue in
|
||||||
|
setBarsColor(newValue)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if canImport(UIKit)
|
||||||
|
private func setWindowUserInterfaceStyle(_ colorScheme: ColorScheme) {
|
||||||
|
allWindows()
|
||||||
|
.forEach {
|
||||||
|
switch colorScheme {
|
||||||
|
case .dark:
|
||||||
|
$0.overrideUserInterfaceStyle = .dark
|
||||||
|
case .light:
|
||||||
|
$0.overrideUserInterfaceStyle = .light
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setWindowTint(_ color: Color) {
|
||||||
|
allWindows()
|
||||||
|
.forEach {
|
||||||
|
$0.tintColor = UIColor(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setBarsColor(_ color: Color) {
|
||||||
|
UINavigationBar.appearance().isTranslucent = true
|
||||||
|
UINavigationBar.appearance().barTintColor = UIColor(color)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func allWindows() -> [UIWindow] {
|
||||||
|
UIApplication.shared.connectedScenes
|
||||||
|
.compactMap { $0 as? UIWindowScene }
|
||||||
|
.flatMap { $0.windows }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in a new issue