Skip to content

Commit

Permalink
Fix some iOS build failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed May 1, 2024
1 parent 73b10cd commit 3ce03dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
36 changes: 22 additions & 14 deletions Sources/ThemePark/QueryContextModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
}
}

Expand All @@ -42,30 +61,19 @@ extension View {
}

struct ForegroundColorQueryModifier<Styler: Styling>: 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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ThemePark/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/ThemePark/XcodeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public struct XcodeVariantTheme {
self.dark = dark
}

#if canImport(AppKit) && !targetEnvironment(macCatalyst)
public static var all: [XcodeVariantTheme] {
let allThemes = XcodeTheme.all

Expand All @@ -220,6 +221,7 @@ public struct XcodeVariantTheme {

return variants
}
#endif
}

extension XcodeVariantTheme: Styling {
Expand Down

0 comments on commit 3ce03dc

Please sign in to comment.