diff --git a/Sources/ThemePark/QueryContextModifier.swift b/Sources/ThemePark/QueryContextModifier.swift index d2d23c3..bdd9dce 100644 --- a/Sources/ThemePark/QueryContextModifier.swift +++ b/Sources/ThemePark/QueryContextModifier.swift @@ -11,6 +11,18 @@ extension EnvironmentValues { } } +extension View { + func plaformOnHover(perform block: @escaping (Bool) -> Void) -> some View { + #if os(macOS) || os(iOS) + if #available(iOS 13.4, *) { + return self.onHover(perform: block) + } + #endif + + return self + } +} + struct QueryContextModifier: ViewModifier { #if os(macOS) @Environment(\.controlActiveState) private var controlActiveState @@ -20,17 +32,24 @@ struct QueryContextModifier: ViewModifier { @State private var hovering = false private var context: Query.Context { +#if os(macOS) .init( controlState: .init(controlActiveState: controlActiveState), colorScheme: colorScheme, colorSchemeContrast: colorSchemeContrast ) +#else + .init( + colorScheme: colorScheme, + colorSchemeContrast: colorSchemeContrast + ) +#endif } func body(content: Content) -> some View { content .environment(\.styleQueryContext, context) - .onHover(perform: { self.hovering = $0 }) + .plaformOnHover(perform: { self.hovering = $0 }) } } @@ -42,30 +61,19 @@ extension View { } struct ForegroundColorQueryModifier: ViewModifier { -#if os(macOS) - @Environment(\.controlActiveState) private var controlActiveState -#endif - @Environment(\.colorScheme) private var colorScheme - @Environment(\.colorSchemeContrast) private var colorSchemeContrast + @Environment(\.styleQueryContext) private var context @State private var hovering = false let key: Query.Key let styler: Styler - private var context: Query.Context { - .init( - controlState: .init(controlActiveState: controlActiveState), - colorScheme: colorScheme, - colorSchemeContrast: colorSchemeContrast - ) - } - var foregroundColor: PlatformColor { styler.color(for: Query(key: key, context: context)) } func body(content: Content) -> some View { content + .themeSensitive() .foregroundColor(Color(foregroundColor)) } } diff --git a/Sources/ThemePark/Style.swift b/Sources/ThemePark/Style.swift index ac875da..13cd166 100644 --- a/Sources/ThemePark/Style.swift +++ b/Sources/ThemePark/Style.swift @@ -31,7 +31,7 @@ extension PlatformColor { static let fallbackForegroundColor: PlatformColor = .labelColor static let fallbackBackgroundColor: PlatformColor = .windowBackgroundColor #else - static let fallbackForegroundColor: PlatformColor = .labelColor + static let fallbackForegroundColor: PlatformColor = .label static let fallbackBackgroundColor: PlatformColor = .black #endif } diff --git a/Sources/ThemePark/XcodeTheme.swift b/Sources/ThemePark/XcodeTheme.swift index d07620d..e84594f 100644 --- a/Sources/ThemePark/XcodeTheme.swift +++ b/Sources/ThemePark/XcodeTheme.swift @@ -195,6 +195,7 @@ public struct XcodeVariantTheme { self.dark = dark } +#if canImport(AppKit) && !targetEnvironment(macCatalyst) public static var all: [XcodeVariantTheme] { let allThemes = XcodeTheme.all @@ -220,6 +221,7 @@ public struct XcodeVariantTheme { return variants } +#endif } extension XcodeVariantTheme: Styling {