react-native-macos 0.71.8 → 0.71.9

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.
@@ -12,6 +12,6 @@
12
12
  exports.version = {
13
13
  major: 0,
14
14
  minor: 71,
15
- patch: 8,
15
+ patch: 9,
16
16
  prerelease: null,
17
17
  };
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(71),
26
- RCTVersionPatch: @(8),
26
+ RCTVersionPatch: @(9),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -28,7 +28,7 @@ NSSharingServicePickerDelegate
28
28
  #endif // macOS]
29
29
  , NativeActionSheetManagerSpec>
30
30
 
31
- #if !TARGET_OS_OSX // [macOS]
31
+ #if !TARGET_OS_OSX // [macOS] Unlike iOS, we will only ever have one NSMenu present at a time
32
32
  @property (nonatomic, strong) NSMutableArray<UIAlertController *> *alertControllers;
33
33
  #endif // [macOS]
34
34
 
@@ -37,22 +37,30 @@ NSSharingServicePickerDelegate
37
37
  @implementation RCTActionSheetManager
38
38
  #if TARGET_OS_OSX // [macOS
39
39
  {
40
- // Use NSMapTable, as UIAlertViews do not implement <NSCopying>
41
- // which is required for NSDictionary keys
40
+ /* Unlike UIAlertAction (which takes a block for it's action), NSMenuItem takes a selector.
41
+ * That selector no longer has has access to the method argument `callback`, so we must save it
42
+ * as an instance variable, that we can access in `menuItemDidTap`. We must do this as well for
43
+ * `failureCallback` and `successCallback`.
44
+ */
42
45
  NSMapTable *_callbacks;
43
- NSArray<NSSharingService*> *_excludedActivities;
44
- NSString *_sharingSubject;
45
46
  RCTResponseSenderBlock _failureCallback;
46
47
  RCTResponseSenderBlock _successCallback;
48
+ NSArray<NSSharingService*> *_excludedActivities;
49
+ NSString *_sharingSubject;
50
+
47
51
  }
48
52
  #endif // macOS]
49
53
 
50
- #if !TARGET_OS_OSX // [macOS]
51
54
  - (instancetype)init
52
55
  {
53
56
  self = [super init];
54
57
  if (self) {
58
+ #if !TARGET_OS_OSX // [macOS]
55
59
  _alertControllers = [NSMutableArray new];
60
+ #else // [macOS
61
+ _callbacks = [NSMapTable new];
62
+ #endif // macOS]
63
+
56
64
  }
57
65
  return self;
58
66
  }
@@ -61,15 +69,10 @@ NSSharingServicePickerDelegate
61
69
  {
62
70
  return NO;
63
71
  }
64
- #endif // [macOS]
65
72
 
66
73
  RCT_EXPORT_MODULE()
67
74
 
68
- #if !TARGET_OS_OSX // [macOS]
69
75
  @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
70
- #else // [macOS
71
- @synthesize bridge = _bridge;
72
- #endif // macOS]
73
76
 
74
77
  - (dispatch_queue_t)methodQueue
75
78
  {
@@ -93,6 +96,28 @@ RCT_EXPORT_MODULE()
93
96
  alertController.popoverPresentationController.sourceRect = sourceView.bounds;
94
97
  [parentViewController presentViewController:alertController animated:YES completion:nil];
95
98
  }
99
+ #else // [macOS
100
+ - (void)presentMenu:(NSMenu *)menu
101
+ anchorViewTag:(NSNumber *)anchorViewTag
102
+ {
103
+ NSView *sourceView = nil;
104
+ if (anchorViewTag) {
105
+ sourceView = [self.viewRegistry_DEPRECATED viewForReactTag:anchorViewTag];
106
+ }
107
+
108
+ NSPoint location = CGPointZero;
109
+ if (sourceView != nil) {
110
+ // Display under the anchorview
111
+ CGRect bounds = [sourceView bounds];
112
+
113
+ CGFloat originX = [sourceView userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft ? NSMaxX(bounds) : NSMinX(bounds);
114
+ location = NSMakePoint(originX, NSMaxY(bounds));
115
+ } else {
116
+ // Display at mouse location if no anchorView provided
117
+ location = [NSEvent mouseLocation];
118
+ }
119
+ [menu popUpMenuPositioningItem:menu.itemArray.firstObject atLocation:location inView:sourceView];
120
+ }
96
121
  #endif // [macOS]
97
122
 
98
123
  RCT_EXPORT_METHOD(showActionSheetWithOptions
@@ -107,7 +132,7 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
107
132
  #endif // [macOS]
108
133
 
109
134
  NSString *title = options.title();
110
- #if !TARGET_OS_OSX // [macOS]
135
+ #if !TARGET_OS_OSX // [macOS] Unused on macOS
111
136
  NSString *message = options.message();
112
137
  #endif // [macOS]
113
138
  NSArray<NSString *> *buttons = RCTConvertOptionalVecToArray(options.options(), ^id(NSString *element) {
@@ -122,28 +147,28 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
122
147
  return @(element);
123
148
  });
124
149
  }
150
+ #if !TARGET_OS_OSX // [macOS] NSMenu doesn't have an equivalent of destructive buttons
125
151
  if (options.destructiveButtonIndices()) {
126
152
  destructiveButtonIndices = RCTConvertVecToArray(*options.destructiveButtonIndices(), ^id(double element) {
127
153
  return @(element);
128
154
  });
129
155
  } else {
130
- #if !TARGET_OS_OSX // [macOS]
131
156
  NSNumber *destructiveButtonIndex = @-1;
132
157
  destructiveButtonIndices = @[ destructiveButtonIndex ];
133
- #endif // [macOS]
134
158
  }
135
159
 
160
+ UIViewController *controller = RCTPresentedViewController();
161
+ #endif // [macOS]
136
162
  NSNumber *anchor = [RCTConvert NSNumber:options.anchor() ? @(*options.anchor()) : nil];
137
-
138
163
  #if !TARGET_OS_OSX // [macOS]
139
- UIViewController *controller = RCTPresentedViewController();
140
164
  UIColor *tintColor = [RCTConvert UIColor:options.tintColor() ? @(*options.tintColor()) : nil];
141
165
  UIColor *cancelButtonTintColor =
142
166
  [RCTConvert UIColor:options.cancelButtonTintColor() ? @(*options.cancelButtonTintColor()) : nil];
143
167
 
144
168
  if (controller == nil) {
169
+ // [macOS nil check our dict values before inserting them or we may crash
145
170
  RCTLogError(
146
- @"Tried to display action sheet but there is no application window. options: %@", @{ /* [macOS nil check our dict values before inserting them or we may crash */
171
+ @"Tried to display action sheet but there is no application window. options: %@", @{
147
172
  @"title" : title ?: [NSNull null],
148
173
  @"message" : message ?: [NSNull null],
149
174
  @"options" : buttons ?: [NSNull null],
@@ -153,10 +178,12 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
153
178
  @"tintColor" : tintColor ?: [NSNull null],
154
179
  @"cancelButtonTintColor" : cancelButtonTintColor ?: [NSNull null],
155
180
  @"disabledButtonIndices" : disabledButtonIndices ?: [NSNull null],
156
- }); /* [macOS] nil check our dict values before inserting them or we may crash ] */
181
+ });
182
+ // macOS]
157
183
  return;
158
184
  }
159
185
  #endif // [macOS]
186
+
160
187
  /*
161
188
  * The `anchor` option takes a view to set as the anchor for the share
162
189
  * popup to point to, on iPads running iOS 8. If it is not passed, it
@@ -168,14 +195,22 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
168
195
  UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
169
196
  message:message
170
197
  preferredStyle:UIAlertControllerStyleActionSheet];
198
+ #else // [macOS
199
+ NSMenu *menu = [[NSMenu alloc] initWithTitle:title ?: @""];
200
+ [menu setAutoenablesItems:NO];
201
+ [_callbacks setObject:callback forKey:menu];
202
+ #endif // macOS]
171
203
 
172
204
  NSInteger index = 0;
205
+ #if !TARGET_OS_OSX // [macOS]
173
206
  bool isCancelButtonIndex = false;
174
207
  // The handler for a button might get called more than once when tapping outside
175
208
  // the action sheet on iPad. RCTResponseSenderBlock can only be called once so
176
209
  // keep track of callback invocation here.
177
210
  __block bool callbackInvoked = false;
211
+ #endif // [macOS]
178
212
  for (NSString *option in buttons) {
213
+ #if !TARGET_OS_OSX // [macOS]
179
214
  UIAlertActionStyle style = UIAlertActionStyleDefault;
180
215
  if ([destructiveButtonIndices containsObject:@(index)]) {
181
216
  style = UIAlertActionStyleDestructive;
@@ -198,6 +233,17 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
198
233
  [actionButton setValue:cancelButtonTintColor forKey:@"titleTextColor"];
199
234
  }
200
235
  [alertController addAction:actionButton];
236
+ #else // [macOS
237
+ if (index == cancelButtonIndex) {
238
+ // NSMenu doesn't need a cancel button, you can just click outside the menu
239
+ continue;
240
+ }
241
+
242
+ NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:option action:@selector(menuItemDidTap:) keyEquivalent:@""];
243
+ [item setTag:index];
244
+ [item setTarget:self];
245
+ [menu addItem:item];
246
+ #endif // macOS]
201
247
 
202
248
  index++;
203
249
  }
@@ -205,7 +251,12 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
205
251
  if (disabledButtonIndices) {
206
252
  for (NSNumber *disabledButtonIndex in disabledButtonIndices) {
207
253
  if ([disabledButtonIndex integerValue] < buttons.count) {
254
+ #if !TARGET_OS_OSX // [macOS]
208
255
  [alertController.actions[[disabledButtonIndex integerValue]] setEnabled:false];
256
+ #else // [macOS
257
+ NSMenuItem *menuItem = [[menu itemArray] objectAtIndex:[disabledButtonIndex integerValue]];
258
+ [menuItem setEnabled:NO];
259
+ #endif // macOS]
209
260
  } else {
210
261
  RCTLogError(
211
262
  @"Index %@ from `disabledButtonIndices` is out of bounds. Maximum index value is %@.",
@@ -216,6 +267,7 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
216
267
  }
217
268
  }
218
269
 
270
+ #if !TARGET_OS_OSX // [macOS]
219
271
  alertController.view.tintColor = tintColor;
220
272
  #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
221
273
  __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
@@ -234,39 +286,8 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions
234
286
 
235
287
  [_alertControllers addObject:alertController];
236
288
  [self presentViewController:alertController onParentViewController:controller anchorViewTag:anchorViewTag];
237
-
238
289
  #else // [macOS
239
- NSMenu *menu = [[NSMenu alloc] initWithTitle:title ?: @""];
240
- [_callbacks setObject:callback forKey:menu];
241
- for (NSInteger index = 0; index < buttons.count; index++) {
242
- if (index == cancelButtonIndex) {
243
- //NSMenu doesn't require a cancel button
244
- continue;
245
- }
246
-
247
- NSString *option = buttons[index];
248
- NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:option action:@selector(menuItemDidTap:) keyEquivalent:@""];
249
- item.tag = index;
250
- item.target = self;
251
- [menu addItem:item];
252
- }
253
-
254
- RCTPlatformView *view = nil;
255
- if (anchorViewTag) {
256
- view = [self.bridge.uiManager viewForReactTag:anchorViewTag];
257
- }
258
- NSPoint location = CGPointZero;
259
- if (view != nil) {
260
- // Display under the anchorview
261
- CGRect bounds = [view bounds];
262
-
263
- CGFloat originX = [view userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft ? NSMaxX(bounds) : NSMinX(bounds);
264
- location = NSMakePoint(originX, NSMaxY(bounds));
265
- } else {
266
- // Display at mouse location if no anchorView provided
267
- location = [NSEvent mouseLocation];
268
- }
269
- [menu popUpMenuPositioningItem:menu.itemArray.firstObject atLocation:location inView:view];
290
+ [self presentMenu:menu anchorViewTag:anchorViewTag];
270
291
  #endif // macOS]
271
292
  }
272
293
 
@@ -378,12 +399,12 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions
378
399
  _sharingSubject = options.subject();
379
400
  _failureCallback = failureCallback;
380
401
  _successCallback = successCallback;
381
- RCTPlatformView *view = nil;
402
+ RCTPlatformView *sourceView = nil;
382
403
  NSNumber *anchorViewTag = [RCTConvert NSNumber:options.anchor() ? @(*options.anchor()) : nil];
383
404
  if (anchorViewTag) {
384
- view = [self.bridge.uiManager viewForReactTag:anchorViewTag];
405
+ sourceView = [self.viewRegistry_DEPRECATED viewForReactTag:anchorViewTag];
385
406
  }
386
- NSView *contentView = view ?: NSApp.keyWindow.contentView;
407
+ NSView *contentView = sourceView ?: NSApp.keyWindow.contentView;
387
408
  NSSharingServicePicker *picker = [[NSSharingServicePicker alloc] initWithItems:items];
388
409
  picker.delegate = self;
389
410
  [picker showRelativeToRect:contentView.bounds ofView:contentView preferredEdge:NSRectEdgeMinX];
@@ -396,14 +417,14 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions
396
417
 
397
418
  - (void)menuItemDidTap:(NSMenuItem*)menuItem
398
419
  {
399
- NSMenu *actionSheet = menuItem.menu;
420
+ NSMenu *menu = menuItem.menu;
400
421
  NSInteger buttonIndex = menuItem.tag;
401
- RCTResponseSenderBlock callback = [_callbacks objectForKey:actionSheet];
422
+ RCTResponseSenderBlock callback = [_callbacks objectForKey:menu];
402
423
  if (callback) {
403
424
  callback(@[@(buttonIndex)]);
404
- [_callbacks removeObjectForKey:actionSheet];
425
+ [_callbacks removeObjectForKey:menu];
405
426
  } else {
406
- RCTLogWarn(@"No callback registered for action sheet: %@", actionSheet.title);
427
+ RCTLogWarn(@"No callback registered for menu: %@", menu.title);
407
428
  }
408
429
  }
409
430
 
@@ -438,7 +459,6 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions
438
459
  return ![self->_excludedActivities containsObject:service];
439
460
  }]];
440
461
  }
441
-
442
462
  #endif // macOS]
443
463
 
444
464
  - (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.71.8
1
+ VERSION_NAME=0.71.9
2
2
  GROUP=com.facebook.react
3
3
 
4
4
  # JVM Versions
@@ -17,6 +17,6 @@ public class ReactNativeVersion {
17
17
  public static final Map<String, Object> VERSION = MapBuilder.<String, Object>of(
18
18
  "major", 0,
19
19
  "minor", 71,
20
- "patch", 8,
20
+ "patch", 9,
21
21
  "prerelease", null);
22
22
  }
@@ -17,7 +17,7 @@ namespace facebook::react {
17
17
  constexpr struct {
18
18
  int32_t Major = 0;
19
19
  int32_t Minor = 71;
20
- int32_t Patch = 8;
20
+ int32_t Patch = 9;
21
21
  std::string_view Prerelease = "";
22
22
  } ReactNativeVersion;
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.71.8",
3
+ "version": "0.71.9",
4
4
  "bin": "./cli.js",
5
5
  "description": "React Native for macOS",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "react": "18.2.0",
15
- "react-native-macos": "0.71.8"
15
+ "react-native-macos": "0.71.9"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@babel/core": "^7.20.0",