react-native-macos 0.81.9 → 0.81.12
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.
- package/CHANGELOG.md +8 -0
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/Text/TextInput/Multiline/RCTUITextView.mm +34 -0
- package/Libraries/Text/TextInput/Multiline/RCTWrappedTextView.m +16 -0
- package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +2 -0
- package/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +27 -3
- package/React/Base/RCTConvert.mm +2 -1
- package/React/Base/RCTUIKit.h +2 -0
- package/React/Base/RCTUtils.h +6 -0
- package/React/Base/RCTUtils.mm +1 -1
- package/React/Base/RCTVersion.m +1 -1
- package/React/Base/macOS/RCTUIKit.m +16 -0
- package/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +21 -0
- package/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm +5 -1
- package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +233 -7
- package/React/Views/RCTViewManager.m +4 -0
- package/ReactAndroid/gradle.properties +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.kt +1 -1
- package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
- package/ReactCommon/react/renderer/core/ShadowNode.cpp +29 -19
- package/ReactCommon/react/renderer/core/ShadowNodeFamily.h +2 -0
- package/ReactCommon/react/renderer/uimanager/UIManager.cpp +62 -53
- package/ReactCommon/react/renderer/uimanager/tests/FabricUIManagerTest.cpp +179 -3
- package/package.json +3 -3
- package/react-native.config.js +31 -7
package/CHANGELOG.md
ADDED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
NSArray<NSString *> *_acceptDragAndDropTypes;
|
|
28
28
|
#if TARGET_OS_OSX // [macOS
|
|
29
29
|
BOOL _enableFocusRing;
|
|
30
|
+
BOOL _enabled;
|
|
30
31
|
NSArray<NSPasteboardType> *_readablePasteboardTypes;
|
|
31
32
|
#endif // macOS]
|
|
32
33
|
}
|
|
@@ -66,6 +67,7 @@ static RCTUIColor *defaultPlaceholderColor(void) // [macOS]
|
|
|
66
67
|
self.canDrawSubviewsIntoLayer = YES;
|
|
67
68
|
self.allowsUndo = YES;
|
|
68
69
|
_enableFocusRing = YES;
|
|
70
|
+
_enabled = YES;
|
|
69
71
|
#endif // macOS]
|
|
70
72
|
|
|
71
73
|
_textInputDelegateAdapter = [[RCTBackedTextViewDelegateAdapter alloc] initWithTextView:self];
|
|
@@ -280,6 +282,38 @@ static RCTUIColor *defaultPlaceholderColor(void) // [macOS]
|
|
|
280
282
|
{
|
|
281
283
|
return _enableFocusRing;
|
|
282
284
|
}
|
|
285
|
+
|
|
286
|
+
- (BOOL)isEnabled
|
|
287
|
+
{
|
|
288
|
+
return _enabled;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
- (void)setEnabled:(BOOL)enabled
|
|
292
|
+
{
|
|
293
|
+
if (_enabled != enabled) {
|
|
294
|
+
_enabled = enabled;
|
|
295
|
+
|
|
296
|
+
// NSTextView has no enabled state. Behave like a disabled NSTextField: report AXEnabled = NO, refuse first
|
|
297
|
+
// responder (see -acceptsFirstResponder) and end editing if the view is focused.
|
|
298
|
+
self.accessibilityEnabled = enabled;
|
|
299
|
+
if (!enabled && self.window.firstResponder == self) {
|
|
300
|
+
[self.window makeFirstResponder:nil];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
- (BOOL)acceptsFirstResponder
|
|
306
|
+
{
|
|
307
|
+
return _enabled && [super acceptsFirstResponder];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
- (void)setAccessibilityState:(NSDictionary<NSString *, id> *)accessibilityState
|
|
311
|
+
{
|
|
312
|
+
// Paper routes `accessibilityState` to the backed text view through -[RCTBaseTextInputView reactAccessibilityElement].
|
|
313
|
+
[super setAccessibilityState:accessibilityState];
|
|
314
|
+
id disabled = accessibilityState[@"disabled"];
|
|
315
|
+
self.enabled = !([disabled isKindOfClass:[NSNumber class]] && [disabled boolValue]);
|
|
316
|
+
}
|
|
283
317
|
#endif // macOS]
|
|
284
318
|
|
|
285
319
|
- (void)setDefaultTextAttributes:(NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes
|
|
@@ -108,6 +108,12 @@
|
|
|
108
108
|
return _forwardingTextView;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
- (BOOL)canBecomeKeyView
|
|
112
|
+
{
|
|
113
|
+
// The forwarding text view is the Tab stop; this wrapper would otherwise add a second one.
|
|
114
|
+
return NO;
|
|
115
|
+
}
|
|
116
|
+
|
|
111
117
|
- (BOOL)acceptsFirstResponder
|
|
112
118
|
{
|
|
113
119
|
return _forwardingTextView.acceptsFirstResponder;
|
|
@@ -123,6 +129,16 @@
|
|
|
123
129
|
return [_forwardingTextView resignFirstResponder];
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
- (BOOL)isEnabled
|
|
133
|
+
{
|
|
134
|
+
return _forwardingTextView.isEnabled;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
- (void)setEnabled:(BOOL)enabled
|
|
138
|
+
{
|
|
139
|
+
_forwardingTextView.enabled = enabled;
|
|
140
|
+
}
|
|
141
|
+
|
|
126
142
|
#pragma mark -
|
|
127
143
|
#pragma mark Text Input delegate forwarding
|
|
128
144
|
|
|
@@ -40,6 +40,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
40
40
|
@property (nonatomic, assign) BOOL textWasPasted;
|
|
41
41
|
@property (nonatomic, readonly) NSResponder *responder;
|
|
42
42
|
@property (nonatomic, assign) BOOL enableFocusRing;
|
|
43
|
+
// Driven by `accessibilityState.disabled`; `editable` only controls whether the text can be changed.
|
|
44
|
+
@property (nonatomic, assign, getter=isEnabled) BOOL enabled;
|
|
43
45
|
#endif // macOS]
|
|
44
46
|
@property (nonatomic, assign, readonly) BOOL dictationRecognizing;
|
|
45
47
|
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
|
|
@@ -391,18 +391,42 @@
|
|
|
391
391
|
|
|
392
392
|
- (BOOL)isEditable
|
|
393
393
|
{
|
|
394
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
394
395
|
return self.isEnabled;
|
|
396
|
+
#else // [macOS
|
|
397
|
+
return [super isEditable];
|
|
398
|
+
#endif // macOS]
|
|
395
399
|
}
|
|
396
400
|
|
|
397
401
|
- (void)setEditable:(BOOL)editable
|
|
398
402
|
{
|
|
399
|
-
#if TARGET_OS_OSX // [macOS
|
|
400
|
-
|
|
403
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
404
|
+
self.enabled = editable;
|
|
405
|
+
#else // [macOS
|
|
406
|
+
// On macOS read-only text remains selectable and focusable, matching desktop behavior rather than iOS's disabled
|
|
407
|
+
// field. `accessibilityState.disabled` disables it; the super call sets NSTextFieldCell's editable state.
|
|
401
408
|
[super setEditable:editable];
|
|
409
|
+
self.selectable = YES;
|
|
402
410
|
#endif // macOS]
|
|
403
|
-
self.enabled = editable;
|
|
404
411
|
}
|
|
405
412
|
|
|
413
|
+
#if TARGET_OS_OSX // [macOS
|
|
414
|
+
- (BOOL)acceptsFirstResponder
|
|
415
|
+
{
|
|
416
|
+
// NSTextField refuses first responder when it is not editable, which would make read-only fields unreachable with
|
|
417
|
+
// Tab. Accept it while the field is enabled and selectable; disabled fields are skipped.
|
|
418
|
+
return self.isEnabled && self.isSelectable;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
- (void)setAccessibilityState:(NSDictionary<NSString *, id> *)accessibilityState
|
|
422
|
+
{
|
|
423
|
+
// Paper routes `accessibilityState` to the backed text field through -[RCTBaseTextInputView reactAccessibilityElement].
|
|
424
|
+
[super setAccessibilityState:accessibilityState];
|
|
425
|
+
id disabled = accessibilityState[@"disabled"];
|
|
426
|
+
self.enabled = !([disabled isKindOfClass:[NSNumber class]] && [disabled boolValue]);
|
|
427
|
+
}
|
|
428
|
+
#endif // macOS]
|
|
429
|
+
|
|
406
430
|
#if !TARGET_OS_OSX // [macOS]
|
|
407
431
|
- (void)setSecureTextEntry:(BOOL)secureTextEntry
|
|
408
432
|
{
|
package/React/Base/RCTConvert.mm
CHANGED
|
@@ -1664,6 +1664,7 @@ RCT_ENUM_CONVERTER(
|
|
|
1664
1664
|
@"tab": NSAccessibilityButtonRole, // no exact match on macOS
|
|
1665
1665
|
@"tablist": NSAccessibilityTabGroupRole,
|
|
1666
1666
|
@"text": NSAccessibilityStaticTextRole, // also a legacy iOS accessibilityTraits
|
|
1667
|
+
@"textbox": NSAccessibilityTextFieldRole,
|
|
1667
1668
|
@"timer": NSAccessibilityStaticTextRole, // no exact match on macOS
|
|
1668
1669
|
@"toolbar": NSAccessibilityToolbarRole,
|
|
1669
1670
|
// Roles/traits that are macOS specific and are used by some of the core components (Lists):
|
|
@@ -1689,7 +1690,7 @@ RCT_ENUM_CONVERTER(
|
|
|
1689
1690
|
return useAriaMappings ? [RCTConvert accessibilityRoleFromAriaRole:json] : [RCTConvert accessibilityRoleFromTrait:json];
|
|
1690
1691
|
} else if ([json isKindOfClass:[NSArray class]]) {
|
|
1691
1692
|
for (NSString *trait in json) {
|
|
1692
|
-
NSString *accessibilityRole = useAriaMappings ? [RCTConvert accessibilityRoleFromAriaRole:
|
|
1693
|
+
NSString *accessibilityRole = useAriaMappings ? [RCTConvert accessibilityRoleFromAriaRole:trait] : [RCTConvert accessibilityRoleFromTrait:trait];
|
|
1693
1694
|
if (![accessibilityRole isEqualToString:NSAccessibilityUnknownRole]) {
|
|
1694
1695
|
return accessibilityRole;
|
|
1695
1696
|
}
|
package/React/Base/RCTUIKit.h
CHANGED
package/React/Base/RCTUtils.h
CHANGED
|
@@ -142,6 +142,12 @@ RCT_EXTERN NSURL *RCTDataURL(NSString *mimeType, NSData *data);
|
|
|
142
142
|
// Gzip functionality - compression level in range 0 - 1 (-1 for default)
|
|
143
143
|
RCT_EXTERN NSData *__nullable RCTGzipData(NSData *__nullable data, float level);
|
|
144
144
|
|
|
145
|
+
// [macOS
|
|
146
|
+
// Determines whether data is already gzipped. Declared here (rather than only in
|
|
147
|
+
// RCTUtils.mm) so it keeps C linkage and can be called from .m unit tests.
|
|
148
|
+
RCT_EXTERN BOOL RCTIsGzippedData(NSData *__nullable data);
|
|
149
|
+
// macOS]
|
|
150
|
+
|
|
145
151
|
// Returns the relative path within the main bundle for an absolute URL
|
|
146
152
|
// (or nil, if the URL does not specify a path within the main bundle)
|
|
147
153
|
RCT_EXTERN NSString *__nullable RCTBundlePathForURL(NSURL *__nullable URL);
|
package/React/Base/RCTUtils.mm
CHANGED
|
@@ -781,7 +781,7 @@ NSURL *RCTDataURL(NSString *mimeType, NSData *data)
|
|
|
781
781
|
[data base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)0]]];
|
|
782
782
|
}
|
|
783
783
|
|
|
784
|
-
|
|
784
|
+
// [macOS] RCTUtils.h supplies C linkage for Objective-C callers.
|
|
785
785
|
BOOL RCTIsGzippedData(NSData *__nullable data)
|
|
786
786
|
{
|
|
787
787
|
UInt8 *bytes = (UInt8 *)data.bytes;
|
package/React/Base/RCTVersion.m
CHANGED
|
@@ -168,6 +168,7 @@ void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath)
|
|
|
168
168
|
BOOL _respondsToDisplayLayer;
|
|
169
169
|
CATransform3D _transform3D;
|
|
170
170
|
BOOL _hasCustomTransform3D;
|
|
171
|
+
NSEdgeInsets _lastSafeAreaInsets;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
+ (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key
|
|
@@ -204,6 +205,15 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
|
|
|
204
205
|
return self;
|
|
205
206
|
}
|
|
206
207
|
|
|
208
|
+
- (void)rct_updateSafeAreaInsets
|
|
209
|
+
{
|
|
210
|
+
NSEdgeInsets insets = self.safeAreaInsets;
|
|
211
|
+
if (!NSEdgeInsetsEqual(insets, _lastSafeAreaInsets)) {
|
|
212
|
+
_lastSafeAreaInsets = insets;
|
|
213
|
+
[self safeAreaInsetsDidChange];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
207
217
|
- (instancetype)initWithFrame:(NSRect)frameRect
|
|
208
218
|
{
|
|
209
219
|
return RCTUIViewCommonInit([super initWithFrame:frameRect]);
|
|
@@ -243,6 +253,7 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
|
|
|
243
253
|
- (void)viewDidMoveToWindow
|
|
244
254
|
{
|
|
245
255
|
[self didMoveToWindow];
|
|
256
|
+
[self rct_updateSafeAreaInsets];
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
- (BOOL)mouseDownCanMoveWindow{
|
|
@@ -353,6 +364,7 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
|
|
|
353
364
|
{
|
|
354
365
|
[super layout];
|
|
355
366
|
if (self.window != nil) {
|
|
367
|
+
[self rct_updateSafeAreaInsets];
|
|
356
368
|
[self layoutSubviews];
|
|
357
369
|
}
|
|
358
370
|
}
|
|
@@ -425,6 +437,10 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
|
|
|
425
437
|
[super layout];
|
|
426
438
|
}
|
|
427
439
|
|
|
440
|
+
- (void)safeAreaInsetsDidChange
|
|
441
|
+
{
|
|
442
|
+
}
|
|
443
|
+
|
|
428
444
|
- (void)setNeedsDisplay
|
|
429
445
|
{
|
|
430
446
|
self.needsDisplay = YES;
|
|
@@ -255,6 +255,20 @@ static NSSet<NSNumber *> *returnKeyTypesSet;
|
|
|
255
255
|
|
|
256
256
|
#pragma mark - RCTViewComponentView overrides
|
|
257
257
|
|
|
258
|
+
#if TARGET_OS_OSX // [macOS
|
|
259
|
+
// The backed text input owns focus and accessibility; keep this host out of the key view loop to avoid a second Tab
|
|
260
|
+
// stop. `focus()` targets the backed view.
|
|
261
|
+
- (BOOL)canBecomeKeyView
|
|
262
|
+
{
|
|
263
|
+
return NO;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
- (BOOL)acceptsFirstResponder
|
|
267
|
+
{
|
|
268
|
+
return NO;
|
|
269
|
+
}
|
|
270
|
+
#endif // macOS]
|
|
271
|
+
|
|
258
272
|
- (NSObject *)accessibilityElement
|
|
259
273
|
{
|
|
260
274
|
return _backedTextInputView;
|
|
@@ -305,6 +319,13 @@ static NSSet<NSNumber *> *returnKeyTypesSet;
|
|
|
305
319
|
_backedTextInputView.editable = newTextInputProps.traits.editable;
|
|
306
320
|
}
|
|
307
321
|
|
|
322
|
+
#if TARGET_OS_OSX // [macOS
|
|
323
|
+
// `accessibilityState.disabled` disables the backed text input; `editable={false}` only makes it read-only.
|
|
324
|
+
if (newTextInputProps.accessibilityState != oldTextInputProps.accessibilityState) {
|
|
325
|
+
_backedTextInputView.enabled = !newTextInputProps.accessibilityState.value_or(AccessibilityState{}).disabled;
|
|
326
|
+
}
|
|
327
|
+
#endif // macOS]
|
|
328
|
+
|
|
308
329
|
#if !TARGET_OS_OSX // [macOS]
|
|
309
330
|
if (newTextInputProps.multiline &&
|
|
310
331
|
newTextInputProps.traits.dataDetectorTypes != oldTextInputProps.traits.dataDetectorTypes) {
|
|
@@ -33,8 +33,12 @@ void RCTCopyBackedTextInput(
|
|
|
33
33
|
toTextInput.accessibilityHelp = fromTextInput.accessibilityHelp;
|
|
34
34
|
toTextInput.accessibilityIdentifier = fromTextInput.accessibilityIdentifier;
|
|
35
35
|
toTextInput.accessibilityLabel = fromTextInput.accessibilityLabel;
|
|
36
|
-
|
|
36
|
+
// An unset role reads back as NSAccessibilityUnknownRole; copying it would hide the new view's default role.
|
|
37
|
+
if (![fromTextInput.accessibilityRole isEqualToString:NSAccessibilityUnknownRole]) {
|
|
38
|
+
toTextInput.accessibilityRole = fromTextInput.accessibilityRole;
|
|
39
|
+
}
|
|
37
40
|
toTextInput.autoresizingMask = fromTextInput.autoresizingMask;
|
|
41
|
+
toTextInput.enabled = fromTextInput.enabled;
|
|
38
42
|
#endif // macOS]
|
|
39
43
|
#if TARGET_OS_IOS // [macOS] [visionOS]
|
|
40
44
|
toTextInput.inputAccessoryView = fromTextInput.inputAccessoryView;
|
|
@@ -44,6 +44,189 @@ using namespace facebook::react;
|
|
|
44
44
|
|
|
45
45
|
const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
|
|
46
46
|
|
|
47
|
+
#if TARGET_OS_OSX // [macOS
|
|
48
|
+
// The role an accessibility element reports when React Native does not override it. NSControl subclasses, such as the
|
|
49
|
+
// NSTextField behind a single-line TextInput, report their role through their cell; the control's own
|
|
50
|
+
// `accessibilityRole` getter returns NSAccessibilityUnknownRole until a role is set explicitly.
|
|
51
|
+
static NSAccessibilityRole RCTDefaultAccessibilityRoleForElement(NSView *element)
|
|
52
|
+
{
|
|
53
|
+
if ([element isKindOfClass:[NSControl class]]) {
|
|
54
|
+
NSAccessibilityRole cellRole = ((NSControl *)element).cell.accessibilityRole;
|
|
55
|
+
if (cellRole != nil) {
|
|
56
|
+
return cellRole;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return NSAccessibilityUnknownRole;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Fabric keeps these mappings local instead of depending on Paper's RCTConvert.
|
|
63
|
+
static NSAccessibilityRole RCTAccessibilityRoleFromString(NSString *role, BOOL useAriaMappings)
|
|
64
|
+
{
|
|
65
|
+
if (useAriaMappings && [role isEqualToString:@"rowgroup"]) {
|
|
66
|
+
return nil;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static NSDictionary<NSString *, NSAccessibilityRole> *ariaRoleToNSAccessibilityRole;
|
|
70
|
+
static NSDictionary<NSString *, NSAccessibilityRole> *traitOrRoleToAccessibilityRole;
|
|
71
|
+
static dispatch_once_t onceToken;
|
|
72
|
+
dispatch_once(&onceToken, ^{
|
|
73
|
+
ariaRoleToNSAccessibilityRole = @{
|
|
74
|
+
@"alert" : NSAccessibilityGroupRole,
|
|
75
|
+
@"alertdialog" : NSAccessibilityGroupRole,
|
|
76
|
+
@"application" : NSAccessibilityGroupRole,
|
|
77
|
+
@"article" : NSAccessibilityGroupRole,
|
|
78
|
+
@"banner" : NSAccessibilityGroupRole,
|
|
79
|
+
@"button" : NSAccessibilityButtonRole,
|
|
80
|
+
@"cell" : NSAccessibilityCellRole,
|
|
81
|
+
@"checkbox" : NSAccessibilityCheckBoxRole,
|
|
82
|
+
@"columnheader" : NSAccessibilityCellRole,
|
|
83
|
+
@"combobox" : NSAccessibilityComboBoxRole,
|
|
84
|
+
@"complementary" : NSAccessibilityGroupRole,
|
|
85
|
+
@"contentinfo" : NSAccessibilityGroupRole,
|
|
86
|
+
@"definition" : NSAccessibilityGroupRole,
|
|
87
|
+
@"dialog" : NSAccessibilityGroupRole,
|
|
88
|
+
@"directory" : NSAccessibilityListRole,
|
|
89
|
+
@"document" : NSAccessibilityGroupRole,
|
|
90
|
+
@"feed" : NSAccessibilityGroupRole,
|
|
91
|
+
@"figure" : NSAccessibilityGroupRole,
|
|
92
|
+
@"form" : NSAccessibilityGroupRole,
|
|
93
|
+
@"grid" : NSAccessibilityTableRole,
|
|
94
|
+
@"gridcell" : NSAccessibilityCellRole,
|
|
95
|
+
@"group" : NSAccessibilityGroupRole,
|
|
96
|
+
@"heading" : NSAccessibilityStaticTextRole,
|
|
97
|
+
@"image" : NSAccessibilityImageRole,
|
|
98
|
+
@"img" : NSAccessibilityImageRole,
|
|
99
|
+
@"link" : NSAccessibilityLinkRole,
|
|
100
|
+
@"list" : NSAccessibilityListRole,
|
|
101
|
+
@"listbox" : NSAccessibilityListRole,
|
|
102
|
+
@"listitem" : NSAccessibilityGroupRole,
|
|
103
|
+
@"log" : NSAccessibilityGroupRole,
|
|
104
|
+
@"main" : NSAccessibilityGroupRole,
|
|
105
|
+
@"marquee" : NSAccessibilityGroupRole,
|
|
106
|
+
@"math" : NSAccessibilityGroupRole,
|
|
107
|
+
@"menu" : NSAccessibilityMenuRole,
|
|
108
|
+
@"menubar" : NSAccessibilityMenuBarRole,
|
|
109
|
+
@"menuitem" : NSAccessibilityMenuItemRole,
|
|
110
|
+
@"menuitemcheckbox" : NSAccessibilityMenuItemRole,
|
|
111
|
+
@"menuitemradio" : NSAccessibilityMenuItemRole,
|
|
112
|
+
@"meter" : NSAccessibilityLevelIndicatorRole,
|
|
113
|
+
@"navigation" : NSAccessibilityGroupRole,
|
|
114
|
+
@"none" : NSAccessibilityGroupRole,
|
|
115
|
+
@"note" : NSAccessibilityGroupRole,
|
|
116
|
+
@"option" : NSAccessibilityStaticTextRole,
|
|
117
|
+
@"presentation" : NSAccessibilityGroupRole,
|
|
118
|
+
@"progressbar" : NSAccessibilityProgressIndicatorRole,
|
|
119
|
+
@"radio" : NSAccessibilityRadioButtonRole,
|
|
120
|
+
@"radiogroup" : NSAccessibilityRadioGroupRole,
|
|
121
|
+
@"region" : NSAccessibilityGroupRole,
|
|
122
|
+
@"row" : NSAccessibilityRowRole,
|
|
123
|
+
@"rowheader" : NSAccessibilityCellRole,
|
|
124
|
+
@"scrollbar" : NSAccessibilityScrollBarRole,
|
|
125
|
+
@"search" : NSAccessibilityGroupRole,
|
|
126
|
+
@"searchbox" : NSAccessibilityTextFieldRole,
|
|
127
|
+
@"separator" : NSAccessibilitySplitterRole,
|
|
128
|
+
@"slider" : NSAccessibilitySliderRole,
|
|
129
|
+
@"spinbutton" : NSAccessibilityIncrementorRole,
|
|
130
|
+
@"status" : NSAccessibilityGroupRole,
|
|
131
|
+
@"switch" : NSAccessibilityCheckBoxRole,
|
|
132
|
+
@"tab" : NSAccessibilityRadioButtonRole,
|
|
133
|
+
@"table" : NSAccessibilityTableRole,
|
|
134
|
+
@"tablist" : NSAccessibilityTabGroupRole,
|
|
135
|
+
@"tabpanel" : NSAccessibilityGroupRole,
|
|
136
|
+
@"term" : NSAccessibilityGroupRole,
|
|
137
|
+
@"textbox" : NSAccessibilityTextFieldRole,
|
|
138
|
+
@"timer" : NSAccessibilityGroupRole,
|
|
139
|
+
@"toolbar" : NSAccessibilityToolbarRole,
|
|
140
|
+
@"tooltip" : NSAccessibilityGroupRole,
|
|
141
|
+
@"tree" : NSAccessibilityOutlineRole,
|
|
142
|
+
@"treegrid" : NSAccessibilityTableRole,
|
|
143
|
+
@"treeitem" : NSAccessibilityRowRole,
|
|
144
|
+
};
|
|
145
|
+
traitOrRoleToAccessibilityRole = @{
|
|
146
|
+
@"adjustable" : NSAccessibilitySliderRole,
|
|
147
|
+
@"alert" : NSAccessibilityStaticTextRole,
|
|
148
|
+
@"button" : NSAccessibilityButtonRole,
|
|
149
|
+
@"checkbox" : NSAccessibilityCheckBoxRole,
|
|
150
|
+
@"combobox" : NSAccessibilityComboBoxRole,
|
|
151
|
+
@"header" : NSAccessibilityStaticTextRole,
|
|
152
|
+
@"image" : NSAccessibilityImageRole,
|
|
153
|
+
@"imagebutton" : NSAccessibilityButtonRole,
|
|
154
|
+
@"keyboardkey" : NSAccessibilityButtonRole,
|
|
155
|
+
@"link" : NSAccessibilityLinkRole,
|
|
156
|
+
@"menu" : NSAccessibilityMenuRole,
|
|
157
|
+
@"menubar" : NSAccessibilityMenuBarRole,
|
|
158
|
+
@"menuitem" : NSAccessibilityMenuItemRole,
|
|
159
|
+
@"none" : NSAccessibilityUnknownRole,
|
|
160
|
+
@"progressbar" : NSAccessibilityProgressIndicatorRole,
|
|
161
|
+
@"radio" : NSAccessibilityRadioButtonRole,
|
|
162
|
+
@"radiogroup" : NSAccessibilityRadioGroupRole,
|
|
163
|
+
@"scrollbar" : NSAccessibilityScrollBarRole,
|
|
164
|
+
@"search" : NSAccessibilityTextFieldRole,
|
|
165
|
+
@"spinbutton" : NSAccessibilityIncrementorRole,
|
|
166
|
+
@"summary" : NSAccessibilityStaticTextRole,
|
|
167
|
+
@"switch" : NSAccessibilityCheckBoxRole,
|
|
168
|
+
@"tab" : NSAccessibilityButtonRole,
|
|
169
|
+
@"tablist" : NSAccessibilityTabGroupRole,
|
|
170
|
+
@"text" : NSAccessibilityStaticTextRole,
|
|
171
|
+
@"textbox" : NSAccessibilityTextFieldRole,
|
|
172
|
+
@"timer" : NSAccessibilityStaticTextRole,
|
|
173
|
+
@"toolbar" : NSAccessibilityToolbarRole,
|
|
174
|
+
@"disclosure" : NSAccessibilityDisclosureTriangleRole,
|
|
175
|
+
@"group" : NSAccessibilityGroupRole,
|
|
176
|
+
@"list" : NSAccessibilityListRole,
|
|
177
|
+
@"popupbutton" : NSAccessibilityPopUpButtonRole,
|
|
178
|
+
@"menubutton" : NSAccessibilityMenuButtonRole,
|
|
179
|
+
@"table" : NSAccessibilityTableRole,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
NSAccessibilityRole accessibilityRole =
|
|
184
|
+
useAriaMappings ? ariaRoleToNSAccessibilityRole[role] : traitOrRoleToAccessibilityRole[role];
|
|
185
|
+
if (accessibilityRole == nil && useAriaMappings) {
|
|
186
|
+
accessibilityRole = traitOrRoleToAccessibilityRole[role];
|
|
187
|
+
}
|
|
188
|
+
return accessibilityRole ?: NSAccessibilityUnknownRole;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Matches Paper (`-[RCTViewManager updateAccessibilityRole:withDefaultView:]`): `role` takes precedence over
|
|
192
|
+
// `accessibilityRole`, and the element's default role is used when neither is set.
|
|
193
|
+
static NSAccessibilityRole RCTAccessibilityRoleFromViewProps(const ViewProps &props, NSView *element)
|
|
194
|
+
{
|
|
195
|
+
if (props.role != Role::None) {
|
|
196
|
+
return RCTAccessibilityRoleFromString(RCTNSStringFromString(toString(props.role)), YES);
|
|
197
|
+
}
|
|
198
|
+
if (!props.accessibilityRole.empty()) {
|
|
199
|
+
return RCTAccessibilityRoleFromString(RCTNSStringFromString(props.accessibilityRole), NO);
|
|
200
|
+
}
|
|
201
|
+
NSAccessibilityRole traitsRole =
|
|
202
|
+
RCTAccessibilityRoleFromTraits(RCTUIAccessibilityTraitsFromAccessibilityTraits(props.accessibilityTraits));
|
|
203
|
+
if (![traitsRole isEqualToString:NSAccessibilityUnknownRole]) {
|
|
204
|
+
return traitsRole;
|
|
205
|
+
}
|
|
206
|
+
return RCTDefaultAccessibilityRoleForElement(element);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Setting an NSAccessibility state property makes AppKit advertise that attribute, so like Paper
|
|
210
|
+
// (`-[RCTView isAccessibilitySelectorAllowed:]`) only expose a state when JS provides it. `disabled` and `selected` are
|
|
211
|
+
// plain bools in `AccessibilityState`, so they count as provided whenever `accessibilityState` is set.
|
|
212
|
+
static BOOL RCTViewPropsProvideAccessibilityEnabled(const ViewProps &props)
|
|
213
|
+
{
|
|
214
|
+
const auto traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(props.accessibilityTraits);
|
|
215
|
+
return props.accessibilityState.has_value() || (traits & RCTUIAccessibilityTraitNotEnabled) != 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static BOOL RCTViewPropsProvideAccessibilitySelected(const ViewProps &props)
|
|
219
|
+
{
|
|
220
|
+
const auto traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(props.accessibilityTraits);
|
|
221
|
+
return props.accessibilityState.has_value() || (traits & RCTUIAccessibilityTraitSelected) != 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static BOOL RCTViewPropsProvideAccessibilityExpanded(const ViewProps &props)
|
|
225
|
+
{
|
|
226
|
+
return props.accessibilityState.has_value() && props.accessibilityState->expanded.has_value();
|
|
227
|
+
}
|
|
228
|
+
#endif // macOS]
|
|
229
|
+
|
|
47
230
|
@implementation RCTViewComponentView {
|
|
48
231
|
RCTUIColor *_backgroundColor; // [macOS]
|
|
49
232
|
CALayer *_backgroundColorLayer;
|
|
@@ -483,19 +666,45 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
|
|
|
483
666
|
_accessibilityElements = [NSMutableArray new];
|
|
484
667
|
}
|
|
485
668
|
|
|
669
|
+
#if !TARGET_OS_OSX // [macOS]
|
|
486
670
|
// `accessibilityTraits`
|
|
487
671
|
if (oldViewProps.accessibilityTraits != newViewProps.accessibilityTraits) {
|
|
488
|
-
#if !TARGET_OS_OSX // [macOS]
|
|
489
672
|
self.accessibilityElement.accessibilityTraits =
|
|
490
673
|
RCTUIAccessibilityTraitsFromAccessibilityTraits(newViewProps.accessibilityTraits);
|
|
674
|
+
}
|
|
491
675
|
#else // [macOS
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
676
|
+
// `role`, `accessibilityRole` and `accessibilityTraits`
|
|
677
|
+
// NSAccessibility has no traits, so all three resolve to a single role on the accessibility element.
|
|
678
|
+
// Role props can change without accessibilityTraits changing, so check all three.
|
|
679
|
+
if (oldViewProps.role != newViewProps.role || oldViewProps.accessibilityRole != newViewProps.accessibilityRole ||
|
|
680
|
+
oldViewProps.accessibilityTraits != newViewProps.accessibilityTraits) {
|
|
681
|
+
self.accessibilityElement.accessibilityRole =
|
|
682
|
+
RCTAccessibilityRoleFromViewProps(newViewProps, self.accessibilityElement);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// `accessibilityState`
|
|
686
|
+
// `disabled` and `selected` can also come from the NotEnabled and Selected traits. Only update a state that is, or
|
|
687
|
+
// was, provided so that elements without it do not start advertising it.
|
|
688
|
+
if (oldViewProps.accessibilityState != newViewProps.accessibilityState ||
|
|
689
|
+
oldViewProps.accessibilityTraits != newViewProps.accessibilityTraits) {
|
|
690
|
+
const auto accessibilityState = newViewProps.accessibilityState.value_or(AccessibilityState{});
|
|
691
|
+
const auto traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(newViewProps.accessibilityTraits);
|
|
692
|
+
if (RCTViewPropsProvideAccessibilityEnabled(newViewProps) ||
|
|
693
|
+
RCTViewPropsProvideAccessibilityEnabled(oldViewProps)) {
|
|
694
|
+
self.accessibilityElement.accessibilityEnabled =
|
|
695
|
+
!accessibilityState.disabled && (traits & RCTUIAccessibilityTraitNotEnabled) == 0;
|
|
696
|
+
}
|
|
697
|
+
if (RCTViewPropsProvideAccessibilitySelected(newViewProps) ||
|
|
698
|
+
RCTViewPropsProvideAccessibilitySelected(oldViewProps)) {
|
|
699
|
+
self.accessibilityElement.accessibilitySelected =
|
|
700
|
+
accessibilityState.selected || (traits & RCTUIAccessibilityTraitSelected) != 0;
|
|
701
|
+
}
|
|
702
|
+
if (RCTViewPropsProvideAccessibilityExpanded(newViewProps) ||
|
|
703
|
+
RCTViewPropsProvideAccessibilityExpanded(oldViewProps)) {
|
|
704
|
+
self.accessibilityElement.accessibilityExpanded = accessibilityState.expanded.value_or(false);
|
|
705
|
+
}
|
|
498
706
|
}
|
|
707
|
+
#endif // macOS]
|
|
499
708
|
|
|
500
709
|
#if !TARGET_OS_OSX // [macOS]
|
|
501
710
|
// `accessibilityState`
|
|
@@ -1562,6 +1771,23 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // [macOS]
|
|
|
1562
1771
|
return [super isAccessibilityElement];
|
|
1563
1772
|
}
|
|
1564
1773
|
|
|
1774
|
+
#if TARGET_OS_OSX // [macOS
|
|
1775
|
+
- (BOOL)isAccessibilitySelectorAllowed:(SEL)selector
|
|
1776
|
+
{
|
|
1777
|
+
const auto &props = static_cast<const ViewProps &>(*_props);
|
|
1778
|
+
if (selector == @selector(isAccessibilityEnabled)) {
|
|
1779
|
+
return RCTViewPropsProvideAccessibilityEnabled(props);
|
|
1780
|
+
}
|
|
1781
|
+
if (selector == @selector(isAccessibilitySelected)) {
|
|
1782
|
+
return RCTViewPropsProvideAccessibilitySelected(props);
|
|
1783
|
+
}
|
|
1784
|
+
if (selector == @selector(isAccessibilityExpanded)) {
|
|
1785
|
+
return RCTViewPropsProvideAccessibilityExpanded(props);
|
|
1786
|
+
}
|
|
1787
|
+
return [super isAccessibilitySelectorAllowed:selector];
|
|
1788
|
+
}
|
|
1789
|
+
#endif // macOS]
|
|
1790
|
+
|
|
1565
1791
|
- (NSString *)accessibilityValue
|
|
1566
1792
|
{
|
|
1567
1793
|
const auto &props = static_cast<const ViewProps &>(*_props);
|
|
@@ -355,6 +355,10 @@ RCT_CUSTOM_VIEW_PROPERTY(accessibilityState, NSDictionary, RCTView)
|
|
|
355
355
|
NSMutableDictionary<NSString *, id> *newState = [NSMutableDictionary<NSString *, id> new];
|
|
356
356
|
|
|
357
357
|
if (!state) {
|
|
358
|
+
#if TARGET_OS_OSX // [macOS
|
|
359
|
+
// Removing the prop must clear the previous state, e.g. so a TextInput is re-enabled once `disabled` goes away.
|
|
360
|
+
view.reactAccessibilityElement.accessibilityState = nil;
|
|
361
|
+
#endif // macOS]
|
|
358
362
|
return;
|
|
359
363
|
}
|
|
360
364
|
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
|
|
15
15
|
#define REACT_NATIVE_VERSION_MAJOR 0
|
|
16
16
|
#define REACT_NATIVE_VERSION_MINOR 81
|
|
17
|
-
#define REACT_NATIVE_VERSION_PATCH
|
|
17
|
+
#define REACT_NATIVE_VERSION_PATCH 12
|
|
18
18
|
|
|
19
19
|
namespace facebook::react {
|
|
20
20
|
|
|
21
21
|
constexpr struct {
|
|
22
22
|
int32_t Major = 0;
|
|
23
23
|
int32_t Minor = 81;
|
|
24
|
-
int32_t Patch =
|
|
24
|
+
int32_t Patch = 12;
|
|
25
25
|
std::string_view Prerelease = "";
|
|
26
26
|
} ReactNativeVersion;
|
|
27
27
|
|
|
@@ -136,32 +136,42 @@ ShadowNode::ShadowNode(
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// [macOS Backport react/react-native@923e7ddcaf4d (#52646).
|
|
139
140
|
std::shared_ptr<ShadowNode> ShadowNode::clone(
|
|
140
141
|
const ShadowNodeFragment& fragment) const {
|
|
141
142
|
const auto& family = *family_;
|
|
142
143
|
const auto& componentDescriptor = family.componentDescriptor_;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
.state = fragment.state});
|
|
155
|
-
return clonedNode;
|
|
156
|
-
} else {
|
|
157
|
-
// TODO: We might need to merge fragment.priops with
|
|
158
|
-
// `family.nativeProps_DEPRECATED`.
|
|
159
|
-
return componentDescriptor.cloneShadowNode(*this, fragment);
|
|
144
|
+
|
|
145
|
+
std::optional<RawProps> propsOverride;
|
|
146
|
+
{
|
|
147
|
+
std::lock_guard<std::mutex> lock(family.nativePropsMutex);
|
|
148
|
+
if (family.nativeProps_DEPRECATED != nullptr) {
|
|
149
|
+
if (fragment.props == ShadowNodeFragment::propsPlaceholder()) {
|
|
150
|
+
propsOverride.emplace(*family.nativeProps_DEPRECATED);
|
|
151
|
+
} else {
|
|
152
|
+
// TODO: We might need to merge fragment.props with
|
|
153
|
+
// `family.nativeProps_DEPRECATED`.
|
|
154
|
+
}
|
|
160
155
|
}
|
|
161
|
-
} else {
|
|
162
|
-
return componentDescriptor.cloneShadowNode(*this, fragment);
|
|
163
156
|
}
|
|
157
|
+
|
|
158
|
+
if (propsOverride) {
|
|
159
|
+
// Clone existing `props_` with `family.nativeProps_DEPRECATED` to
|
|
160
|
+
// apply previously set props via `setNativeProps` API. The parsed
|
|
161
|
+
// result escapes the lock so the rest of the clone work runs
|
|
162
|
+
// unblocked.
|
|
163
|
+
auto propsParserContext = PropsParserContext{family_->getSurfaceId(), {}};
|
|
164
|
+
return componentDescriptor.cloneShadowNode(
|
|
165
|
+
*this,
|
|
166
|
+
{.props = componentDescriptor.cloneProps(
|
|
167
|
+
propsParserContext, props_, std::move(*propsOverride)),
|
|
168
|
+
.children = fragment.children,
|
|
169
|
+
.state = fragment.state});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return componentDescriptor.cloneShadowNode(*this, fragment);
|
|
164
173
|
}
|
|
174
|
+
// macOS]
|
|
165
175
|
|
|
166
176
|
ContextContainer::Shared ShadowNode::getContextContainer() const {
|
|
167
177
|
return family_->componentDescriptor_.getContextContainer();
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
#include <memory>
|
|
11
|
+
#include <mutex> // [macOS] Backport upstream #52646.
|
|
11
12
|
#include <shared_mutex>
|
|
12
13
|
|
|
13
14
|
#include <react/renderer/core/EventEmitter.h>
|
|
@@ -116,6 +117,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
|
|
|
116
117
|
* architecture and will be removed in the future.
|
|
117
118
|
*/
|
|
118
119
|
mutable std::unique_ptr<folly::dynamic> nativeProps_DEPRECATED;
|
|
120
|
+
mutable std::mutex nativePropsMutex; // [macOS] Backport upstream #52646.
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
123
|
* @return tag for the ShadowNodeFamily.
|
|
@@ -103,6 +103,7 @@ std::shared_ptr<ShadowNode> UIManager::createNode(
|
|
|
103
103
|
return shadowNode;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
// [macOS Backport react/react-native@923e7ddcaf4d (#52646).
|
|
106
107
|
std::shared_ptr<ShadowNode> UIManager::cloneNode(
|
|
107
108
|
const ShadowNode& shadowNode,
|
|
108
109
|
const ShadowNode::SharedListOfShared& children,
|
|
@@ -115,49 +116,51 @@ std::shared_ptr<ShadowNode> UIManager::cloneNode(
|
|
|
115
116
|
|
|
116
117
|
auto& componentDescriptor = shadowNode.getComponentDescriptor();
|
|
117
118
|
auto& family = shadowNode.getFamily();
|
|
118
|
-
auto props = ShadowNodeFragment::propsPlaceholder();
|
|
119
119
|
|
|
120
|
+
auto props = ShadowNodeFragment::propsPlaceholder();
|
|
120
121
|
if (!rawProps.isEmpty()) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
} else {
|
|
158
|
-
props = componentDescriptor.cloneProps(
|
|
159
|
-
propsParserContext, shadowNode.getProps(), std::move(rawProps));
|
|
122
|
+
std::optional<folly::dynamic> finalProps;
|
|
123
|
+
{
|
|
124
|
+
std::lock_guard<std::mutex> lock(family.nativePropsMutex);
|
|
125
|
+
if (family.nativeProps_DEPRECATED != nullptr) {
|
|
126
|
+
// 1. update the nativeProps_DEPRECATED props.
|
|
127
|
+
//
|
|
128
|
+
// In this step, we want the most recent value for the props
|
|
129
|
+
// managed by setNativeProps.
|
|
130
|
+
// Values in `rawProps` patch (take precedence over)
|
|
131
|
+
// `nativeProps_DEPRECATED`. For example, if both
|
|
132
|
+
// `nativeProps_DEPRECATED` and `rawProps` contain key 'A'.
|
|
133
|
+
// Value from `rawProps` overrides what was previously in
|
|
134
|
+
// `nativeProps_DEPRECATED`. Notice that the `nativeProps_DEPRECATED`
|
|
135
|
+
// patch will not get more props from `rawProps`: if the key is not
|
|
136
|
+
// present in `nativeProps_DEPRECATED`, it will not be added.
|
|
137
|
+
//
|
|
138
|
+
// The result of this operation is the new `nativeProps_DEPRECATED`.
|
|
139
|
+
family.nativeProps_DEPRECATED =
|
|
140
|
+
std::make_unique<folly::dynamic>(mergeDynamicProps(
|
|
141
|
+
*family.nativeProps_DEPRECATED, // source
|
|
142
|
+
(folly::dynamic)rawProps, // patch
|
|
143
|
+
NullValueStrategy::Ignore));
|
|
144
|
+
|
|
145
|
+
// 2. Compute the final set of props.
|
|
146
|
+
//
|
|
147
|
+
// This step takes the new props handled by `setNativeProps` and
|
|
148
|
+
// merges them in the `rawProps` managed by React.
|
|
149
|
+
// The new props handled by `nativeProps` now takes precedence
|
|
150
|
+
// on the props handled by React, as we want to make sure that
|
|
151
|
+
// all the props are applied to the component.
|
|
152
|
+
// We use these finalProps as source of truth for the component.
|
|
153
|
+
finalProps = mergeDynamicProps(
|
|
154
|
+
(folly::dynamic)rawProps, // source
|
|
155
|
+
*family.nativeProps_DEPRECATED, // patch
|
|
156
|
+
NullValueStrategy::Override);
|
|
157
|
+
}
|
|
160
158
|
}
|
|
159
|
+
|
|
160
|
+
props = componentDescriptor.cloneProps(
|
|
161
|
+
propsParserContext,
|
|
162
|
+
shadowNode.getProps(),
|
|
163
|
+
finalProps ? RawProps(std::move(*finalProps)) : std::move(rawProps));
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
auto clonedShadowNode = componentDescriptor.cloneShadowNode(
|
|
@@ -170,6 +173,7 @@ std::shared_ptr<ShadowNode> UIManager::cloneNode(
|
|
|
170
173
|
|
|
171
174
|
return clonedShadowNode;
|
|
172
175
|
}
|
|
176
|
+
// macOS]
|
|
173
177
|
|
|
174
178
|
void UIManager::appendChild(
|
|
175
179
|
const std::shared_ptr<const ShadowNode>& parentShadowNode,
|
|
@@ -426,20 +430,25 @@ void UIManager::setNativeProps_DEPRECATED(
|
|
|
426
430
|
const std::shared_ptr<const ShadowNode>& shadowNode,
|
|
427
431
|
RawProps rawProps) const {
|
|
428
432
|
auto& family = shadowNode->getFamily();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
433
|
+
// [macOS Backport react/react-native@923e7ddcaf4d (#52646).
|
|
434
|
+
{
|
|
435
|
+
std::lock_guard<std::mutex> lock(family.nativePropsMutex);
|
|
436
|
+
if (family.nativeProps_DEPRECATED) {
|
|
437
|
+
// Values in `rawProps` patch (take precedence over)
|
|
438
|
+
// `nativeProps_DEPRECATED`. For example, if both `nativeProps_DEPRECATED`
|
|
439
|
+
// and `rawProps` contain key 'A'. Value from `rawProps` overrides what
|
|
440
|
+
// was previously in `nativeProps_DEPRECATED`.
|
|
441
|
+
family.nativeProps_DEPRECATED =
|
|
442
|
+
std::make_unique<folly::dynamic>(mergeDynamicProps(
|
|
443
|
+
*family.nativeProps_DEPRECATED,
|
|
444
|
+
(folly::dynamic)rawProps,
|
|
445
|
+
NullValueStrategy::Override));
|
|
446
|
+
} else {
|
|
447
|
+
family.nativeProps_DEPRECATED =
|
|
448
|
+
std::make_unique<folly::dynamic>((folly::dynamic)rawProps);
|
|
449
|
+
}
|
|
442
450
|
}
|
|
451
|
+
// macOS]
|
|
443
452
|
|
|
444
453
|
shadowTreeRegistry_.visit(
|
|
445
454
|
family.getSurfaceId(), [&](const ShadowTree& shadowTree) {
|
|
@@ -5,13 +5,189 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
// [macOS Adapted from react/react-native@923e7ddcaf4d (#52646).
|
|
9
|
+
#include <atomic>
|
|
8
10
|
#include <memory>
|
|
11
|
+
#include <thread>
|
|
9
12
|
|
|
10
13
|
#include <gtest/gtest.h>
|
|
14
|
+
#include <react/renderer/components/view/ViewShadowNode.h>
|
|
15
|
+
#include <react/renderer/core/ShadowNodeFragment.h>
|
|
16
|
+
#include <react/renderer/element/Element.h>
|
|
17
|
+
#include <react/renderer/element/testUtils.h>
|
|
11
18
|
#include <react/renderer/uimanager/UIManager.h>
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
namespace facebook::react {
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
class FabricUIManagerTest : public ::testing::Test {
|
|
23
|
+
public:
|
|
24
|
+
FabricUIManagerTest() {
|
|
25
|
+
contextContainer_ = std::make_shared<ContextContainer>();
|
|
26
|
+
ComponentDescriptorProviderRegistry providers{};
|
|
27
|
+
auto registry = providers.createComponentDescriptorRegistry(
|
|
28
|
+
{.eventDispatcher = EventDispatcher::Shared{},
|
|
29
|
+
.contextContainer = contextContainer_,
|
|
30
|
+
.flavor = nullptr});
|
|
31
|
+
providers.add(
|
|
32
|
+
concreteComponentDescriptorProvider<RootComponentDescriptor>());
|
|
33
|
+
providers.add(
|
|
34
|
+
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
|
|
35
|
+
builder_ = std::make_unique<ComponentBuilder>(registry);
|
|
36
|
+
|
|
37
|
+
RuntimeExecutor executor =
|
|
38
|
+
[](std::function<void(jsi::Runtime&)>&& /*callback*/) {};
|
|
39
|
+
uiManager_ = std::make_unique<UIManager>(executor, contextContainer_);
|
|
40
|
+
uiManager_->setComponentDescriptorRegistry(registry);
|
|
41
|
+
|
|
42
|
+
std::shared_ptr<RootShadowNode> root;
|
|
43
|
+
// clang-format off
|
|
44
|
+
builder_->build(
|
|
45
|
+
Element<RootShadowNode>()
|
|
46
|
+
.tag(1)
|
|
47
|
+
.surfaceId(surfaceId_)
|
|
48
|
+
.reference(root)
|
|
49
|
+
.props([] {
|
|
50
|
+
auto props = std::make_shared<RootProps>();
|
|
51
|
+
props->layoutConstraints = LayoutConstraints{
|
|
52
|
+
.minimumSize = {.width = 0, .height = 0},
|
|
53
|
+
.maximumSize = {.width = 500, .height = 500}};
|
|
54
|
+
return props;
|
|
55
|
+
})
|
|
56
|
+
.children({
|
|
57
|
+
Element<ViewShadowNode>()
|
|
58
|
+
.tag(42)
|
|
59
|
+
.surfaceId(surfaceId_)
|
|
60
|
+
.props([] {
|
|
61
|
+
auto props = std::make_shared<ViewShadowNodeProps>();
|
|
62
|
+
props->nativeId = "initial";
|
|
63
|
+
props->opacity = 1.0;
|
|
64
|
+
return props;
|
|
65
|
+
})
|
|
66
|
+
}));
|
|
67
|
+
// clang-format on
|
|
68
|
+
|
|
69
|
+
auto tree = std::make_unique<ShadowTree>(
|
|
70
|
+
surfaceId_,
|
|
71
|
+
LayoutConstraints{},
|
|
72
|
+
LayoutContext{},
|
|
73
|
+
*uiManager_,
|
|
74
|
+
*contextContainer_);
|
|
75
|
+
shadowTree_ = tree.get();
|
|
76
|
+
tree->commit([&root](const RootShadowNode&) { return root; }, {true});
|
|
77
|
+
uiManager_->startSurface(
|
|
78
|
+
std::move(tree), "test", folly::dynamic::object, DisplayMode::Visible);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void TearDown() override {
|
|
82
|
+
uiManager_->stopSurface(surfaceId_);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected:
|
|
86
|
+
std::shared_ptr<const ShadowNode> currentViewNode() const {
|
|
87
|
+
return shadowTree_->getCurrentRevision()
|
|
88
|
+
.rootShadowNode->getChildren()
|
|
89
|
+
.front();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const ViewProps& viewPropsInTree() const {
|
|
93
|
+
return static_cast<const ViewProps&>(*currentViewNode()->getProps());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static const ViewProps& viewProps(const ShadowNode& node) {
|
|
97
|
+
return static_cast<const ViewProps&>(*node.getProps());
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
SurfaceId surfaceId_{0};
|
|
101
|
+
std::shared_ptr<ContextContainer> contextContainer_;
|
|
102
|
+
std::unique_ptr<ComponentBuilder> builder_;
|
|
103
|
+
std::unique_ptr<UIManager> uiManager_;
|
|
104
|
+
ShadowTree* shadowTree_{nullptr};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
TEST_F(FabricUIManagerTest, SetNativePropsMergesWithReactRender) {
|
|
108
|
+
ASSERT_EQ(viewPropsInTree().nativeId, "initial");
|
|
109
|
+
ASSERT_FLOAT_EQ(viewPropsInTree().opacity, 1.0);
|
|
110
|
+
uiManager_->setNativeProps_DEPRECATED(
|
|
111
|
+
currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5)));
|
|
112
|
+
EXPECT_EQ(viewPropsInTree().nativeId, "initial");
|
|
113
|
+
EXPECT_FLOAT_EQ(viewPropsInTree().opacity, 0.5);
|
|
114
|
+
|
|
115
|
+
auto rendered = uiManager_->cloneNode(
|
|
116
|
+
*currentViewNode(),
|
|
117
|
+
nullptr,
|
|
118
|
+
RawProps(folly::dynamic::object("nativeID", "from-react")));
|
|
119
|
+
EXPECT_EQ(viewProps(*rendered).nativeId, "from-react");
|
|
120
|
+
EXPECT_FLOAT_EQ(viewProps(*rendered).opacity, 0.5);
|
|
17
121
|
}
|
|
122
|
+
|
|
123
|
+
TEST_F(FabricUIManagerTest, ReactRefreshesNativeOwnedKeysIncludingNull) {
|
|
124
|
+
uiManager_->setNativeProps_DEPRECATED(
|
|
125
|
+
currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5)));
|
|
126
|
+
auto refreshed = uiManager_->cloneNode(
|
|
127
|
+
*currentViewNode(),
|
|
128
|
+
nullptr,
|
|
129
|
+
RawProps(folly::dynamic::object("opacity", 0.75)));
|
|
130
|
+
EXPECT_FLOAT_EQ(viewProps(*refreshed).opacity, 0.75);
|
|
131
|
+
EXPECT_FLOAT_EQ(viewProps(*refreshed->clone({})).opacity, 0.75);
|
|
132
|
+
|
|
133
|
+
auto reset = uiManager_->cloneNode(
|
|
134
|
+
*refreshed,
|
|
135
|
+
nullptr,
|
|
136
|
+
RawProps(folly::dynamic::object("opacity", nullptr)));
|
|
137
|
+
EXPECT_FLOAT_EQ(viewProps(*reset).opacity, 1.0);
|
|
138
|
+
EXPECT_FLOAT_EQ(viewProps(*reset->clone({})).opacity, 1.0);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
TEST_F(FabricUIManagerTest, ReactOnlyKeysDoNotBecomeNativeOverrides) {
|
|
142
|
+
uiManager_->setNativeProps_DEPRECATED(
|
|
143
|
+
currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5)));
|
|
144
|
+
auto rendered = uiManager_->cloneNode(
|
|
145
|
+
*currentViewNode(),
|
|
146
|
+
nullptr,
|
|
147
|
+
RawProps(folly::dynamic::object("nativeID", "from-react")));
|
|
148
|
+
auto explicitProps = std::make_shared<ViewShadowNodeProps>();
|
|
149
|
+
explicitProps->nativeId = "explicit";
|
|
150
|
+
explicitProps->opacity = 0.9;
|
|
151
|
+
auto explicitClone = rendered->clone({.props = explicitProps});
|
|
152
|
+
EXPECT_EQ(viewProps(*explicitClone).nativeId, "explicit");
|
|
153
|
+
EXPECT_FLOAT_EQ(viewProps(*explicitClone).opacity, 0.9);
|
|
154
|
+
|
|
155
|
+
auto placeholderClone = explicitClone->clone({});
|
|
156
|
+
EXPECT_EQ(viewProps(*placeholderClone).nativeId, "explicit");
|
|
157
|
+
EXPECT_FLOAT_EQ(viewProps(*placeholderClone).opacity, 0.5);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
TEST_F(
|
|
161
|
+
FabricUIManagerTest,
|
|
162
|
+
ConcurrentReactAndPlaceholderClonesUseOwnedSnapshots) {
|
|
163
|
+
uiManager_->setNativeProps_DEPRECATED(
|
|
164
|
+
currentViewNode(), RawProps(folly::dynamic::object("opacity", 0.5)));
|
|
165
|
+
auto node = currentViewNode();
|
|
166
|
+
std::atomic<bool> start{false};
|
|
167
|
+
std::atomic<int> invalidSnapshots{0};
|
|
168
|
+
std::thread writer([&] {
|
|
169
|
+
while (!start.load()) {
|
|
170
|
+
std::this_thread::yield();
|
|
171
|
+
}
|
|
172
|
+
for (int i = 0; i < 1000; ++i) {
|
|
173
|
+
uiManager_->cloneNode(
|
|
174
|
+
*node,
|
|
175
|
+
nullptr,
|
|
176
|
+
RawProps(folly::dynamic::object("opacity", i % 2 ? 0.75 : 0.25)));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
start.store(true);
|
|
180
|
+
for (int i = 0; i < 1000; ++i) {
|
|
181
|
+
auto clone = node->clone({});
|
|
182
|
+
auto opacity = viewProps(*clone).opacity;
|
|
183
|
+
if (opacity != 0.25 && opacity != 0.5 && opacity != 0.75) {
|
|
184
|
+
++invalidSnapshots;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
writer.join();
|
|
188
|
+
EXPECT_EQ(invalidSnapshots.load(), 0);
|
|
189
|
+
EXPECT_FLOAT_EQ(viewProps(*node->clone({})).opacity, 0.75);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
} // namespace facebook::react
|
|
193
|
+
// macOS]
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-macos",
|
|
3
|
-
"version": "0.81.
|
|
3
|
+
"version": "0.81.12",
|
|
4
4
|
"description": "React Native for macOS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "
|
|
8
|
+
"url": "https://github.com/microsoft/react-native-macos",
|
|
9
9
|
"directory": "packages/react-native"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://reactnative.dev/",
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
},
|
|
188
188
|
"dependencies": {
|
|
189
189
|
"@jest/create-cache-key-function": "^29.7.0",
|
|
190
|
-
"@react-native-macos/virtualized-lists": "0.81.
|
|
190
|
+
"@react-native-macos/virtualized-lists": "0.81.12",
|
|
191
191
|
"@react-native/assets-registry": "0.81.6",
|
|
192
192
|
"@react-native/codegen": "0.81.6",
|
|
193
193
|
"@react-native/community-cli-plugin": "0.81.6",
|
package/react-native.config.js
CHANGED
|
@@ -38,7 +38,7 @@ function findCommunityPlatformPackage(
|
|
|
38
38
|
// root. This is also what `@react-native-community/cli` assumes (see
|
|
39
39
|
// https://github.com/react-native-community/cli/blob/14.x/packages/cli-tools/src/findProjectRoot.ts).
|
|
40
40
|
const main = require.resolve(spec, {paths: [startDir]});
|
|
41
|
-
// $
|
|
41
|
+
// $FlowFixMe[unsupported-syntax]
|
|
42
42
|
return require(main);
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -74,6 +74,7 @@ try {
|
|
|
74
74
|
const iosPath = require.resolve('@react-native-community/cli-platform-ios', {
|
|
75
75
|
paths: [process.cwd()],
|
|
76
76
|
});
|
|
77
|
+
// $FlowFixMe[untyped-import]
|
|
77
78
|
apple = findCommunityPlatformPackage(
|
|
78
79
|
'@react-native-community/cli-platform-apple',
|
|
79
80
|
iosPath,
|
|
@@ -86,8 +87,19 @@ try {
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
let macosCommands;
|
|
91
|
+
// Loading `runMacOS` requires `@react-native-community/cli`which is an
|
|
92
|
+
// optional peer dependency and is not installed when using Expo CLI.
|
|
93
|
+
try {
|
|
94
|
+
// $FlowFixMe[untyped-import]
|
|
95
|
+
macosCommands = require('./local-cli/runMacOS/runMacOS');
|
|
96
|
+
} catch (e) {
|
|
97
|
+
if (verbose) {
|
|
98
|
+
console.warn(
|
|
99
|
+
`Failed to load runMacOS commands, the react-native.config.js may be unusable: ${e instanceof Error ? e.message : String(e)}`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
91
103
|
const {
|
|
92
104
|
bundleCommand,
|
|
93
105
|
startCommand,
|
|
@@ -160,9 +172,17 @@ if (android != null) {
|
|
|
160
172
|
}
|
|
161
173
|
|
|
162
174
|
// [macOS
|
|
163
|
-
|
|
175
|
+
if (macosCommands != null) {
|
|
176
|
+
config.commands.push(...macosCommands);
|
|
177
|
+
}
|
|
164
178
|
if (apple) {
|
|
179
|
+
const {
|
|
180
|
+
REACT_NATIVE: npmPackageName,
|
|
181
|
+
} = require('./scripts/codegen/generate-artifacts-executor/constants.js');
|
|
182
|
+
const macos = {platformName: 'macos'};
|
|
183
|
+
const visionos = {platformName: 'visionos'};
|
|
165
184
|
config.platforms.macos = {
|
|
185
|
+
npmPackageName,
|
|
166
186
|
linkConfig: () => {
|
|
167
187
|
return {
|
|
168
188
|
isInstalled: (
|
|
@@ -186,9 +206,13 @@ if (apple) {
|
|
|
186
206
|
unlinkAssets: (_assets /*: mixed */, _projectConfig /*: mixed */) => {},
|
|
187
207
|
};
|
|
188
208
|
},
|
|
189
|
-
projectConfig: apple.getProjectConfig(
|
|
190
|
-
dependencyConfig: apple.
|
|
191
|
-
|
|
209
|
+
projectConfig: apple.getProjectConfig(macos),
|
|
210
|
+
dependencyConfig: apple.getDependencyConfig(macos),
|
|
211
|
+
};
|
|
212
|
+
config.platforms.visionos = {
|
|
213
|
+
npmPackageName,
|
|
214
|
+
projectConfig: apple.getProjectConfig(visionos),
|
|
215
|
+
dependencyConfig: apple.getDependencyConfig(visionos),
|
|
192
216
|
};
|
|
193
217
|
}
|
|
194
218
|
// macOS]
|