react-native-macos 0.0.0-dd8ec0d8a → 0.0.0-e68278c58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/Libraries/AddressSanitizerCrash/RCTAddressSanitizerCrash.js +25 -0
  2. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +22 -12
  3. package/Libraries/Core/ReactNativeVersion.js +1 -1
  4. package/Libraries/StyleSheet/PlatformColorValueTypes.macos.js +16 -1
  5. package/Libraries/StyleSheet/PlatformColorValueTypesMacOS.js +2 -0
  6. package/Libraries/StyleSheet/PlatformColorValueTypesMacOS.macos.js +8 -1
  7. package/Libraries/Text/RawText/RCTRawTextShadowView.m +2 -0
  8. package/Libraries/Text/Text/RCTTextView.m +7 -9
  9. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +10 -8
  10. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +2 -0
  11. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +15 -3
  12. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +9 -0
  13. package/README.md +18 -42
  14. package/React/Base/RCTBridgeModule.h +1 -1
  15. package/React/Base/RCTConvert.m +23 -6
  16. package/React/Base/RCTImageSource.m +2 -0
  17. package/React/Base/RCTJSStackFrame.m +2 -0
  18. package/React/Base/RCTJavaScriptLoader.mm +2 -0
  19. package/React/Base/RCTKeyCommands.m +2 -0
  20. package/React/Base/RCTModuleData.mm +2 -0
  21. package/React/Base/RCTModuleMethod.mm +2 -0
  22. package/React/Base/RCTTouchEvent.m +2 -0
  23. package/React/Base/RCTVersion.m +1 -1
  24. package/React/Base/macOS/RCTPlatformDisplayLink.m +4 -1
  25. package/React/CoreModules/RCTAddressSanitizerCrashManager.h +12 -0
  26. package/React/CoreModules/RCTAddressSanitizerCrashManager.mm +18 -0
  27. package/React/CoreModules/RCTAppearance.mm +5 -1
  28. package/React/CoreModules/RCTDevLoadingView.mm +14 -9
  29. package/React/CxxModule/RCTCxxMethod.mm +2 -0
  30. package/React/Modules/RCTLayoutAnimation.m +2 -0
  31. package/React/Modules/RCTLayoutAnimationGroup.m +2 -0
  32. package/React/Views/RCTShadowView.m +2 -0
  33. package/React/Views/RCTView.h +5 -2
  34. package/React/Views/RCTView.m +22 -10
  35. package/React/Views/RCTViewManager.m +9 -8
  36. package/React/Views/SafeAreaView/RCTSafeAreaView.m +2 -0
  37. package/ReactAndroid/gradle.properties +1 -1
  38. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  39. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  40. package/package.json +3 -3
  41. package/template/package.json +1 -1
  42. package/React/Base/macOS/RCTDynamicColor.h +0 -28
  43. package/React/Base/macOS/RCTDynamicColor.m +0 -217
@@ -98,10 +98,12 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
98
98
  return _coalescingKey;
99
99
  }
100
100
 
101
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
101
102
  - (NSString *)description
102
103
  {
103
104
  return [NSString
104
105
  stringWithFormat:@"<%@: %p; name = %@; coalescing key = %hu>", [self class], self, _eventName, _coalescingKey];
105
106
  }
107
+ #endif // TODO(macOS GH#774)
106
108
 
107
109
  @end
@@ -28,7 +28,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
28
28
  RCTVersionMajor: @(0),
29
29
  RCTVersionMinor: @(0),
30
30
  RCTVersionPatch: @(0),
31
- RCTVersionPrerelease: @"dd8ec0d8a",
31
+ RCTVersionPrerelease: @"e68278c58",
32
32
  };
33
33
  });
34
34
  return __rnVersion;
@@ -50,7 +50,7 @@ static CVReturn RCTPlatformDisplayLinkCallBack(__unused CVDisplayLinkRef display
50
50
  os_unfair_lock_lock(&rctDisplayLink->_lock);
51
51
  if (rctDisplayLink->_runLoop != nil) {
52
52
  CFRunLoopRef cfRunLoop = [rctDisplayLink->_runLoop getCFRunLoop];
53
- CFRunLoopPerformBlock(cfRunLoop, kCFRunLoopDefaultMode, ^{
53
+ CFRunLoopPerformBlock(cfRunLoop, (__bridge CFArrayRef)rctDisplayLink->_modes, ^{
54
54
  [rctDisplayLink tick];
55
55
  });
56
56
  CFRunLoopWakeUp(cfRunLoop);
@@ -71,14 +71,17 @@ static CVReturn RCTPlatformDisplayLinkCallBack(__unused CVDisplayLinkRef display
71
71
 
72
72
  - (void)addToRunLoop:(NSRunLoop *)runloop forMode:(NSRunLoopMode)mode
73
73
  {
74
+ os_unfair_lock_lock(&_lock);
74
75
  _runLoop = runloop;
75
76
 
76
77
  if (_displayLink != NULL) {
77
78
  [_modes addObject:mode];
79
+ os_unfair_lock_unlock(&_lock);
78
80
  return;
79
81
  }
80
82
 
81
83
  _modes = @[mode].mutableCopy;
84
+ os_unfair_lock_unlock(&_lock);
82
85
  CVReturn ret = CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
83
86
  if (ret != kCVReturnSuccess) {
84
87
  ret = CVDisplayLinkCreateWithCGDisplay(CGMainDisplayID(), &_displayLink);
@@ -0,0 +1,12 @@
1
+ /*
2
+ *
3
+ * This source code is licensed under the MIT license found in the
4
+ * LICENSE file in the root directory of this source tree.
5
+ */
6
+
7
+ #import <React/RCTUIKit.h>
8
+ #import <React/RCTBridge.h>
9
+
10
+ @interface RCTAddressSanitizerCrashManager : NSObject <RCTBridgeModule>
11
+
12
+ @end
@@ -0,0 +1,18 @@
1
+ //
2
+ // RCTAddressSanitizerCrashManager.mm
3
+ // Pods
4
+ //
5
+
6
+ #import "RCTAddressSanitizerCrashManager.h"
7
+
8
+ @implementation RCTAddressSanitizerCrashManager
9
+
10
+ RCT_EXPORT_MODULE(ASANCrash)
11
+
12
+ RCT_EXPORT_METHOD(invokeMemoryCrash) {
13
+ char *s = (char*)malloc(100);
14
+ free(s);
15
+ strcpy(s, "Hello world!"); // AddressSanitizer: heap-use-after-free
16
+ }
17
+
18
+ @end
@@ -81,7 +81,11 @@ NSString *RCTColorSchemePreference(NSAppearance *appearance)
81
81
  return RCTAppearanceColorSchemeLight;
82
82
  }
83
83
 
84
- appearance = appearance ?: [NSAppearance currentAppearance];
84
+ if (@available(macOS 11.0, *)) {
85
+ appearance = appearance ?: [NSAppearance currentDrawingAppearance];
86
+ } else {
87
+ appearance = appearance ?: [NSAppearance currentAppearance];
88
+ }
85
89
  NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
86
90
  return appearances[appearanceName] ?: RCTAppearanceColorSchemeLight;
87
91
  }
@@ -266,16 +266,21 @@ RCT_EXPORT_METHOD(hide)
266
266
 
267
267
  - (void)showOfflineMessage
268
268
  {
269
- RCTUIColor *color = [RCTUIColor whiteColor]; // TODO(macOS GH#774)
270
- RCTUIColor *backgroundColor = [RCTUIColor blackColor]; // TODO(macOS GH#774)
271
-
272
- if ([self isDarkModeEnabled]) {
273
- color = [RCTUIColor blackColor]; // TODO(macOS GH#774)
274
- backgroundColor = [RCTUIColor whiteColor]; // TODO(macOS GH#774)
275
- }
269
+ // [TODO(macOS GH#774) - isDarkModeEnabled should only be run on the main thread
270
+ __weak __typeof(self) weakSelf = self;
271
+ RCTExecuteOnMainQueue(^{
272
+ RCTUIColor *color = [RCTUIColor whiteColor]; // TODO(macOS GH#774)
273
+ RCTUIColor *backgroundColor = [RCTUIColor blackColor]; // TODO(macOS GH#774)
274
+
275
+ if ([weakSelf isDarkModeEnabled]) {
276
+ color = [RCTUIColor blackColor]; // TODO(macOS GH#774)
277
+ backgroundColor = [RCTUIColor whiteColor]; // TODO(macOS GH#774)
278
+ }
276
279
 
277
- NSString *message = [NSString stringWithFormat:@"Connect to %@ to develop JavaScript.", RCT_PACKAGER_NAME];
278
- [self showMessage:message color:color backgroundColor:backgroundColor];
280
+ NSString *message = [NSString stringWithFormat:@"Connect to %@ to develop JavaScript.", RCT_PACKAGER_NAME];
281
+ [weakSelf showMessage:message color:color backgroundColor:backgroundColor];
282
+ });
283
+ // ]TODO(macOS GH#774)
279
284
  }
280
285
 
281
286
  - (BOOL)isDarkModeEnabled
@@ -131,9 +131,11 @@ using namespace facebook::react;
131
131
  }
132
132
  }
133
133
 
134
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
134
135
  - (NSString *)description
135
136
  {
136
137
  return [NSString stringWithFormat:@"<%@: %p; name = %s>", [self class], self, self.JSMethodName];
137
138
  }
139
+ #endif // TODO(macOS GH#774)
138
140
 
139
141
  @end
@@ -190,6 +190,7 @@ static NSString *CAMediaTimingFunctionNameFromRCTAnimationType(RCTAnimationType
190
190
  _animationType == animation.animationType;
191
191
  }
192
192
 
193
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
193
194
  - (NSString *)description
194
195
  {
195
196
  return [NSString
@@ -204,5 +205,6 @@ static NSString *CAMediaTimingFunctionNameFromRCTAnimationType(RCTAnimationType
204
205
  _initialVelocity,
205
206
  (long)_animationType];
206
207
  }
208
+ #endif // TODO(macOS GH#774)
207
209
 
208
210
  @end
@@ -64,6 +64,7 @@
64
64
  [_deletingLayoutAnimation isEqual:deletingLayoutAnimation]);
65
65
  }
66
66
 
67
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
67
68
  - (NSString *)description
68
69
  {
69
70
  return
@@ -75,5 +76,6 @@
75
76
  [_updatingLayoutAnimation description],
76
77
  [_deletingLayoutAnimation description]];
77
78
  }
79
+ #endif // TODO(macOS GH#774)
78
80
 
79
81
  @end
@@ -393,6 +393,7 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
393
393
  return self.reactTag;
394
394
  }
395
395
 
396
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
396
397
  - (NSString *)description
397
398
  {
398
399
  NSString *description = super.description;
@@ -403,6 +404,7 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
403
404
  NSStringFromCGRect(self.layoutMetrics.frame)];
404
405
  return description;
405
406
  }
407
+ #endif // TODO(macOS GH#774)
406
408
 
407
409
  - (void)addRecursiveDescriptionToString:(NSMutableString *)string atLevel:(NSUInteger)level
408
410
  {
@@ -9,7 +9,7 @@
9
9
 
10
10
  #import <React/RCTBorderStyle.h>
11
11
  #import <React/RCTComponent.h>
12
- #import <React/RCTEventDispatcher.h> // TODO(OSS Candidate ISS#2710739)
12
+ #import <React/RCTEventDispatcherProtocol.h> // TODO(OSS Candidate ISS#2710739)
13
13
  #import <React/RCTPointerEvents.h>
14
14
 
15
15
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
@@ -23,7 +23,7 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
23
23
  @interface RCTView : RCTUIView // TODO(macOS ISS#3536887)
24
24
 
25
25
  // [TODO(OSS Candidate ISS#2710739)
26
- - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher;
26
+ - (instancetype)initWithEventDispatcher:(id<RCTEventDispatcherProtocol>)eventDispatcher;
27
27
 
28
28
  - (BOOL)becomeFirstResponder;
29
29
  - (BOOL)resignFirstResponder;
@@ -128,6 +128,9 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
128
128
  /**
129
129
  * macOS Properties
130
130
  */
131
+
132
+ @property (nonatomic, assign) CATransform3D transform3D;
133
+
131
134
  @property (nonatomic, copy) RCTDirectEventBlock onDoubleClick;
132
135
  @property (nonatomic, copy) RCTDirectEventBlock onClick;
133
136
  @property (nonatomic, copy) RCTDirectEventBlock onMouseEnter;
@@ -123,7 +123,7 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // TODO(macOS I
123
123
 
124
124
  @implementation RCTView {
125
125
  RCTUIColor *_backgroundColor; // TODO(OSS Candidate ISS#2710739)
126
- RCTEventDispatcher *_eventDispatcher; // TODO(OSS Candidate ISS#2710739)
126
+ id<RCTEventDispatcherProtocol> _eventDispatcher; // TODO(OSS Candidate ISS#2710739)
127
127
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
128
128
  NSTrackingArea *_trackingArea;
129
129
  BOOL _hasMouseOver;
@@ -133,7 +133,7 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // TODO(macOS I
133
133
  }
134
134
 
135
135
  // [TODO(OSS Candidate ISS#2710739)
136
- - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
136
+ - (instancetype)initWithEventDispatcher:(id<RCTEventDispatcherProtocol>)eventDispatcher
137
137
  {
138
138
  if ((self = [self initWithFrame:CGRectZero])) {
139
139
  _eventDispatcher = eventDispatcher;
@@ -162,6 +162,9 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // TODO(macOS I
162
162
  _borderBottomEndRadius = -1;
163
163
  _borderStyle = RCTBorderStyleSolid;
164
164
  _hitTestEdgeInsets = UIEdgeInsetsZero;
165
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
166
+ _transform3D = CATransform3DIdentity;
167
+ #endif // TODO(macOS GH#774)
165
168
 
166
169
  _backgroundColor = super.backgroundColor;
167
170
  }
@@ -708,17 +711,13 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : unused)
708
711
  }
709
712
  #endif // ]TODO(macOS GH#774)
710
713
 
714
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
711
715
  - (NSString *)description
712
716
  {
713
- NSString *superDescription = super.description;
714
- NSRange semicolonRange = [superDescription rangeOfString:@";"];
715
- if (semicolonRange.location == NSNotFound) { // [TODO(macOS GH#774)
716
- return [[superDescription substringToIndex:superDescription.length - 1] stringByAppendingFormat:@"; reactTag: %@; frame = %@; layer = %@>", self.reactTag, NSStringFromCGRect(self.frame), self.layer];
717
- } else { // ]TODO(macOS GH#774)
718
- NSString *replacement = [NSString stringWithFormat:@"; reactTag: %@;", self.reactTag];
719
- return [superDescription stringByReplacingCharactersInRange:semicolonRange withString:replacement];
720
- } // TODO(macOS GH#774)
717
+ // TODO(macOS GH#774): we shouldn't make assumptions on what super's description is. Just append additional content.
718
+ return [[super description] stringByAppendingFormat:@" reactTag: %@; frame = %@; layer = %@", self.reactTag, NSStringFromCGRect(self.frame), self.layer];
721
719
  }
720
+ #endif // TODO(macOS GH#774)
722
721
 
723
722
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
724
723
  - (void)viewDidMoveToWindow
@@ -1169,6 +1168,19 @@ static CGFloat RCTDefaultIfNegativeTo(CGFloat defaultValue, CGFloat x)
1169
1168
  backgroundColor = _backgroundColor.CGColor;
1170
1169
  #endif
1171
1170
 
1171
+ #if TARGET_OS_OSX // [TODO(macOS GH#1035)
1172
+ CATransform3D transform = [self transform3D];
1173
+ CGPoint anchorPoint = [layer anchorPoint];
1174
+ if (CGPointEqualToPoint(anchorPoint, CGPointZero) && !CATransform3DEqualToTransform(transform, CATransform3DIdentity)) {
1175
+ // https://developer.apple.com/documentation/quartzcore/calayer/1410817-anchorpoint
1176
+ // This compensates for the fact that layer.anchorPoint is {0, 0} instead of {0.5, 0.5} on macOS for some reason.
1177
+ CATransform3D originAdjust = CATransform3DTranslate(CATransform3DIdentity, self.frame.size.width / 2, self.frame.size.height / 2, 0);
1178
+ transform = CATransform3DConcat(CATransform3DConcat(CATransform3DInvert(originAdjust), transform), originAdjust);
1179
+ // Enable edge antialiasing in perspective transforms
1180
+ [layer setAllowsEdgeAntialiasing:!(transform.m34 == 0.0f)];
1181
+ }
1182
+ [layer setTransform:transform];
1183
+ #endif // ]TODO(macOS GH#1035)
1172
1184
  if (useIOSBorderRendering) {
1173
1185
  layer.cornerRadius = cornerRadii.topLeft;
1174
1186
  layer.borderColor = borderColors.left;
@@ -215,15 +215,16 @@ RCT_CUSTOM_VIEW_PROPERTY(shouldRasterizeIOS, BOOL, RCTView)
215
215
 
216
216
  RCT_CUSTOM_VIEW_PROPERTY(transform, CATransform3D, RCTView)
217
217
  {
218
- #if !TARGET_OS_OSX // TODO(macOS GH#774)
218
+ #if TARGET_OS_OSX // [TODO(macOS GH#460)
219
+ CATransform3D transform = json ? [RCTConvert CATransform3D:json] : defaultView.layer.transform;
220
+ [view setTransform3D:transform];
221
+ [view setNeedsDisplay];
222
+ #else // ]TODO(macOS GH#460)]
219
223
  view.layer.transform = json ? [RCTConvert CATransform3D:json] : defaultView.layer.transform;
220
- // Enable edge antialiasing in perspective transforms
221
- view.layer.allowsEdgeAntialiasing = !(view.layer.transform.m34 == 0.0f);
222
- #elif TARGET_OS_OSX // [TODO(macOS GH#774)
223
- view.layer.sublayerTransform = json ? [RCTConvert CATransform3D:json] : defaultView.layer.sublayerTransform;
224
- // TODO: Improve this by enabling edge antialiasing only for transforms with rotation or skewing
225
- view.layer.edgeAntialiasingMask = !CATransform3DIsIdentity(view.layer.sublayerTransform) ? kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge : 0;
226
- #endif // ]TODO(macOS GH#774)
224
+ // Enable edge antialiasing in rotation, skew, or perspective transforms
225
+ view.layer.allowsEdgeAntialiasing =
226
+ view.layer.transform.m12 != 0.0f || view.layer.transform.m21 != 0.0f || view.layer.transform.m34 != 0.0f;
227
+ #endif // [TODO(macOS GH#460)]
227
228
  }
228
229
 
229
230
  RCT_CUSTOM_VIEW_PROPERTY(accessibilityRole, UIAccessibilityTraits, RCTView)
@@ -30,6 +30,7 @@
30
30
  RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
31
31
  RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
32
32
 
33
+ #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
33
34
  - (NSString *)description
34
35
  {
35
36
  NSString *superDescription = [super description];
@@ -44,6 +45,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
44
45
  NSStringFromUIEdgeInsets([self safeAreaInsetsIfSupportedAndEnabled]),
45
46
  NSStringFromUIEdgeInsets(_currentSafeAreaInsets)];
46
47
  }
48
+ #endif // TODO(macOS GH#774)
47
49
 
48
50
  - (BOOL)isSupportedByOS
49
51
  {
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.0.0-dd8ec0d8a
1
+ VERSION_NAME=0.0.0-e68278c58
2
2
  GROUP=com.facebook.react
3
3
 
4
4
  POM_NAME=ReactNative
@@ -22,5 +22,5 @@ public class ReactNativeVersion {
22
22
  "major", 0,
23
23
  "minor", 0,
24
24
  "patch", 0,
25
- "prerelease", "dd8ec0d8a");
25
+ "prerelease", "e68278c58");
26
26
  }
@@ -22,7 +22,7 @@ constexpr struct {
22
22
  int32_t Major = 0;
23
23
  int32_t Minor = 0;
24
24
  int32_t Patch = 0;
25
- std::string_view Prerelease = "dd8ec0d8a";
25
+ std::string_view Prerelease = "e68278c58";
26
26
  } ReactNativeVersion;
27
27
 
28
28
  } // namespace facebook::react
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.0.0-dd8ec0d8a",
3
+ "version": "0.0.0-e68278c58",
4
4
  "bin": "./cli.js",
5
- "description": "[Microsoft Fork] A framework for building native apps using React",
5
+ "description": "React Native for macOS",
6
6
  "license": "MIT",
7
7
  "repository": "git@github.com:microsoft/react-native-macos.git",
8
8
  "engines": {
@@ -144,7 +144,7 @@
144
144
  "eslint-plugin-jest": "22.4.1",
145
145
  "eslint-plugin-jsx-a11y": "6.2.1",
146
146
  "eslint-plugin-prettier": "2.6.2",
147
- "eslint-plugin-react": "7.21.5",
147
+ "eslint-plugin-react": "7.28.0",
148
148
  "eslint-plugin-react-hooks": "^4.2.0",
149
149
  "eslint-plugin-react-native": "3.10.0",
150
150
  "eslint-plugin-relay": "1.8.1",
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "react": "17.0.2",
15
15
  "react-native-macos": "1000.0.0",
16
- "react-native": "0.0.0-dd8ec0d8a"
16
+ "react-native": "0.0.0-e68278c58"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@babel/core": "^7.12.9",
@@ -1,28 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- // TODO(macOS GH#774)
9
-
10
- #include <AppKit/AppKit.h>
11
-
12
- /** A dynamic, theme aware subclass of NSColor.
13
- * It is a tuple that contains two NSColors for light and dark
14
- * theme appearances. Like a semantic NSColor or an
15
- * asset catalog named NSColor, the effective color values
16
- * returned by the various methods and properties vary
17
- * depending on the current [NSAppearance currentAppearance].
18
- */
19
- @interface RCTDynamicColor : NSColor
20
-
21
- /** Inits a RCTDynamicColor with a pair of NSColors
22
- * @param aquaColor the color to use when the current appearance is not dark
23
- * @param darkAquaColor the color to use when the current appearance is dark
24
- */
25
- - (instancetype)initWithAquaColor:(NSColor *)aquaColor
26
- darkAquaColor:(nullable NSColor *)darkAquaColor;
27
-
28
- @end
@@ -1,217 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- // TODO(macOS GH#774)
9
-
10
- #import "RCTDynamicColor.h"
11
-
12
- #define RCT_FORWARD_PROPERTY( PROP, TYPE ) \
13
- - (TYPE)PROP { return [[self effectiveColor] PROP]; }
14
-
15
- static NSString *const RCTAquaColor = @"aquaColor";
16
- static NSString *const RCTDarkAquaColor = @"darkAquaColor";
17
-
18
- @implementation RCTDynamicColor
19
- {
20
- NSColor *_aquaColor;
21
- NSColor *_darkAquaColor;
22
- }
23
-
24
- - (instancetype)initWithAquaColor:(NSColor *)aquaColor
25
- darkAquaColor:(NSColor *)darkAquaColor
26
- {
27
- self = [super init];
28
- if (self) {
29
- _aquaColor = [aquaColor copy];
30
- _darkAquaColor = [darkAquaColor copy];
31
- }
32
- return self;
33
- }
34
-
35
- + (BOOL)supportsSecureCoding
36
- {
37
- return YES;
38
- }
39
-
40
- - (instancetype)initWithCoder:(NSCoder *)coder
41
- {
42
- self = [super initWithCoder:coder];
43
- if (self) {
44
- _aquaColor = [coder decodeObjectOfClass:[NSColor class] forKey:RCTAquaColor];
45
- _darkAquaColor = [coder decodeObjectOfClass:[NSColor class] forKey:RCTDarkAquaColor];
46
- }
47
- return self;
48
- }
49
-
50
- - (void)encodeWithCoder:(NSCoder *)aCoder
51
- {
52
- [super encodeWithCoder:aCoder];
53
- [aCoder encodeObject:_aquaColor forKey:RCTAquaColor];
54
- if (_darkAquaColor) {
55
- [aCoder encodeObject:_darkAquaColor forKey:RCTDarkAquaColor];
56
- }
57
- }
58
-
59
- - (NSColor *)effectiveColor
60
- {
61
- NSColor *effectiveColor = _aquaColor;
62
- NSAppearance *appearance = [NSAppearance currentAppearance] ?: [NSApp effectiveAppearance];
63
-
64
- NSAppearanceName appearanceName = [appearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
65
-
66
- if (_darkAquaColor != nil && [appearanceName isEqualToString:NSAppearanceNameDarkAqua]) {
67
- effectiveColor = _darkAquaColor;
68
- }
69
- return effectiveColor;
70
- }
71
-
72
- RCT_FORWARD_PROPERTY(colorSpace, NSColorSpace *)
73
- - (NSColor *)colorUsingColorSpace:(NSColorSpace *)space
74
- {
75
- return [[self effectiveColor] colorUsingColorSpace:space];
76
- }
77
-
78
- RCT_FORWARD_PROPERTY(colorSpaceName, NSColorSpaceName)
79
- - (NSColor *)colorUsingColorSpaceName:(NSColorSpaceName)name
80
- {
81
- return [[self effectiveColor] colorUsingColorSpaceName:name];
82
- }
83
-
84
- RCT_FORWARD_PROPERTY(numberOfComponents, NSInteger)
85
- - (void)getComponents:(CGFloat *)components
86
- {
87
- return [[self effectiveColor] getComponents:components];
88
- }
89
-
90
- #pragma mark - RGB colorspace
91
-
92
- RCT_FORWARD_PROPERTY(redComponent, CGFloat)
93
- RCT_FORWARD_PROPERTY(greenComponent, CGFloat)
94
- RCT_FORWARD_PROPERTY(blueComponent, CGFloat)
95
-
96
- - (void)getRed:(nullable CGFloat *)red green:(nullable CGFloat *)green blue:(nullable CGFloat *)blue alpha:(nullable CGFloat *)alpha
97
- {
98
- return [[self effectiveColor] getRed:red green:green blue:blue alpha:alpha];
99
- }
100
-
101
- #pragma mark - HSB colorspace
102
-
103
- RCT_FORWARD_PROPERTY(hueComponent, CGFloat)
104
- RCT_FORWARD_PROPERTY(saturationComponent, CGFloat)
105
- RCT_FORWARD_PROPERTY(brightnessComponent, CGFloat)
106
-
107
- - (void)getHue:(nullable CGFloat *)hue saturation:(nullable CGFloat *)saturation brightness:(nullable CGFloat *)brightness alpha:(nullable CGFloat *)alpha
108
- {
109
- return [[self effectiveColor] getHue:hue saturation:saturation brightness:brightness alpha:alpha];
110
- }
111
-
112
- #pragma mark - Gray colorspace
113
-
114
- RCT_FORWARD_PROPERTY(whiteComponent, CGFloat)
115
-
116
- - (void)getWhite:(CGFloat *)white alpha:(CGFloat *)alpha
117
- {
118
- return [[self effectiveColor] getWhite:white alpha:alpha];
119
- }
120
-
121
- #pragma mark - CMYK colorspace
122
-
123
- RCT_FORWARD_PROPERTY(cyanComponent, CGFloat)
124
- RCT_FORWARD_PROPERTY(magentaComponent, CGFloat)
125
- RCT_FORWARD_PROPERTY(yellowComponent, CGFloat)
126
- RCT_FORWARD_PROPERTY(blackComponent, CGFloat)
127
-
128
- - (void)getCyan:(nullable CGFloat *)cyan magenta:(nullable CGFloat *)magenta yellow:(nullable CGFloat *)yellow black:(nullable CGFloat *)black alpha:(nullable CGFloat *)alpha
129
- {
130
- return [[self effectiveColor] getCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha];
131
- }
132
-
133
- #pragma mark - Others
134
-
135
- RCT_FORWARD_PROPERTY(alphaComponent, CGFloat)
136
- RCT_FORWARD_PROPERTY(CGColor, CGColorRef)
137
- RCT_FORWARD_PROPERTY(catalogNameComponent, NSColorListName)
138
- RCT_FORWARD_PROPERTY(colorNameComponent, NSColorName)
139
- RCT_FORWARD_PROPERTY(localizedCatalogNameComponent, NSColorListName)
140
- RCT_FORWARD_PROPERTY(localizedColorNameComponent, NSString *)
141
-
142
- - (void)setStroke
143
- {
144
- [[self effectiveColor] setStroke];
145
- }
146
-
147
- - (void)setFill
148
- {
149
- [[self effectiveColor] setFill];
150
- }
151
-
152
- - (void)set
153
- {
154
- [[self effectiveColor] set];
155
- }
156
-
157
- - (nullable NSColor *)highlightWithLevel:(CGFloat)val
158
- {
159
- return [[self effectiveColor] highlightWithLevel:val];
160
- }
161
-
162
- - (NSColor *)shadowWithLevel:(CGFloat)val
163
- {
164
- return [[self effectiveColor] shadowWithLevel:val];
165
- }
166
-
167
- - (NSColor *)colorWithAlphaComponent:(CGFloat)alpha
168
- {
169
- return [[self effectiveColor] colorWithAlphaComponent:alpha];
170
- }
171
-
172
- - (nullable NSColor *)blendedColorWithFraction:(CGFloat)fraction ofColor:(NSColor *)color
173
- {
174
- return [[self effectiveColor] blendedColorWithFraction:fraction ofColor:color];
175
- }
176
-
177
- - (NSColor *)colorWithSystemEffect:(NSColorSystemEffect)systemEffect NS_AVAILABLE_MAC(10_14)
178
- {
179
- NSColor *aquaColorWithSystemEffect = [_aquaColor colorWithSystemEffect:systemEffect];
180
- NSColor *darkAquaColorWithSystemEffect = [_darkAquaColor colorWithSystemEffect:systemEffect];
181
- return [[RCTDynamicColor alloc] initWithAquaColor:aquaColorWithSystemEffect darkAquaColor:darkAquaColorWithSystemEffect];
182
- }
183
-
184
- - (NSUInteger)hash
185
- {
186
- const NSUInteger prime = 31;
187
- NSUInteger result = 1;
188
- result = prime * result + [_aquaColor hash];
189
- result = prime * result + [_darkAquaColor hash];
190
- return result;
191
- }
192
-
193
- - (BOOL)isEqual:(id)other {
194
- if (other == self) {
195
- return YES;
196
- }
197
-
198
- return other != nil && [other isKindOfClass:[self class]] && [self isEqualToDynamicColor:other];
199
- }
200
-
201
- - (BOOL)isEqualToDynamicColor:(RCTDynamicColor *)other {
202
- if (self == other) {
203
- return YES;
204
- }
205
-
206
- if ([_aquaColor isNotEqualTo:other->_aquaColor]) {
207
- return NO;
208
- }
209
-
210
- if ([_darkAquaColor isNotEqualTo:other->_darkAquaColor]) {
211
- return NO;
212
- }
213
-
214
- return YES;
215
- }
216
-
217
- @end