From 7b6aa556e862e6481101be5923ecb8ddfe91335d Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Fri, 18 Feb 2022 18:12:27 -0800 Subject: [PATCH] [0.66] Backport a few of 10.15+ changes to 0.66 stable (#1030) * RCTSwitch: Use NSSwitch instead of NSButton (#924) * add pull yml * match handleOpenURLNotification event payload with iOS (#755) (#2) Co-authored-by: Ryan Linton * [pull] master from microsoft:master (#11) * Deprecated api (#853) * Remove deprecated/unused context param * Update a few Mac deprecated APIs * Packing RN dependencies, hermes and ignoring javadoc failure, (#852) * Ignore javadoc failure * Bringing few more changes from 0.63-stable * Fixing a patch in engine selection * Fixing a patch in nuget spec * Fixing the output directory of nuget pack * Packaging dependencies in the nuget * Fix onMouseEnter/onMouseLeave callbacks not firing on Pressable (#855) * add pull yml * match handleOpenURLNotification event payload with iOS (#755) (#2) Co-authored-by: Ryan Linton * fix mouse evetns on pressable * delete extra yml from this branch * Add macOS tags * reorder props to have onMouseEnter/onMouseLeave always be before onPress Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> Co-authored-by: Ryan Linton * Grammar fixes. (#856) Updates simple grammar issues. Co-authored-by: Nick Trescases <42704557+ntre@users.noreply.github.com> Co-authored-by: Anandraj Co-authored-by: Saad Najmi Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> Co-authored-by: Ryan Linton Co-authored-by: Muhammad Hamza Zaman * Use NSSwitch * remove change from my fork Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> Co-authored-by: Ryan Linton Co-authored-by: Nick Trescases <42704557+ntre@users.noreply.github.com> Co-authored-by: Anandraj Co-authored-by: Muhammad Hamza Zaman * DynamicColorMacOS fixes (#1028) * Use initWithDynamicProvider + Add HC Support * Update log error * replace all references to 10.14 (#938) * Replace currentAppearance with currentDrawingAppearance on macOS 11+ (#1029) * Manually cherry-pick #1012 Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> Co-authored-by: Ryan Linton Co-authored-by: Nick Trescases <42704557+ntre@users.noreply.github.com> Co-authored-by: Anandraj Co-authored-by: Muhammad Hamza Zaman --- Libraries/Image/RCTImageView.mm | 10 +- .../PlatformColorValueTypes.macos.js | 17 +- .../PlatformColorValueTypesMacOS.js | 2 + .../PlatformColorValueTypesMacOS.macos.js | 9 +- README.md | 2 +- React/Base/RCTConvert.m | 27 ++- React/Base/macOS/RCTDynamicColor.h | 28 --- React/Base/macOS/RCTDynamicColor.m | 219 ------------------ React/CoreModules/RCTAppearance.mm | 45 ++-- React/CoreModules/RCTDevLoadingView.mm | 25 +- React/Views/RCTSwitch.h | 2 +- React/Views/RCTSwitch.m | 15 -- .../RCTConvert_NSColorTests.m | 38 ++- .../PlatformColor/PlatformColorExample.js | 21 ++ 14 files changed, 125 insertions(+), 335 deletions(-) delete mode 100644 React/Base/macOS/RCTDynamicColor.h delete mode 100644 React/Base/macOS/RCTDynamicColor.m diff --git a/Libraries/Image/RCTImageView.mm b/Libraries/Image/RCTImageView.mm index 68818b3a427df3..ae44c0ac9daf88 100644 --- a/Libraries/Image/RCTImageView.mm +++ b/Libraries/Image/RCTImageView.mm @@ -649,18 +649,12 @@ - (RCTPlatformView *)reactAccessibilityElement - (NSColor *)tintColor { - NSColor *tintColor = nil; - if (@available(macOS 10.14, *)) { - tintColor = _imageView.contentTintColor; - } - return tintColor; + return _imageView.contentTintColor; } - (void)setTintColor:(NSColor *)tintColor { - if (@available(macOS 10.14, *)) { - _imageView.contentTintColor = tintColor; - } + _imageView.contentTintColor = tintColor; } #endif // ]TODO(macOS GH#774) diff --git a/Libraries/StyleSheet/PlatformColorValueTypes.macos.js b/Libraries/StyleSheet/PlatformColorValueTypes.macos.js index 876e668f0fcbc9..58e36cde7bbd47 100644 --- a/Libraries/StyleSheet/PlatformColorValueTypes.macos.js +++ b/Libraries/StyleSheet/PlatformColorValueTypes.macos.js @@ -18,6 +18,8 @@ export opaque type NativeColorValue = { dynamic?: { light: ?(ColorValue | ProcessedColorValue), dark: ?(ColorValue | ProcessedColorValue), + highContrastLight?: ?(ColorValue | ProcessedColorValue), + highContrastDark?: ?(ColorValue | ProcessedColorValue), }, colorWithSystemEffect?: { baseColor: ?(ColorValue | ProcessedColorValue), @@ -51,12 +53,21 @@ export const ColorWithSystemEffectMacOSPrivate = ( export type DynamicColorMacOSTuplePrivate = { light: ColorValue, dark: ColorValue, + highContrastLight?: ColorValue, + highContrastDark?: ColorValue, }; export const DynamicColorMacOSPrivate = ( tuple: DynamicColorMacOSTuplePrivate, ): ColorValue => { - return {dynamic: {light: tuple.light, dark: tuple.dark}}; + return { + dynamic: { + light: tuple.light, + dark: tuple.dark, + highContrastLight: tuple.highContrastLight, + highContrastDark: tuple.highContrastDark, + }, + }; }; export const normalizeColorObject = ( @@ -74,6 +85,8 @@ export const normalizeColorObject = ( dynamic: { light: normalizeColor(dynamic.light), dark: normalizeColor(dynamic.dark), + highContrastLight: normalizeColor(dynamic.highContrastLight), + highContrastDark: normalizeColor(dynamic.highContrastDark), }, }; return dynamicColor; @@ -104,6 +117,8 @@ export const processColorObject = ( dynamic: { light: processColor(dynamic.light), dark: processColor(dynamic.dark), + highContrastLight: processColor(dynamic.highContrastLight), + highContrastDark: processColor(dynamic.highContrastDark), }, }; return dynamicColor; diff --git a/Libraries/StyleSheet/PlatformColorValueTypesMacOS.js b/Libraries/StyleSheet/PlatformColorValueTypesMacOS.js index 8a2c2e8eab684f..53955c5200c91d 100644 --- a/Libraries/StyleSheet/PlatformColorValueTypesMacOS.js +++ b/Libraries/StyleSheet/PlatformColorValueTypesMacOS.js @@ -15,6 +15,8 @@ import type {ColorValue} from './StyleSheet'; export type DynamicColorMacOSTuple = { light: ColorValue, dark: ColorValue, + highContrastLight?: ColorValue, + highContrastDark?: ColorValue, }; export const DynamicColorMacOS = ( diff --git a/Libraries/StyleSheet/PlatformColorValueTypesMacOS.macos.js b/Libraries/StyleSheet/PlatformColorValueTypesMacOS.macos.js index 76d4cfd3782896..a3d5d99d59c45c 100644 --- a/Libraries/StyleSheet/PlatformColorValueTypesMacOS.macos.js +++ b/Libraries/StyleSheet/PlatformColorValueTypesMacOS.macos.js @@ -19,12 +19,19 @@ import { export type DynamicColorMacOSTuple = { light: ColorValue, dark: ColorValue, + highContrastLight?: ColorValue, + highContrastDark?: ColorValue, }; export const DynamicColorMacOS = ( tuple: DynamicColorMacOSTuple, ): ColorValue => { - return DynamicColorMacOSPrivate({light: tuple.light, dark: tuple.dark}); + return DynamicColorMacOSPrivate({ + light: tuple.light, + dark: tuple.dark, + highContrastLight: tuple.highContrastLight, + highContrastDark: tuple.highContrastDark, + }); }; export type SystemEffectMacOS = diff --git a/README.md b/README.md index 27945d13bbe998..849329aabd7b61 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ You can read more about the macOS implementation on our website - [React Native ## Requirements -You can run React Native for macOS apps on Mac devices with versions Mojave (10.14) or newer. +You can run React Native for macOS apps on Mac devices with versions Catalina (10.15) or newer. For a full and detailed list of the system requirements and how to set up your development platform, see our [System Requirements](https://microsoft.github.io/react-native-windows/docs/rnm-dependencies) documentation on our website. diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 55af6b684ccbb3..6a317543e6b118 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -16,10 +16,6 @@ #import "RCTParserUtils.h" #import "RCTUtils.h" -#if TARGET_OS_OSX // [TODO(macOS GH#774) -#import "RCTDynamicColor.h" -#endif // ]TODO(macOS GH#774) - @implementation RCTConvert RCT_CONVERTER(id, id, self) @@ -1043,7 +1039,28 @@ + (RCTUIColor *)UIColor:(id)json // TODO(macOS GH#750) RCTUIColor *highContrastDarkColor = [RCTConvert UIColor:highContrastDark]; // TODO(macOS GH#750) if (lightColor != nil && darkColor != nil) { #if TARGET_OS_OSX - RCTDynamicColor *color = [[RCTDynamicColor alloc] initWithAquaColor:lightColor darkAquaColor:darkColor]; + NSColor *color = [NSColor colorWithName:nil dynamicProvider:^NSColor * _Nonnull(NSAppearance * _Nonnull appearance) { + NSMutableArray *appearances = [NSMutableArray arrayWithArray:@[NSAppearanceNameAqua,NSAppearanceNameDarkAqua]]; + if (highContrastLightColor != nil) { + [appearances addObject:NSAppearanceNameAccessibilityHighContrastAqua]; + } + if (highContrastDarkColor != nil) { + [appearances addObject:NSAppearanceNameAccessibilityHighContrastDarkAqua]; + } + NSAppearanceName bestMatchingAppearance = [appearance bestMatchFromAppearancesWithNames:appearances]; + if (bestMatchingAppearance == NSAppearanceNameAqua) { + return lightColor; + } else if (bestMatchingAppearance == NSAppearanceNameDarkAqua) { + return darkColor; + } else if (bestMatchingAppearance == NSAppearanceNameAccessibilityHighContrastAqua) { + return highContrastLightColor; + } else if (bestMatchingAppearance == NSAppearanceNameAccessibilityHighContrastDarkAqua) { + return highContrastDarkColor; + } else { + RCTLogConvertError(json, @"an NSColorColor. Could not resolve current appearance. Defaulting to light."); + return lightColor; + } + }]; return color; #else #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 diff --git a/React/Base/macOS/RCTDynamicColor.h b/React/Base/macOS/RCTDynamicColor.h deleted file mode 100644 index 7919ca4f8bd1c0..00000000000000 --- a/React/Base/macOS/RCTDynamicColor.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// TODO(macOS GH#774) - -#include - -/** A dynamic, theme aware subclass of NSColor. - * It is a tuple that contains two NSColors for light and dark - * theme appearances. Like a semantic NSColor or an - * asset catalog named NSColor, the effective color values - * returned by the various methods and properties vary - * depending on the current [NSAppearance currentAppearance]. - */ -@interface RCTDynamicColor : NSColor - -/** Inits a RCTDynamicColor with a pair of NSColors - * @param aquaColor the color to use when the current appearance is not dark - * @param darkAquaColor the color to use when the current appearance is dark - */ -- (instancetype)initWithAquaColor:(NSColor *)aquaColor - darkAquaColor:(nullable NSColor *)darkAquaColor; - -@end diff --git a/React/Base/macOS/RCTDynamicColor.m b/React/Base/macOS/RCTDynamicColor.m deleted file mode 100644 index 3315979c300701..00000000000000 --- a/React/Base/macOS/RCTDynamicColor.m +++ /dev/null @@ -1,219 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// TODO(macOS GH#774) - -#import "RCTDynamicColor.h" - -#define RCT_FORWARD_PROPERTY( PROP, TYPE ) \ -- (TYPE)PROP { return [[self effectiveColor] PROP]; } - -static NSString *const RCTAquaColor = @"aquaColor"; -static NSString *const RCTDarkAquaColor = @"darkAquaColor"; - -@implementation RCTDynamicColor -{ - NSColor *_aquaColor; - NSColor *_darkAquaColor; -} - -- (instancetype)initWithAquaColor:(NSColor *)aquaColor - darkAquaColor:(NSColor *)darkAquaColor -{ - self = [super init]; - if (self) { - _aquaColor = [aquaColor copy]; - _darkAquaColor = [darkAquaColor copy]; - } - return self; -} - -+ (BOOL)supportsSecureCoding -{ - return YES; -} - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - self = [super initWithCoder:coder]; - if (self) { - _aquaColor = [coder decodeObjectOfClass:[NSColor class] forKey:RCTAquaColor]; - _darkAquaColor = [coder decodeObjectOfClass:[NSColor class] forKey:RCTDarkAquaColor]; - } - return self; -} - -- (void)encodeWithCoder:(NSCoder *)aCoder -{ - [super encodeWithCoder:aCoder]; - [aCoder encodeObject:_aquaColor forKey:RCTAquaColor]; - if (_darkAquaColor) { - [aCoder encodeObject:_darkAquaColor forKey:RCTDarkAquaColor]; - } -} - -- (NSColor *)effectiveColor -{ - NSColor *effectiveColor = _aquaColor; - if (@available(macOS 10.14, *)) { - NSAppearance *appearance = [NSAppearance currentAppearance] ?: [NSApp effectiveAppearance]; - - NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; - - if (_darkAquaColor != nil && [appearanceName isEqualToString:NSAppearanceNameDarkAqua]) { - effectiveColor = _darkAquaColor; - } - } - return effectiveColor; -} - -RCT_FORWARD_PROPERTY(colorSpace, NSColorSpace *) -- (NSColor *)colorUsingColorSpace:(NSColorSpace *)space -{ - return [[self effectiveColor] colorUsingColorSpace:space]; -} - -RCT_FORWARD_PROPERTY(colorSpaceName, NSColorSpaceName) -- (NSColor *)colorUsingColorSpaceName:(NSColorSpaceName)name -{ - return [[self effectiveColor] colorUsingColorSpaceName:name]; -} - -RCT_FORWARD_PROPERTY(numberOfComponents, NSInteger) -- (void)getComponents:(CGFloat *)components -{ - return [[self effectiveColor] getComponents:components]; -} - -#pragma mark - RGB colorspace - -RCT_FORWARD_PROPERTY(redComponent, CGFloat) -RCT_FORWARD_PROPERTY(greenComponent, CGFloat) -RCT_FORWARD_PROPERTY(blueComponent, CGFloat) - -- (void)getRed:(nullable CGFloat *)red green:(nullable CGFloat *)green blue:(nullable CGFloat *)blue alpha:(nullable CGFloat *)alpha -{ - return [[self effectiveColor] getRed:red green:green blue:blue alpha:alpha]; -} - -#pragma mark - HSB colorspace - -RCT_FORWARD_PROPERTY(hueComponent, CGFloat) -RCT_FORWARD_PROPERTY(saturationComponent, CGFloat) -RCT_FORWARD_PROPERTY(brightnessComponent, CGFloat) - -- (void)getHue:(nullable CGFloat *)hue saturation:(nullable CGFloat *)saturation brightness:(nullable CGFloat *)brightness alpha:(nullable CGFloat *)alpha -{ - return [[self effectiveColor] getHue:hue saturation:saturation brightness:brightness alpha:alpha]; -} - -#pragma mark - Gray colorspace - -RCT_FORWARD_PROPERTY(whiteComponent, CGFloat) - -- (void)getWhite:(CGFloat *)white alpha:(CGFloat *)alpha -{ - return [[self effectiveColor] getWhite:white alpha:alpha]; -} - -#pragma mark - CMYK colorspace - -RCT_FORWARD_PROPERTY(cyanComponent, CGFloat) -RCT_FORWARD_PROPERTY(magentaComponent, CGFloat) -RCT_FORWARD_PROPERTY(yellowComponent, CGFloat) -RCT_FORWARD_PROPERTY(blackComponent, CGFloat) - -- (void)getCyan:(nullable CGFloat *)cyan magenta:(nullable CGFloat *)magenta yellow:(nullable CGFloat *)yellow black:(nullable CGFloat *)black alpha:(nullable CGFloat *)alpha -{ - return [[self effectiveColor] getCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha]; -} - -#pragma mark - Others - -RCT_FORWARD_PROPERTY(alphaComponent, CGFloat) -RCT_FORWARD_PROPERTY(CGColor, CGColorRef) -RCT_FORWARD_PROPERTY(catalogNameComponent, NSColorListName) -RCT_FORWARD_PROPERTY(colorNameComponent, NSColorName) -RCT_FORWARD_PROPERTY(localizedCatalogNameComponent, NSColorListName) -RCT_FORWARD_PROPERTY(localizedColorNameComponent, NSString *) - -- (void)setStroke -{ - [[self effectiveColor] setStroke]; -} - -- (void)setFill -{ - [[self effectiveColor] setFill]; -} - -- (void)set -{ - [[self effectiveColor] set]; -} - -- (nullable NSColor *)highlightWithLevel:(CGFloat)val -{ - return [[self effectiveColor] highlightWithLevel:val]; -} - -- (NSColor *)shadowWithLevel:(CGFloat)val -{ - return [[self effectiveColor] shadowWithLevel:val]; -} - -- (NSColor *)colorWithAlphaComponent:(CGFloat)alpha -{ - return [[self effectiveColor] colorWithAlphaComponent:alpha]; -} - -- (nullable NSColor *)blendedColorWithFraction:(CGFloat)fraction ofColor:(NSColor *)color -{ - return [[self effectiveColor] blendedColorWithFraction:fraction ofColor:color]; -} - -- (NSColor *)colorWithSystemEffect:(NSColorSystemEffect)systemEffect NS_AVAILABLE_MAC(10_14) -{ - NSColor *aquaColorWithSystemEffect = [_aquaColor colorWithSystemEffect:systemEffect]; - NSColor *darkAquaColorWithSystemEffect = [_darkAquaColor colorWithSystemEffect:systemEffect]; - return [[RCTDynamicColor alloc] initWithAquaColor:aquaColorWithSystemEffect darkAquaColor:darkAquaColorWithSystemEffect]; -} - -- (NSUInteger)hash -{ - const NSUInteger prime = 31; - NSUInteger result = 1; - result = prime * result + [_aquaColor hash]; - result = prime * result + [_darkAquaColor hash]; - return result; -} - -- (BOOL)isEqual:(id)other { - if (other == self) { - return YES; - } - - return other != nil && [other isKindOfClass:[self class]] && [self isEqualToDynamicColor:other]; -} - -- (BOOL)isEqualToDynamicColor:(RCTDynamicColor *)other { - if (self == other) { - return YES; - } - - if ([_aquaColor isNotEqualTo:other->_aquaColor]) { - return NO; - } - - if ([_darkAquaColor isNotEqualTo:other->_darkAquaColor]) { - return NO; - } - - return YES; -} - -@end diff --git a/React/CoreModules/RCTAppearance.mm b/React/CoreModules/RCTAppearance.mm index b0da18b72db345..7d81fae4dc1362 100644 --- a/React/CoreModules/RCTAppearance.mm +++ b/React/CoreModules/RCTAppearance.mm @@ -66,29 +66,28 @@ void RCTOverrideAppearancePreference(NSString *const colorSchemeOverride) #else // [TODO(macOS GH#774) NSString *RCTColorSchemePreference(NSAppearance *appearance) { - if (@available(macOS 10.14, *)) { - static NSDictionary *appearances; - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - appearances = @{ - NSAppearanceNameAqua: RCTAppearanceColorSchemeLight, - NSAppearanceNameDarkAqua: RCTAppearanceColorSchemeDark - }; - }); - - if (!sAppearancePreferenceEnabled) { - // Return the default if the app doesn't allow different color schemes. - return RCTAppearanceColorSchemeLight; - } - - appearance = appearance ?: [NSAppearance currentAppearance]; - NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; - return appearances[appearanceName] ?: RCTAppearanceColorSchemeLight; + static NSDictionary *appearances; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + appearances = @{ + NSAppearanceNameAqua: RCTAppearanceColorSchemeLight, + NSAppearanceNameDarkAqua: RCTAppearanceColorSchemeDark + }; + }); + + if (!sAppearancePreferenceEnabled) { + // Return the default if the app doesn't allow different color schemes. + return RCTAppearanceColorSchemeLight; } - // Default to light on older OS version - same behavior as Android. - return RCTAppearanceColorSchemeLight; + if (@available(macOS 11.0, *)) { + appearance = appearance ?: [NSAppearance currentDrawingAppearance]; + } else { + appearance = appearance ?: [NSAppearance currentAppearance]; + } + NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; + return appearances[appearanceName] ?: RCTAppearanceColorSchemeLight; } #endif // ]TODO(macOS GH#774) @@ -165,7 +164,7 @@ - (void)appearanceChanged:(NSNotification *)notification - (void)startObserving { - if (@available(macOS 10.14, iOS 13.0, *)) { // TODO(macOS GH#774) + if (@available(iOS 13.0, *)) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appearanceChanged:) name:RCTUserInterfaceStyleDidChangeNotification @@ -175,7 +174,7 @@ - (void)startObserving - (void)stopObserving { - if (@available(macOS 10.14, iOS 13.0, *)) { // TODO(macOS GH#774) + if (@available(iOS 13.0, *)) { [[NSNotificationCenter defaultCenter] removeObserver:self]; } } diff --git a/React/CoreModules/RCTDevLoadingView.mm b/React/CoreModules/RCTDevLoadingView.mm index 427620e7802d37..919d66f93e8955 100644 --- a/React/CoreModules/RCTDevLoadingView.mm +++ b/React/CoreModules/RCTDevLoadingView.mm @@ -266,16 +266,21 @@ - (void)showProgressMessage:(NSString *)message - (void)showOfflineMessage { - RCTUIColor *color = [RCTUIColor whiteColor]; // TODO(macOS GH#774) - RCTUIColor *backgroundColor = [RCTUIColor blackColor]; // TODO(macOS GH#774) - - if ([self isDarkModeEnabled]) { - color = [RCTUIColor blackColor]; // TODO(macOS GH#774) - backgroundColor = [RCTUIColor whiteColor]; // TODO(macOS GH#774) - } + // [TODO(macOS GH#774) - isDarkModeEnabled should only be run on the main thread + __weak __typeof(self) weakSelf = self; + RCTExecuteOnMainQueue(^{ + RCTUIColor *color = [RCTUIColor whiteColor]; // TODO(macOS GH#774) + RCTUIColor *backgroundColor = [RCTUIColor blackColor]; // TODO(macOS GH#774) + + if ([weakSelf isDarkModeEnabled]) { + color = [RCTUIColor blackColor]; // TODO(macOS GH#774) + backgroundColor = [RCTUIColor whiteColor]; // TODO(macOS GH#774) + } - NSString *message = [NSString stringWithFormat:@"Connect to %@ to develop JavaScript.", RCT_PACKAGER_NAME]; - [self showMessage:message color:color backgroundColor:backgroundColor]; + NSString *message = [NSString stringWithFormat:@"Connect to %@ to develop JavaScript.", RCT_PACKAGER_NAME]; + [weakSelf showMessage:message color:color backgroundColor:backgroundColor]; + }); + // ]TODO(macOS GH#774) } - (BOOL)isDarkModeEnabled @@ -361,4 +366,4 @@ - (void)hide Class RCTDevLoadingViewCls(void) { return RCTDevLoadingView.class; -} +} \ No newline at end of file diff --git a/React/Views/RCTSwitch.h b/React/Views/RCTSwitch.h index b2fea24c9ea6f7..9dbb28709ca228 100644 --- a/React/Views/RCTSwitch.h +++ b/React/Views/RCTSwitch.h @@ -12,7 +12,7 @@ #if !TARGET_OS_OSX // TODO(macOS GH#774) @interface RCTSwitch : UISwitch #else // [TODO(macOS GH#774) -@interface RCTSwitch : NSButton +@interface RCTSwitch : NSSwitch #endif // ]TODO(macOS GH#774) #if !TARGET_OS_OSX // TODO(macOS GH#774) diff --git a/React/Views/RCTSwitch.m b/React/Views/RCTSwitch.m index 056f8066090bcc..78b846bbdf97bf 100644 --- a/React/Views/RCTSwitch.m +++ b/React/Views/RCTSwitch.m @@ -7,25 +7,10 @@ #import "RCTSwitch.h" -#if TARGET_OS_OSX // [TODO(macOS GH#774) -#import -#endif // ]TODO(macOS GH#774) - #import "UIView+React.h" @implementation RCTSwitch -#if TARGET_OS_OSX // [TODO(macOS GH#774) -- (instancetype)initWithFrame:(CGRect)frame -{ - if ((self = [super initWithFrame:frame])) { - self.buttonType = NSButtonTypeSwitch; - self.title = @""; // default is "Button" - } - return self; -} -#endif - #if !TARGET_OS_OSX // TODO(macOS GH#774) - (void)setOn:(BOOL)on animated:(BOOL)animated { diff --git a/packages/rn-tester/RNTesterUnitTests/RCTConvert_NSColorTests.m b/packages/rn-tester/RNTesterUnitTests/RCTConvert_NSColorTests.m index 64a1b20ebe08a4..9d38caf000dec3 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTConvert_NSColorTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTConvert_NSColorTests.m @@ -55,18 +55,14 @@ - (void)testAlternatingColorEven { id json = RCTJSONParse(@"{ \"semantic\": \"alternatingContentBackgroundColorEven\" }", nil); NSColor *value = [RCTConvert UIColor:json]; - if (@available(macOS 10.14, *)) { - XCTAssertEqualObjects(value, [NSColor alternatingContentBackgroundColors][0]); - } + XCTAssertEqualObjects(value, [NSColor alternatingContentBackgroundColors][0]); } - (void)testAlternatingColorOdd { id json = RCTJSONParse(@"{ \"semantic\": \"alternatingContentBackgroundColorOdd\" }", nil); NSColor *value = [RCTConvert UIColor:json]; - if (@available(macOS 10.14, *)) { - XCTAssertEqualObjects(value, [NSColor alternatingContentBackgroundColors][1]); - } + XCTAssertEqualObjects(value, [NSColor alternatingContentBackgroundColors][1]); } - (void)testAlternatingColorFallbackEven @@ -99,14 +95,12 @@ - (void)testDynamicColor XCTAssertEqual(b, 0); XCTAssertEqual(a, 0); - if (@available(macOS 10.14, *)) { - [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; - [value getRed:&r green:&g blue:&b alpha:&a]; - XCTAssertEqual(r, 1); - XCTAssertEqual(g, 1); - XCTAssertEqual(b, 1); - XCTAssertEqual(a, 0); - } + [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; + [value getRed:&r green:&g blue:&b alpha:&a]; + XCTAssertEqual(r, 1); + XCTAssertEqual(g, 1); + XCTAssertEqual(b, 1); + XCTAssertEqual(a, 0); [NSAppearance setCurrentAppearance:nil]; } @@ -127,15 +121,13 @@ - (void)testCompositeDynamicColor XCTAssertEqual(b1, b2); XCTAssertEqual(a1, a2); - if (@available(macOS 10.14, *)) { - [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; - [[value colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r1 green:&g1 blue:&b1 alpha:&a1]; - [[[NSColor systemBlueColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r2 green:&g2 blue:&b2 alpha:&a2]; - XCTAssertEqual(r1, r2); - XCTAssertEqual(g1, g2); - XCTAssertEqual(b1, b2); - XCTAssertEqual(a1, a2); - } + [NSAppearance setCurrentAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; + [[value colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r1 green:&g1 blue:&b1 alpha:&a1]; + [[[NSColor systemBlueColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r2 green:&g2 blue:&b2 alpha:&a2]; + XCTAssertEqual(r1, r2); + XCTAssertEqual(g1, g2); + XCTAssertEqual(b1, b2); + XCTAssertEqual(a1, a2); [NSAppearance setCurrentAppearance:nil]; } diff --git a/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js b/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js index ea55de56c44c96..c13166c917ed4f 100644 --- a/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js +++ b/packages/rn-tester/js/examples/PlatformColor/PlatformColorExample.js @@ -266,6 +266,27 @@ function DynamicColorsExample() { }} /> + + + DynamicColorMacOS({'{\n'} + {' '}light: 'red',{'\n'} + {' '}dark: 'blue',{'\n'} + {' '}highContrastLight: 'green',{'\n'} + {' '}highContrastDark: 'orange',{'\n'} + {'}'}) + + + ) : // ]TODO(macOS GH#774) Platform.OS === 'ios' ? (