Skip to content

Commit

Permalink
fix PlatformColor resolves to incorrect color in some appearances
Browse files Browse the repository at this point in the history
  • Loading branch information
unixzii authored and ktiays committed Mar 31, 2022
1 parent 8a5bcc6 commit 8cfbd75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Sources/CyanExtensions/NSAppearance+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Created by Cyandev on 2022/3/31.
// Copyright (c) 2021 Cyandev. All rights reserved.
//

#if canImport(AppKit)
import AppKit

public enum UserInterfaceStyle {
case light
case dark
}

public extension NSAppearance {

var userInterfaceStyle: UserInterfaceStyle {
if name == Name.darkAqua ||
name == Name.vibrantDark ||
name == Name.accessibilityHighContrastDarkAqua ||
name == Name.accessibilityHighContrastVibrantDark {
return .dark
}
return .light
}

}
#endif
2 changes: 1 addition & 1 deletion Sources/CyanExtensions/PlatformColor+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public extension PlatformColor {

convenience init(lightColor: PlatformColor, darkColor: PlatformColor) {
self.init(name: nil, dynamicProvider: { appearance in
if appearance.name == .darkAqua {
if appearance.userInterfaceStyle == .dark {
return darkColor
} else {
return lightColor
Expand Down

0 comments on commit 8cfbd75

Please sign in to comment.