react-native-macos 0.83.0 → 0.83.1

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 (26) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/Libraries/Core/ReactNativeVersion.js +1 -1
  3. package/Libraries/Text/TextInput/Multiline/RCTUITextView.mm +34 -0
  4. package/Libraries/Text/TextInput/Multiline/RCTWrappedTextView.m +16 -0
  5. package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +2 -0
  6. package/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +27 -3
  7. package/React/Base/RCTConvert.mm +2 -1
  8. package/React/Base/RCTUtils.h +6 -0
  9. package/React/Base/RCTUtils.mm +1 -1
  10. package/React/Base/RCTVersion.m +1 -1
  11. package/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +21 -0
  12. package/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm +5 -1
  13. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +233 -7
  14. package/React/Views/RCTView.m +1 -1
  15. package/React/Views/RCTViewManager.m +4 -0
  16. package/ReactAndroid/gradle.properties +1 -1
  17. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.kt +1 -1
  18. package/ReactApple/Libraries/RCTUIKit/RCTUIView.h +2 -0
  19. package/ReactApple/Libraries/RCTUIKit/RCTUIView.m +16 -0
  20. package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
  21. package/ReactCommon/react/renderer/core/ShadowNode.cpp +29 -19
  22. package/ReactCommon/react/renderer/core/ShadowNodeFamily.h +2 -0
  23. package/ReactCommon/react/renderer/uimanager/UIManager.cpp +62 -53
  24. package/ReactCommon/react/renderer/uimanager/tests/FabricUIManagerTest.cpp +179 -3
  25. package/local-cli/generator-macos/templates/macos/HelloWorld-macOS/AppDelegate.swift +3 -2
  26. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # react-native-macos
2
2
 
3
+ ## 0.83.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4d5d679: Release the macOS 0.83 patch containing the merged Fabric native props, safe-area, and accessibility fixes.
8
+ - 3e939cd: <!-- [macOS] -->
9
+
10
+ Backport upstream Fabric native-props synchronization to prevent crashes when native props are updated while shadow nodes are cloned.
11
+ - dca11e7: <!-- [macOS] -->
12
+
13
+ Fix a crash when typing a dead key, such as `´` on a Spanish keyboard layout, into a `TextInput` on the legacy architecture.
14
+ - 2776153: Fix macOS Fabric accessibility roles and states, keep read-only TextInputs focusable and selectable, honor disabled accessibility state, and give each Fabric TextInput a single Tab stop.
15
+ - d0f38cb: <!-- [macOS] -->
16
+
17
+ Restore macOS native image test compilation and gzip test linkage.
18
+ - 55494b3: <!-- [macOS] -->
19
+
20
+ Bridge AppKit safe-area changes to the UIKit-compatible view callback used by Fabric components.
21
+
22
+ Initialize the generated Swift AppDelegate's stored properties before calling its superclass initializer.
23
+ - @react-native-macos/virtualized-lists@0.83.1
24
+
3
25
  ## 0.83.0
4
26
 
5
27
  ### Minor Changes
@@ -28,7 +28,7 @@
28
28
  export default class ReactNativeVersion {
29
29
  static major: number = 0;
30
30
  static minor: number = 83;
31
- static patch: number = 0;
31
+ static patch: number = 1;
32
32
  static prerelease: string | null = null;
33
33
 
34
34
  static getVersionString(): string {
@@ -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 RCTPlatformColor *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 RCTPlatformColor *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
- // on macos the super must be called otherwise its NSTextFieldCell editable property doesn't get set.
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
  {
@@ -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:json] : [RCTConvert accessibilityRoleFromTrait:trait];
1693
+ NSString *accessibilityRole = useAriaMappings ? [RCTConvert accessibilityRoleFromAriaRole:trait] : [RCTConvert accessibilityRoleFromTrait:trait];
1693
1694
  if (![accessibilityRole isEqualToString:NSAccessibilityUnknownRole]) {
1694
1695
  return accessibilityRole;
1695
1696
  }
@@ -141,6 +141,12 @@ RCT_EXTERN NSURL *RCTDataURL(NSString *mimeType, NSData *data);
141
141
  // Gzip functionality - compression level in range 0 - 1 (-1 for default)
142
142
  RCT_EXTERN NSData *__nullable RCTGzipData(NSData *__nullable data, float level);
143
143
 
144
+ // [macOS
145
+ // Determines whether data is already gzipped. Declared here (rather than only in
146
+ // RCTUtils.mm) so it keeps C linkage and can be called from .m unit tests.
147
+ RCT_EXTERN BOOL RCTIsGzippedData(NSData *__nullable data);
148
+ // macOS]
149
+
144
150
  // Returns the relative path within the main bundle for an absolute URL
145
151
  // (or nil, if the URL does not specify a path within the main bundle)
146
152
  RCT_EXTERN NSString *__nullable RCTBundlePathForURL(NSURL *__nullable URL);
@@ -761,7 +761,7 @@ NSURL *RCTDataURL(NSString *mimeType, NSData *data)
761
761
  [data base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)0]]];
762
762
  }
763
763
 
764
- BOOL RCTIsGzippedData(NSData *__nullable /*data*/); // exposed for unit testing purposes
764
+ // [macOS] RCTUtils.h supplies C linkage for Objective-C callers.
765
765
  BOOL RCTIsGzippedData(NSData *__nullable data)
766
766
  {
767
767
  UInt8 *bytes = (UInt8 *)data.bytes;
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(83),
26
- RCTVersionPatch: @(0),
26
+ RCTVersionPatch: @(1),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -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
- toTextInput.accessibilityRole = fromTextInput.accessibilityRole;
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;
@@ -45,6 +45,189 @@ using namespace facebook::react;
45
45
 
46
46
  const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
47
47
 
48
+ #if TARGET_OS_OSX // [macOS
49
+ // The role an accessibility element reports when React Native does not override it. NSControl subclasses, such as the
50
+ // NSTextField behind a single-line TextInput, report their role through their cell; the control's own
51
+ // `accessibilityRole` getter returns NSAccessibilityUnknownRole until a role is set explicitly.
52
+ static NSAccessibilityRole RCTDefaultAccessibilityRoleForElement(NSView *element)
53
+ {
54
+ if ([element isKindOfClass:[NSControl class]]) {
55
+ NSAccessibilityRole cellRole = ((NSControl *)element).cell.accessibilityRole;
56
+ if (cellRole != nil) {
57
+ return cellRole;
58
+ }
59
+ }
60
+ return NSAccessibilityUnknownRole;
61
+ }
62
+
63
+ // Fabric keeps these mappings local instead of depending on Paper's RCTConvert.
64
+ static NSAccessibilityRole RCTAccessibilityRoleFromString(NSString *role, BOOL useAriaMappings)
65
+ {
66
+ if (useAriaMappings && [role isEqualToString:@"rowgroup"]) {
67
+ return nil;
68
+ }
69
+
70
+ static NSDictionary<NSString *, NSAccessibilityRole> *ariaRoleToNSAccessibilityRole;
71
+ static NSDictionary<NSString *, NSAccessibilityRole> *traitOrRoleToAccessibilityRole;
72
+ static dispatch_once_t onceToken;
73
+ dispatch_once(&onceToken, ^{
74
+ ariaRoleToNSAccessibilityRole = @{
75
+ @"alert" : NSAccessibilityGroupRole,
76
+ @"alertdialog" : NSAccessibilityGroupRole,
77
+ @"application" : NSAccessibilityGroupRole,
78
+ @"article" : NSAccessibilityGroupRole,
79
+ @"banner" : NSAccessibilityGroupRole,
80
+ @"button" : NSAccessibilityButtonRole,
81
+ @"cell" : NSAccessibilityCellRole,
82
+ @"checkbox" : NSAccessibilityCheckBoxRole,
83
+ @"columnheader" : NSAccessibilityCellRole,
84
+ @"combobox" : NSAccessibilityComboBoxRole,
85
+ @"complementary" : NSAccessibilityGroupRole,
86
+ @"contentinfo" : NSAccessibilityGroupRole,
87
+ @"definition" : NSAccessibilityGroupRole,
88
+ @"dialog" : NSAccessibilityGroupRole,
89
+ @"directory" : NSAccessibilityListRole,
90
+ @"document" : NSAccessibilityGroupRole,
91
+ @"feed" : NSAccessibilityGroupRole,
92
+ @"figure" : NSAccessibilityGroupRole,
93
+ @"form" : NSAccessibilityGroupRole,
94
+ @"grid" : NSAccessibilityTableRole,
95
+ @"gridcell" : NSAccessibilityCellRole,
96
+ @"group" : NSAccessibilityGroupRole,
97
+ @"heading" : NSAccessibilityStaticTextRole,
98
+ @"image" : NSAccessibilityImageRole,
99
+ @"img" : NSAccessibilityImageRole,
100
+ @"link" : NSAccessibilityLinkRole,
101
+ @"list" : NSAccessibilityListRole,
102
+ @"listbox" : NSAccessibilityListRole,
103
+ @"listitem" : NSAccessibilityGroupRole,
104
+ @"log" : NSAccessibilityGroupRole,
105
+ @"main" : NSAccessibilityGroupRole,
106
+ @"marquee" : NSAccessibilityGroupRole,
107
+ @"math" : NSAccessibilityGroupRole,
108
+ @"menu" : NSAccessibilityMenuRole,
109
+ @"menubar" : NSAccessibilityMenuBarRole,
110
+ @"menuitem" : NSAccessibilityMenuItemRole,
111
+ @"menuitemcheckbox" : NSAccessibilityMenuItemRole,
112
+ @"menuitemradio" : NSAccessibilityMenuItemRole,
113
+ @"meter" : NSAccessibilityLevelIndicatorRole,
114
+ @"navigation" : NSAccessibilityGroupRole,
115
+ @"none" : NSAccessibilityGroupRole,
116
+ @"note" : NSAccessibilityGroupRole,
117
+ @"option" : NSAccessibilityStaticTextRole,
118
+ @"presentation" : NSAccessibilityGroupRole,
119
+ @"progressbar" : NSAccessibilityProgressIndicatorRole,
120
+ @"radio" : NSAccessibilityRadioButtonRole,
121
+ @"radiogroup" : NSAccessibilityRadioGroupRole,
122
+ @"region" : NSAccessibilityGroupRole,
123
+ @"row" : NSAccessibilityRowRole,
124
+ @"rowheader" : NSAccessibilityCellRole,
125
+ @"scrollbar" : NSAccessibilityScrollBarRole,
126
+ @"search" : NSAccessibilityGroupRole,
127
+ @"searchbox" : NSAccessibilityTextFieldRole,
128
+ @"separator" : NSAccessibilitySplitterRole,
129
+ @"slider" : NSAccessibilitySliderRole,
130
+ @"spinbutton" : NSAccessibilityIncrementorRole,
131
+ @"status" : NSAccessibilityGroupRole,
132
+ @"switch" : NSAccessibilityCheckBoxRole,
133
+ @"tab" : NSAccessibilityRadioButtonRole,
134
+ @"table" : NSAccessibilityTableRole,
135
+ @"tablist" : NSAccessibilityTabGroupRole,
136
+ @"tabpanel" : NSAccessibilityGroupRole,
137
+ @"term" : NSAccessibilityGroupRole,
138
+ @"textbox" : NSAccessibilityTextFieldRole,
139
+ @"timer" : NSAccessibilityGroupRole,
140
+ @"toolbar" : NSAccessibilityToolbarRole,
141
+ @"tooltip" : NSAccessibilityGroupRole,
142
+ @"tree" : NSAccessibilityOutlineRole,
143
+ @"treegrid" : NSAccessibilityTableRole,
144
+ @"treeitem" : NSAccessibilityRowRole,
145
+ };
146
+ traitOrRoleToAccessibilityRole = @{
147
+ @"adjustable" : NSAccessibilitySliderRole,
148
+ @"alert" : NSAccessibilityStaticTextRole,
149
+ @"button" : NSAccessibilityButtonRole,
150
+ @"checkbox" : NSAccessibilityCheckBoxRole,
151
+ @"combobox" : NSAccessibilityComboBoxRole,
152
+ @"header" : NSAccessibilityStaticTextRole,
153
+ @"image" : NSAccessibilityImageRole,
154
+ @"imagebutton" : NSAccessibilityButtonRole,
155
+ @"keyboardkey" : NSAccessibilityButtonRole,
156
+ @"link" : NSAccessibilityLinkRole,
157
+ @"menu" : NSAccessibilityMenuRole,
158
+ @"menubar" : NSAccessibilityMenuBarRole,
159
+ @"menuitem" : NSAccessibilityMenuItemRole,
160
+ @"none" : NSAccessibilityUnknownRole,
161
+ @"progressbar" : NSAccessibilityProgressIndicatorRole,
162
+ @"radio" : NSAccessibilityRadioButtonRole,
163
+ @"radiogroup" : NSAccessibilityRadioGroupRole,
164
+ @"scrollbar" : NSAccessibilityScrollBarRole,
165
+ @"search" : NSAccessibilityTextFieldRole,
166
+ @"spinbutton" : NSAccessibilityIncrementorRole,
167
+ @"summary" : NSAccessibilityStaticTextRole,
168
+ @"switch" : NSAccessibilityCheckBoxRole,
169
+ @"tab" : NSAccessibilityButtonRole,
170
+ @"tablist" : NSAccessibilityTabGroupRole,
171
+ @"text" : NSAccessibilityStaticTextRole,
172
+ @"textbox" : NSAccessibilityTextFieldRole,
173
+ @"timer" : NSAccessibilityStaticTextRole,
174
+ @"toolbar" : NSAccessibilityToolbarRole,
175
+ @"disclosure" : NSAccessibilityDisclosureTriangleRole,
176
+ @"group" : NSAccessibilityGroupRole,
177
+ @"list" : NSAccessibilityListRole,
178
+ @"popupbutton" : NSAccessibilityPopUpButtonRole,
179
+ @"menubutton" : NSAccessibilityMenuButtonRole,
180
+ @"table" : NSAccessibilityTableRole,
181
+ };
182
+ });
183
+
184
+ NSAccessibilityRole accessibilityRole =
185
+ useAriaMappings ? ariaRoleToNSAccessibilityRole[role] : traitOrRoleToAccessibilityRole[role];
186
+ if (accessibilityRole == nil && useAriaMappings) {
187
+ accessibilityRole = traitOrRoleToAccessibilityRole[role];
188
+ }
189
+ return accessibilityRole ?: NSAccessibilityUnknownRole;
190
+ }
191
+
192
+ // Matches Paper (`-[RCTViewManager updateAccessibilityRole:withDefaultView:]`): `role` takes precedence over
193
+ // `accessibilityRole`, and the element's default role is used when neither is set.
194
+ static NSAccessibilityRole RCTAccessibilityRoleFromViewProps(const ViewProps &props, NSView *element)
195
+ {
196
+ if (props.role != Role::None) {
197
+ return RCTAccessibilityRoleFromString(RCTNSStringFromString(toString(props.role)), YES);
198
+ }
199
+ if (!props.accessibilityRole.empty()) {
200
+ return RCTAccessibilityRoleFromString(RCTNSStringFromString(props.accessibilityRole), NO);
201
+ }
202
+ NSAccessibilityRole traitsRole =
203
+ RCTAccessibilityRoleFromTraits(RCTUIAccessibilityTraitsFromAccessibilityTraits(props.accessibilityTraits));
204
+ if (![traitsRole isEqualToString:NSAccessibilityUnknownRole]) {
205
+ return traitsRole;
206
+ }
207
+ return RCTDefaultAccessibilityRoleForElement(element);
208
+ }
209
+
210
+ // Setting an NSAccessibility state property makes AppKit advertise that attribute, so like Paper
211
+ // (`-[RCTView isAccessibilitySelectorAllowed:]`) only expose a state when JS provides it. `disabled` and `selected` are
212
+ // plain bools in `AccessibilityState`, so they count as provided whenever `accessibilityState` is set.
213
+ static BOOL RCTViewPropsProvideAccessibilityEnabled(const ViewProps &props)
214
+ {
215
+ const auto traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(props.accessibilityTraits);
216
+ return props.accessibilityState.has_value() || (traits & RCTUIAccessibilityTraitNotEnabled) != 0;
217
+ }
218
+
219
+ static BOOL RCTViewPropsProvideAccessibilitySelected(const ViewProps &props)
220
+ {
221
+ const auto traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(props.accessibilityTraits);
222
+ return props.accessibilityState.has_value() || (traits & RCTUIAccessibilityTraitSelected) != 0;
223
+ }
224
+
225
+ static BOOL RCTViewPropsProvideAccessibilityExpanded(const ViewProps &props)
226
+ {
227
+ return props.accessibilityState.has_value() && props.accessibilityState->expanded.has_value();
228
+ }
229
+ #endif // macOS]
230
+
48
231
  @implementation RCTViewComponentView {
49
232
  RCTPlatformColor *_backgroundColor; // [macOS]
50
233
  CALayer *_backgroundColorLayer;
@@ -516,19 +699,45 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f;
516
699
  }
517
700
  }
518
701
 
702
+ #if !TARGET_OS_OSX // [macOS]
519
703
  // `accessibilityTraits`
520
704
  if (oldViewProps.accessibilityTraits != newViewProps.accessibilityTraits) {
521
- #if !TARGET_OS_OSX // [macOS]
522
705
  self.accessibilityElement.accessibilityTraits =
523
706
  RCTUIAccessibilityTraitsFromAccessibilityTraits(newViewProps.accessibilityTraits);
707
+ }
524
708
  #else // [macOS
525
- // On macOS, accessibilityElement returns self (NSView*) which doesn't have accessibilityTraits.
526
- // Set role directly on self based on traits.
527
- RCTUIAccessibilityTraits traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(newViewProps.accessibilityTraits);
528
- self.accessibilityRole = RCTAccessibilityRoleFromTraits(traits);
529
- self.accessibilityEnabled = (traits & RCTUIAccessibilityTraitNotEnabled) == 0;
530
- #endif // macOS]
709
+ // `role`, `accessibilityRole` and `accessibilityTraits`
710
+ // NSAccessibility has no traits, so all three resolve to a single role on the accessibility element.
711
+ // Role props can change without accessibilityTraits changing, so check all three.
712
+ if (oldViewProps.role != newViewProps.role || oldViewProps.accessibilityRole != newViewProps.accessibilityRole ||
713
+ oldViewProps.accessibilityTraits != newViewProps.accessibilityTraits) {
714
+ self.accessibilityElement.accessibilityRole =
715
+ RCTAccessibilityRoleFromViewProps(newViewProps, self.accessibilityElement);
716
+ }
717
+
718
+ // `accessibilityState`
719
+ // `disabled` and `selected` can also come from the NotEnabled and Selected traits. Only update a state that is, or
720
+ // was, provided so that elements without it do not start advertising it.
721
+ if (oldViewProps.accessibilityState != newViewProps.accessibilityState ||
722
+ oldViewProps.accessibilityTraits != newViewProps.accessibilityTraits) {
723
+ const auto accessibilityState = newViewProps.accessibilityState.value_or(AccessibilityState{});
724
+ const auto traits = RCTUIAccessibilityTraitsFromAccessibilityTraits(newViewProps.accessibilityTraits);
725
+ if (RCTViewPropsProvideAccessibilityEnabled(newViewProps) ||
726
+ RCTViewPropsProvideAccessibilityEnabled(oldViewProps)) {
727
+ self.accessibilityElement.accessibilityEnabled =
728
+ !accessibilityState.disabled && (traits & RCTUIAccessibilityTraitNotEnabled) == 0;
729
+ }
730
+ if (RCTViewPropsProvideAccessibilitySelected(newViewProps) ||
731
+ RCTViewPropsProvideAccessibilitySelected(oldViewProps)) {
732
+ self.accessibilityElement.accessibilitySelected =
733
+ accessibilityState.selected || (traits & RCTUIAccessibilityTraitSelected) != 0;
734
+ }
735
+ if (RCTViewPropsProvideAccessibilityExpanded(newViewProps) ||
736
+ RCTViewPropsProvideAccessibilityExpanded(oldViewProps)) {
737
+ self.accessibilityElement.accessibilityExpanded = accessibilityState.expanded.value_or(false);
738
+ }
531
739
  }
740
+ #endif // macOS]
532
741
 
533
742
  #if !TARGET_OS_OSX // [macOS]
534
743
  // `accessibilityState`
@@ -1714,6 +1923,23 @@ static NSString *RCTRecursiveAccessibilityLabel(RCTUIView *view) // [macOS]
1714
1923
  return [super isAccessibilityElement];
1715
1924
  }
1716
1925
 
1926
+ #if TARGET_OS_OSX // [macOS
1927
+ - (BOOL)isAccessibilitySelectorAllowed:(SEL)selector
1928
+ {
1929
+ const auto &props = static_cast<const ViewProps &>(*_props);
1930
+ if (selector == @selector(isAccessibilityEnabled)) {
1931
+ return RCTViewPropsProvideAccessibilityEnabled(props);
1932
+ }
1933
+ if (selector == @selector(isAccessibilitySelected)) {
1934
+ return RCTViewPropsProvideAccessibilitySelected(props);
1935
+ }
1936
+ if (selector == @selector(isAccessibilityExpanded)) {
1937
+ return RCTViewPropsProvideAccessibilityExpanded(props);
1938
+ }
1939
+ return [super isAccessibilitySelectorAllowed:selector];
1940
+ }
1941
+ #endif // macOS]
1942
+
1717
1943
  - (NSString *)accessibilityValue
1718
1944
  {
1719
1945
  const auto &props = static_cast<const ViewProps &>(*_props);
@@ -1766,7 +1766,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1766
1766
  static const char kRCTViewKeyboardEventEmittedKey = 0;
1767
1767
  NSNumber *emitted = objc_getAssociatedObject(event, &kRCTViewKeyboardEventEmittedKey);
1768
1768
  BOOL alreadyEmitted = [emitted boolValue];
1769
- if (!alreadyEmitted) {
1769
+ if (keyboardEvent && !alreadyEmitted) {
1770
1770
  [_eventDispatcher sendEvent:keyboardEvent];
1771
1771
  objc_setAssociatedObject(event, &kRCTViewKeyboardEventEmittedKey, @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1772
1772
  }
@@ -353,6 +353,10 @@ RCT_CUSTOM_VIEW_PROPERTY(accessibilityState, NSDictionary, RCTView)
353
353
  NSMutableDictionary<NSString *, id> *newState = [NSMutableDictionary<NSString *, id> new];
354
354
 
355
355
  if (!state) {
356
+ #if TARGET_OS_OSX // [macOS
357
+ // Removing the prop must clear the previous state, e.g. so a TextInput is re-enabled once `disabled` goes away.
358
+ view.reactAccessibilityElement.accessibilityState = nil;
359
+ #endif // macOS]
356
360
  return;
357
361
  }
358
362
 
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.83.0
1
+ VERSION_NAME=0.83.1
2
2
  react.internal.publishingGroup=com.facebook.react
3
3
  react.internal.hermesPublishingGroup=com.facebook.hermes
4
4
 
@@ -14,7 +14,7 @@ public object ReactNativeVersion {
14
14
  public val VERSION: Map<String, Any?> = mapOf(
15
15
  "major" to 0,
16
16
  "minor" to 83,
17
- "patch" to 0,
17
+ "patch" to 1,
18
18
  "prerelease" to null
19
19
  )
20
20
  }
@@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN
52
52
 
53
53
  - (void)layoutSubviews;
54
54
 
55
+ - (void)safeAreaInsetsDidChange;
56
+
55
57
  - (void)setNeedsDisplay;
56
58
 
57
59
  @property (nonatomic, copy) NSColor *backgroundColor;
@@ -24,6 +24,7 @@
24
24
  BOOL _respondsToDisplayLayer;
25
25
  CATransform3D _transform3D;
26
26
  BOOL _hasCustomTransform3D;
27
+ NSEdgeInsets _lastSafeAreaInsets;
27
28
  }
28
29
 
29
30
  + (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key
@@ -60,6 +61,15 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
60
61
  return self;
61
62
  }
62
63
 
64
+ - (void)rct_updateSafeAreaInsets
65
+ {
66
+ NSEdgeInsets insets = self.safeAreaInsets;
67
+ if (!NSEdgeInsetsEqual(insets, _lastSafeAreaInsets)) {
68
+ _lastSafeAreaInsets = insets;
69
+ [self safeAreaInsetsDidChange];
70
+ }
71
+ }
72
+
63
73
  - (instancetype)initWithFrame:(NSRect)frameRect
64
74
  {
65
75
  return RCTUIViewCommonInit([super initWithFrame:frameRect]);
@@ -99,6 +109,7 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
99
109
  - (void)viewDidMoveToWindow
100
110
  {
101
111
  [self didMoveToWindow];
112
+ [self rct_updateSafeAreaInsets];
102
113
  }
103
114
 
104
115
  - (BOOL)mouseDownCanMoveWindow{
@@ -209,6 +220,7 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
209
220
  {
210
221
  [super layout];
211
222
  if (self.window != nil) {
223
+ [self rct_updateSafeAreaInsets];
212
224
  [self layoutSubviews];
213
225
  }
214
226
  }
@@ -281,6 +293,10 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
281
293
  [super layout];
282
294
  }
283
295
 
296
+ - (void)safeAreaInsetsDidChange
297
+ {
298
+ }
299
+
284
300
  - (void)setNeedsDisplay
285
301
  {
286
302
  self.needsDisplay = YES;
@@ -14,14 +14,14 @@
14
14
 
15
15
  #define REACT_NATIVE_VERSION_MAJOR 0
16
16
  #define REACT_NATIVE_VERSION_MINOR 83
17
- #define REACT_NATIVE_VERSION_PATCH 0
17
+ #define REACT_NATIVE_VERSION_PATCH 1
18
18
 
19
19
  namespace facebook::react {
20
20
 
21
21
  constexpr struct {
22
22
  int32_t Major = 0;
23
23
  int32_t Minor = 83;
24
- int32_t Patch = 0;
24
+ int32_t Patch = 1;
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
- if (family.nativeProps_DEPRECATED != nullptr) {
144
- auto propsParserContext = PropsParserContext{family_->getSurfaceId(), {}};
145
- if (fragment.props == ShadowNodeFragment::propsPlaceholder()) {
146
- // Clone existing `props_` with `family.nativeProps_DEPRECATED` to apply
147
- // previously set props via `setNativeProps` API.
148
- auto props = componentDescriptor.cloneProps(
149
- propsParserContext, props_, RawProps(*family.nativeProps_DEPRECATED));
150
- auto clonedNode = componentDescriptor.cloneShadowNode(
151
- *this,
152
- {.props = props,
153
- .children = fragment.children,
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
  std::shared_ptr<const ContextContainer> ShadowNode::getContextContainer()
167
177
  const {
@@ -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>
@@ -114,6 +115,7 @@ class ShadowNodeFamily final : public jsi::NativeState {
114
115
  * architecture and will be removed in the future.
115
116
  */
116
117
  mutable std::unique_ptr<folly::dynamic> nativeProps_DEPRECATED;
118
+ mutable std::mutex nativePropsMutex; // [macOS] Backport upstream #52646.
117
119
 
118
120
  /**
119
121
  * @return tag for the ShadowNodeFamily.
@@ -105,6 +105,7 @@ std::shared_ptr<ShadowNode> UIManager::createNode(
105
105
  return shadowNode;
106
106
  }
107
107
 
108
+ // [macOS Backport react/react-native@923e7ddcaf4d (#52646).
108
109
  std::shared_ptr<ShadowNode> UIManager::cloneNode(
109
110
  const ShadowNode& shadowNode,
110
111
  const ShadowNode::SharedListOfShared& children,
@@ -117,49 +118,51 @@ std::shared_ptr<ShadowNode> UIManager::cloneNode(
117
118
 
118
119
  auto& componentDescriptor = shadowNode.getComponentDescriptor();
119
120
  auto& family = shadowNode.getFamily();
120
- auto props = ShadowNodeFragment::propsPlaceholder();
121
121
 
122
+ auto props = ShadowNodeFragment::propsPlaceholder();
122
123
  if (!rawProps.isEmpty()) {
123
- if (family.nativeProps_DEPRECATED != nullptr) {
124
- // 1. update the nativeProps_DEPRECATED props.
125
- //
126
- // In this step, we want the most recent value for the props
127
- // managed by setNativeProps.
128
- // Values in `rawProps` patch (take precedence over)
129
- // `nativeProps_DEPRECATED`. For example, if both
130
- // `nativeProps_DEPRECATED` and `rawProps` contain key 'A'.
131
- // Value from `rawProps` overrides what was previously in
132
- // `nativeProps_DEPRECATED`. Notice that the `nativeProps_DEPRECATED`
133
- // patch will not get more props from `rawProps`: if the key is not
134
- // present in `nativeProps_DEPRECATED`, it will not be added.
135
- //
136
- // The result of this operation is the new `nativeProps_DEPRECATED`.
137
- family.nativeProps_DEPRECATED =
138
- std::make_unique<folly::dynamic>(mergeDynamicProps(
139
- *family.nativeProps_DEPRECATED, // source
140
- (folly::dynamic)rawProps, // patch
141
- NullValueStrategy::Ignore));
142
-
143
- // 2. Compute the final set of props.
144
- //
145
- // This step takes the new props handled by `setNativeProps` and
146
- // merges them in the `rawProps` managed by React.
147
- // The new props handled by `nativeProps` now takes precedence
148
- // on the props handled by React, as we want to make sure that
149
- // all the props are applied to the component.
150
- // We use these finalProps as source of truth for the component.
151
- auto finalProps = mergeDynamicProps(
152
- (folly::dynamic)rawProps, // source
153
- *family.nativeProps_DEPRECATED, // patch
154
- NullValueStrategy::Override);
155
-
156
- // 3. Clone the props by using finalProps.
157
- props = componentDescriptor.cloneProps(
158
- propsParserContext, shadowNode.getProps(), RawProps(finalProps));
159
- } else {
160
- props = componentDescriptor.cloneProps(
161
- propsParserContext, shadowNode.getProps(), std::move(rawProps));
124
+ std::optional<folly::dynamic> finalProps;
125
+ {
126
+ std::lock_guard<std::mutex> lock(family.nativePropsMutex);
127
+ if (family.nativeProps_DEPRECATED != nullptr) {
128
+ // 1. update the nativeProps_DEPRECATED props.
129
+ //
130
+ // In this step, we want the most recent value for the props
131
+ // managed by setNativeProps.
132
+ // Values in `rawProps` patch (take precedence over)
133
+ // `nativeProps_DEPRECATED`. For example, if both
134
+ // `nativeProps_DEPRECATED` and `rawProps` contain key 'A'.
135
+ // Value from `rawProps` overrides what was previously in
136
+ // `nativeProps_DEPRECATED`. Notice that the `nativeProps_DEPRECATED`
137
+ // patch will not get more props from `rawProps`: if the key is not
138
+ // present in `nativeProps_DEPRECATED`, it will not be added.
139
+ //
140
+ // The result of this operation is the new `nativeProps_DEPRECATED`.
141
+ family.nativeProps_DEPRECATED =
142
+ std::make_unique<folly::dynamic>(mergeDynamicProps(
143
+ *family.nativeProps_DEPRECATED, // source
144
+ (folly::dynamic)rawProps, // patch
145
+ NullValueStrategy::Ignore));
146
+
147
+ // 2. Compute the final set of props.
148
+ //
149
+ // This step takes the new props handled by `setNativeProps` and
150
+ // merges them in the `rawProps` managed by React.
151
+ // The new props handled by `nativeProps` now takes precedence
152
+ // on the props handled by React, as we want to make sure that
153
+ // all the props are applied to the component.
154
+ // We use these finalProps as source of truth for the component.
155
+ finalProps = mergeDynamicProps(
156
+ (folly::dynamic)rawProps, // source
157
+ *family.nativeProps_DEPRECATED, // patch
158
+ NullValueStrategy::Override);
159
+ }
162
160
  }
161
+
162
+ props = componentDescriptor.cloneProps(
163
+ propsParserContext,
164
+ shadowNode.getProps(),
165
+ finalProps ? RawProps(std::move(*finalProps)) : std::move(rawProps));
163
166
  }
164
167
 
165
168
  auto clonedShadowNode = componentDescriptor.cloneShadowNode(
@@ -172,6 +175,7 @@ std::shared_ptr<ShadowNode> UIManager::cloneNode(
172
175
 
173
176
  return clonedShadowNode;
174
177
  }
178
+ // macOS]
175
179
 
176
180
  void UIManager::appendChild(
177
181
  const std::shared_ptr<const ShadowNode>& parentShadowNode,
@@ -428,20 +432,25 @@ void UIManager::setNativeProps_DEPRECATED(
428
432
  const std::shared_ptr<const ShadowNode>& shadowNode,
429
433
  RawProps rawProps) const {
430
434
  auto& family = shadowNode->getFamily();
431
- if (family.nativeProps_DEPRECATED) {
432
- // Values in `rawProps` patch (take precedence over)
433
- // `nativeProps_DEPRECATED`. For example, if both `nativeProps_DEPRECATED`
434
- // and `rawProps` contain key 'A'. Value from `rawProps` overrides what was
435
- // previously in `nativeProps_DEPRECATED`.
436
- family.nativeProps_DEPRECATED =
437
- std::make_unique<folly::dynamic>(mergeDynamicProps(
438
- *family.nativeProps_DEPRECATED,
439
- (folly::dynamic)rawProps,
440
- NullValueStrategy::Override));
441
- } else {
442
- family.nativeProps_DEPRECATED =
443
- std::make_unique<folly::dynamic>((folly::dynamic)rawProps);
435
+ // [macOS Backport react/react-native@923e7ddcaf4d (#52646).
436
+ {
437
+ std::lock_guard<std::mutex> lock(family.nativePropsMutex);
438
+ if (family.nativeProps_DEPRECATED) {
439
+ // Values in `rawProps` patch (take precedence over)
440
+ // `nativeProps_DEPRECATED`. For example, if both `nativeProps_DEPRECATED`
441
+ // and `rawProps` contain key 'A'. Value from `rawProps` overrides what
442
+ // was previously in `nativeProps_DEPRECATED`.
443
+ family.nativeProps_DEPRECATED =
444
+ std::make_unique<folly::dynamic>(mergeDynamicProps(
445
+ *family.nativeProps_DEPRECATED,
446
+ (folly::dynamic)rawProps,
447
+ NullValueStrategy::Override));
448
+ } else {
449
+ family.nativeProps_DEPRECATED =
450
+ std::make_unique<folly::dynamic>((folly::dynamic)rawProps);
451
+ }
444
452
  }
453
+ // macOS]
445
454
 
446
455
  shadowTreeRegistry_.visit(
447
456
  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
- using namespace facebook::react;
20
+ namespace facebook::react {
14
21
 
15
- TEST(UIManagerTest, testSomething) {
16
- // TODO
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]
@@ -1,3 +1,5 @@
1
+ // [macOS]
2
+
1
3
  import SwiftUI
2
4
  import React
3
5
  import React_RCTAppDelegate
@@ -22,14 +24,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
22
24
  let reactNativeFactory: RCTReactNativeFactory
23
25
 
24
26
  override init() {
25
- super.init()
26
-
27
27
  let delegate = ReactNativeDelegate()
28
28
  let factory = RCTReactNativeFactory(delegate: delegate)
29
29
  delegate.dependencyProvider = RCTAppDependencyProvider()
30
30
 
31
31
  reactNativeDelegate = delegate
32
32
  reactNativeFactory = factory
33
+ super.init()
33
34
  }
34
35
  }
35
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.83.0",
3
+ "version": "0.83.1",
4
4
  "description": "React Native for macOS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -184,7 +184,7 @@
184
184
  },
185
185
  "dependencies": {
186
186
  "@jest/create-cache-key-function": "^29.7.0",
187
- "@react-native-macos/virtualized-lists": "0.83.0",
187
+ "@react-native-macos/virtualized-lists": "0.83.1",
188
188
  "@react-native/assets-registry": "0.83.10",
189
189
  "@react-native/codegen": "0.83.10",
190
190
  "@react-native/community-cli-plugin": "0.83.10",