Skip to content

Commit

Permalink
Fabric: Fixes high contrast color when not specified (#47418)
Browse files Browse the repository at this point in the history
Summary:
Fixes the high contrast color when not specified. Previously, if we didn't specify highContrastLight or highContrastDark, it would create a UIColor with an alpha of 0, which is not what we expected. We should fall back to the dark or light color instead.

## Changelog:

[IOS] [FIXED] - Fabric: Fixes high contrast color when not specified

Pull Request resolved: #47418

Test Plan:
1. Enable color contrast in iPhone's settings.
2. Open PlatformColor example in RNTester. See dynamic colors
3. color shows correctly
![image](https://github.com/user-attachments/assets/a71b8743-b397-4a11-b287-ec117b1ba243)

Before:
![image](https://github.com/user-attachments/assets/6a12824b-f77c-4979-a232-c1c97554e53c)

Reviewed By: javache

Differential Revision: D66303078

Pulled By: cipolleschi

fbshipit-source-id: 63a0d2bc94eea438d4f69643d09825b74575188b
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Nov 22, 2024
1 parent e6848ba commit 89f93dc
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
if (lightColor != nil && darkColor != nil) {
UIColor *color = [UIColor colorWithDynamicProvider:^UIColor *_Nonnull(UITraitCollection *_Nonnull collection) {
if (collection.userInterfaceStyle == UIUserInterfaceStyleDark) {
if (collection.accessibilityContrast == UIAccessibilityContrastHigh && highContrastDarkColor != nil) {
if (collection.accessibilityContrast == UIAccessibilityContrastHigh && highContrastDark != 0) {
return highContrastDarkColor;
} else {
return darkColor;
}
} else {
if (collection.accessibilityContrast == UIAccessibilityContrastHigh && highContrastLightColor != nil) {
if (collection.accessibilityContrast == UIAccessibilityContrastHigh && highContrastLight != 0) {
return highContrastLightColor;
} else {
return lightColor;
Expand Down

0 comments on commit 89f93dc

Please sign in to comment.