react-native-macos 0.0.0-8b8fc6196 → 0.0.0-8c3fcb33d

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 (29) hide show
  1. package/Libraries/Components/TextInput/TextInput.js +70 -1
  2. package/Libraries/Core/ReactNativeVersion.js +1 -1
  3. package/Libraries/Image/RCTImageView.mm +14 -10
  4. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h +3 -0
  5. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +3 -0
  6. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +11 -0
  7. package/Libraries/Text/TextInput/Multiline/RCTUITextView.h +1 -0
  8. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +58 -4
  9. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +5 -0
  10. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +6 -1
  11. package/Libraries/Text/TextInput/RCTBaseTextInputView.h +4 -1
  12. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +82 -0
  13. package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +6 -0
  14. package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +16 -0
  15. package/React/Base/RCTConvert.m +8 -5
  16. package/React/Base/RCTTouchHandler.m +4 -0
  17. package/React/Base/RCTUtils.m +6 -3
  18. package/React/Base/RCTVersion.m +1 -1
  19. package/React/CoreModules/RCTPerfMonitor.mm +1 -1
  20. package/React/Views/RCTView.h +1 -0
  21. package/React/Views/RCTView.m +41 -15
  22. package/ReactAndroid/gradle.properties +1 -1
  23. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  24. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  25. package/package.json +1 -1
  26. package/scripts/react_native_pods.rb +0 -3
  27. package/template/Gemfile.lock +2 -2
  28. package/template/package.json +1 -1
  29. package/third-party-podspecs/boost-for-react-native.podspec +0 -20
@@ -135,7 +135,27 @@ export type SettingChangeEvent = SyntheticEvent<
135
135
  $ReadOnly<{|
136
136
  enabled: boolean,
137
137
  |}>,
138
- >; // ]TODO(macOS GH#774)
138
+ >;
139
+
140
+ export type PasteEvent = SyntheticEvent<
141
+ $ReadOnly<{|
142
+ dataTransfer: {|
143
+ files: $ReadOnlyArray<{|
144
+ height: number,
145
+ size: number,
146
+ type: string,
147
+ uri: string,
148
+ width: number,
149
+ |}>,
150
+ items: $ReadOnlyArray<{|
151
+ kind: string,
152
+ type: string,
153
+ |}>,
154
+ types: $ReadOnlyArray<string>,
155
+ |},
156
+ |}>,
157
+ >;
158
+ // ]TODO(macOS GH#774)
139
159
 
140
160
  type DataDetectorTypesType =
141
161
  // iOS+macOS
@@ -333,6 +353,51 @@ type IOSProps = $ReadOnly<{|
333
353
  textContentType?: ?TextContentType,
334
354
  |}>;
335
355
 
356
+ // [TODO(macOS GH#774)
357
+ export type SubmitKeyEvent = $ReadOnly<{|
358
+ key: string,
359
+ altKey?: ?boolean,
360
+ ctrlKey?: ?boolean,
361
+ metaKey?: ?boolean,
362
+ shiftKey?: ?boolean,
363
+ functionKey?: ?boolean,
364
+ |}>;
365
+
366
+ type MacOSProps = $ReadOnly<{|
367
+ /**
368
+ * If `true`, clears the text field synchronously before `onSubmitEditing` is emitted.
369
+ * @platform macos
370
+ */
371
+ clearTextOnSubmit?: ?boolean,
372
+
373
+ /**
374
+ * Fired when a supported element is pasted
375
+ *
376
+ * @platform macos
377
+ */
378
+ onPaste?: (event: PasteEvent) => void,
379
+
380
+ /**
381
+ * Enables Paste support for certain types of pasted types
382
+ *
383
+ * Possible values for `pastedTypes` are:
384
+ *
385
+ * - `'fileUrl'`
386
+ * - `'image'`
387
+ * - `'string'`
388
+ *
389
+ * @platform macos
390
+ */
391
+ pastedTypes?: PastedTypesType,
392
+
393
+ /**
394
+ * Configures keys that can be used to submit editing for the TextInput. Defaults to 'Enter' key.
395
+ * @platform macos
396
+ */
397
+ submitKeyEvents?: ?$ReadOnlyArray<SubmitKeyEvent>,
398
+ |}>;
399
+ // ]TODO(macOS GH#774)
400
+
336
401
  type AndroidProps = $ReadOnly<{|
337
402
  /**
338
403
  * Specifies autocomplete hints for the system, so it can provide autofill. On Android, the system will always attempt to offer autofill by using heuristics to identify the type of content.
@@ -492,9 +557,13 @@ type AndroidProps = $ReadOnly<{|
492
557
  underlineColorAndroid?: ?ColorValue,
493
558
  |}>;
494
559
 
560
+ export type PasteType = 'fileUrl' | 'image' | 'string'; // TODO(macOS GH#774)
561
+ export type PastedTypesType = PasteType | $ReadOnlyArray<PasteType>; // TODO(macOS GH#774)
562
+
495
563
  export type Props = $ReadOnly<{|
496
564
  ...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
497
565
  ...IOSProps,
566
+ ...MacOSProps, // TODO(macOS GH#774)
498
567
  ...AndroidProps,
499
568
 
500
569
  /**
@@ -17,5 +17,5 @@ exports.version = {
17
17
  major: 0,
18
18
  minor: 0,
19
19
  patch: 0,
20
- prerelease: '8b8fc6196',
20
+ prerelease: '8c3fcb33d',
21
21
  };
@@ -128,6 +128,8 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
128
128
  // Whether the latest change of props requires the image to be reloaded
129
129
  BOOL _needsReload;
130
130
 
131
+ UIImage *_image; // TODO(macOS GH#774)
132
+
131
133
  RCTUIImageViewAnimated *_imageView;
132
134
 
133
135
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
@@ -199,10 +201,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
199
201
  if (_renderingMode != image.renderingMode) {
200
202
  image = [image imageWithRenderingMode:_renderingMode];
201
203
  }
202
- #else // [TODO(macOS GH#774)
203
- if ((_renderingMode == UIImageRenderingModeAlwaysTemplate) != [image isTemplate]) {
204
- [image setTemplate:(_renderingMode == UIImageRenderingModeAlwaysTemplate)];
205
- }
206
204
  #endif // ]TODO(macOS GH#774)
207
205
 
208
206
  if (_resizeMode == RCTResizeModeRepeat) {
@@ -211,6 +209,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
211
209
  #else // [TODO(macOS GH#774)
212
210
  image.capInsets = _capInsets;
213
211
  image.resizingMode = NSImageResizingModeTile;
212
+ } else if (_resizeMode == RCTResizeModeCover) {
213
+ if (!NSEqualSizes(self.bounds.size, NSZeroSize)) {
214
+ image = RCTFillImagePreservingAspectRatio(image, self.bounds.size, self.window.backingScaleFactor ?: 1.0);
215
+ }
214
216
  #endif // ]TODO(macOS GH#774)
215
217
  } else if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, _capInsets)) {
216
218
  // Applying capInsets of 0 will switch the "resizingMode" of the image to "tile" which is undesired
@@ -222,6 +224,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
222
224
  #endif // ]TODO(macOS GH#774)
223
225
  }
224
226
 
227
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
228
+ if ((_renderingMode == UIImageRenderingModeAlwaysTemplate) != [image isTemplate]) {
229
+ [image setTemplate:(_renderingMode == UIImageRenderingModeAlwaysTemplate)];
230
+ }
231
+ #endif // ]TODO(macOS GH#774)
232
+
225
233
  // Apply trilinear filtering to smooth out mis-sized images
226
234
  _imageView.layer.minificationFilter = kCAFilterTrilinear;
227
235
  _imageView.layer.magnificationFilter = kCAFilterTrilinear;
@@ -233,17 +241,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
233
241
  {
234
242
  image = image ?: _defaultImage;
235
243
  if (image != self.image) {
236
- #if TARGET_OS_OSX // [TODO(macOS GH#774)
237
- if (image && _resizeMode == RCTResizeModeCover && !NSEqualSizes(self.bounds.size, NSZeroSize)) {
238
- image = RCTFillImagePreservingAspectRatio(image, self.bounds.size, self.window.backingScaleFactor ?: 1.0);
239
- }
240
- #endif // ]TODO(macOS GH#774)
244
+ _image = image; // TODO(macOS GH#774)
241
245
  [self updateWithImage:image];
242
246
  }
243
247
  }
244
248
 
245
249
  - (UIImage *)image {
246
- return _imageView.image;
250
+ return _image ?: _imageView.image; // TODO(macOS GH#774)
247
251
  }
248
252
 
249
253
  - (void)setBlurRadius:(CGFloat)blurRadius
@@ -11,6 +11,9 @@ NS_ASSUME_NONNULL_BEGIN
11
11
 
12
12
  @interface RCTMultilineTextInputView : RCTBaseTextInputView
13
13
 
14
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
15
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
16
+ #endif // ]TODO(macOS GH#774)
14
17
  @end
15
18
 
16
19
  NS_ASSUME_NONNULL_END
@@ -99,6 +99,9 @@
99
99
  }
100
100
  }
101
101
 
102
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes {
103
+ [_backedTextInputView setReadablePasteBoardTypes:readablePasteboardTypes];
104
+ }
102
105
  #endif // ]TODO(macOS GH#774)
103
106
 
104
107
  #pragma mark - UIScrollViewDelegate
@@ -7,6 +7,7 @@
7
7
 
8
8
  #import <React/RCTMultilineTextInputViewManager.h>
9
9
  #import <React/RCTMultilineTextInputView.h>
10
+ #import <React/RCTUITextView.h> // TODO(macOS GH#774)
10
11
 
11
12
  @implementation RCTMultilineTextInputViewManager
12
13
 
@@ -22,4 +23,14 @@ RCT_EXPORT_MODULE()
22
23
  RCT_REMAP_NOT_OSX_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.dataDetectorTypes, UIDataDetectorTypes) // TODO(macOS GH#774)
23
24
  RCT_REMAP_OSX_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.enabledTextCheckingTypes, NSTextCheckingTypes) // TODO(macOS GH#774)
24
25
 
26
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
27
+ RCT_CUSTOM_VIEW_PROPERTY(pastedTypes, NSArray<NSPasteboardType>*, RCTUITextView)
28
+ {
29
+ NSArray<NSPasteboardType> *types = json ? [RCTConvert NSPasteboardTypeArray:json] : nil;
30
+ if ([view respondsToSelector:@selector(setReadablePasteBoardTypes:)]) {
31
+ [view setReadablePasteBoardTypes: types];
32
+ }
33
+ }
34
+ #endif // ]TODO(macOS GH#774)
35
+
25
36
  @end
@@ -53,6 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
53
53
  @property (nonatomic, assign) NSTextAlignment textAlignment;
54
54
  @property (nonatomic, copy, nullable) NSAttributedString *attributedText;
55
55
  - (NSSize)sizeThatFits:(NSSize)size;
56
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
56
57
  #endif // ]TODO(macOS GH#774)
57
58
 
58
59
  @end
@@ -21,6 +21,9 @@
21
21
  #endif // TODO(macOS GH#774)
22
22
  RCTBackedTextViewDelegateAdapter *_textInputDelegateAdapter;
23
23
  NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes;
24
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
25
+ NSArray<NSPasteboardType> *_readablePasteboardTypes;
26
+ #endif // TODO(macOS GH#774)
24
27
  }
25
28
 
26
29
  static UIFont *defaultPlaceholderFont()
@@ -177,6 +180,11 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
177
180
  self.string = text;
178
181
  }
179
182
 
183
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes
184
+ {
185
+ _readablePasteboardTypes = readablePasteboardTypes;
186
+ }
187
+
180
188
  - (void)setTypingAttributes:(__unused NSDictionary *)typingAttributes
181
189
  {
182
190
  // Prevent NSTextView from changing its own typing attributes out from under us.
@@ -320,12 +328,45 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
320
328
  {
321
329
  return [super selectedRange];
322
330
  }
331
+
332
+ - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)draggingInfo
333
+ {
334
+ NSDragOperation dragOperation = [self.textInputDelegate textInputDraggingEntered:draggingInfo];
335
+ NSDragOperation superOperation = [super draggingEntered:draggingInfo];
336
+ // The delegate's operation should take precedence.
337
+ return dragOperation != NSDragOperationNone ? dragOperation : superOperation;
338
+ }
339
+
340
+ - (void)draggingExited:(id<NSDraggingInfo>)draggingInfo
341
+ {
342
+ [self.textInputDelegate textInputDraggingExited:draggingInfo];
343
+ [super draggingExited:draggingInfo];
344
+ }
345
+
346
+ - (BOOL)performDragOperation:(id<NSDraggingInfo>)draggingInfo
347
+ {
348
+ if ([self.textInputDelegate textInputShouldHandleDragOperation:draggingInfo]) {
349
+ return [super performDragOperation:draggingInfo];
350
+ }
351
+ return YES;
352
+ }
353
+ - (NSArray *)readablePasteboardTypes
354
+ {
355
+ return _readablePasteboardTypes ? _readablePasteboardTypes : [super readablePasteboardTypes];
356
+ }
357
+
323
358
  #endif // ]TODO(macOS GH#774)
324
359
 
325
360
  - (void)paste:(id)sender
326
361
  {
327
- [super paste:sender];
328
- _textWasPasted = YES;
362
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
363
+ if ([self.textInputDelegate textInputShouldHandlePaste:self]) {
364
+ #endif
365
+ [super paste:sender];
366
+ _textWasPasted = YES;
367
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
368
+ }
369
+ #endif
329
370
  }
330
371
 
331
372
  // Turn off scroll animation to fix flaky scrolling.
@@ -383,6 +424,10 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
383
424
  // UI/NSTextField do NOT have textContainerInset properties
384
425
  _textContainerInsets = textContainerInsets;
385
426
  super.textContainerInset = NSMakeSize(MIN(textContainerInsets.left, textContainerInsets.right), MIN(textContainerInsets.top, textContainerInsets.bottom));
427
+
428
+ if (self.shouldDrawInsertionPoint) {
429
+ [self updateInsertionPointStateAndRestartTimer:NO];
430
+ }
386
431
  }
387
432
 
388
433
  #endif // ]TODO(macOS GH#774)
@@ -516,9 +561,18 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
516
561
  }
517
562
  #else
518
563
  - (void)keyDown:(NSEvent *)event {
519
- // If hasMarkedText is true then an IME is open, so don't send event to JS.
520
- if (self.hasMarkedText || [self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
564
+ // If has marked text, handle by native and return
565
+ // Do this check before textInputShouldHandleKeyEvent as that one attempts to send the event to JS
566
+ if (self.hasMarkedText) {
567
+ [super keyDown:event];
568
+ return;
569
+ }
570
+
571
+ // textInputShouldHandleKeyEvent represents if native should handle the event instead of JS.
572
+ // textInputShouldHandleKeyEvent also sends keyDown event to JS internally, so we only call this once
573
+ if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
521
574
  [super keyDown:event];
575
+ [self.textInputDelegate submitOnKeyDownIfNeeded:event];
522
576
  }
523
577
  }
524
578
 
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
26
26
  - (void)automaticSpellingCorrectionDidChange:(BOOL)enabled;
27
27
  - (void)continuousSpellCheckingDidChange:(BOOL)enabled;
28
28
  - (void)grammarCheckingDidChange:(BOOL)enabled;
29
+ - (void)submitOnKeyDownIfNeeded:(NSEvent *)event;
29
30
  #endif // ]TODO(macOS GH#774)
30
31
 
31
32
  /*
@@ -44,7 +45,11 @@ NS_ASSUME_NONNULL_BEGIN
44
45
  - (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
45
46
  - (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event; // Return `YES` to have the key event handled normally. Return `NO` to disallow it and handle it yourself.
46
47
  - (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key;
48
+ - (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo;
49
+ - (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
50
+ - (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;
47
51
  - (void)textInputDidCancel; // Handle `Escape` key press.
52
+ - (BOOL)textInputShouldHandlePaste:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the paste event handled normally. Return `NO` to disallow it and handle it yourself.
48
53
  #endif // ]TODO(macOS GH#774)
49
54
 
50
55
  @optional
@@ -213,7 +213,12 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
213
213
  }
214
214
  //paste
215
215
  } else if (commandSelector == @selector(paste:)) {
216
- _backedTextInputView.textWasPasted = YES;
216
+ id<RCTBackedTextInputDelegate> textInputDelegate = [_backedTextInputView textInputDelegate];
217
+ if (textInputDelegate != nil && ![textInputDelegate textInputShouldHandlePaste:_backedTextInputView]) {
218
+ commandHandled = YES;
219
+ } else {
220
+ _backedTextInputView.textWasPasted = YES;
221
+ }
217
222
  //escape
218
223
  } else if (commandSelector == @selector(cancelOperation:)) {
219
224
  [textInputDelegate textInputDidCancel];
@@ -39,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
39
39
  @property (nonatomic, copy, nullable) RCTDirectEventBlock onContentSizeChange;
40
40
  @property (nonatomic, copy, nullable) RCTDirectEventBlock onSelectionChange;
41
41
  @property (nonatomic, copy, nullable) RCTDirectEventBlock onChange;
42
+ @property (nonatomic, copy, nullable) RCTDirectEventBlock onPaste; // TODO(OSS Candidate GH#774)
42
43
  @property (nonatomic, copy, nullable) RCTDirectEventBlock onChangeSync;
43
44
  @property (nonatomic, copy, nullable) RCTDirectEventBlock onTextInput;
44
45
  @property (nonatomic, copy, nullable) RCTDirectEventBlock onScroll;
@@ -46,8 +47,10 @@ NS_ASSUME_NONNULL_BEGIN
46
47
  @property (nonatomic, copy, nullable) RCTBubblingEventBlock onAutoCorrectChange;
47
48
  @property (nonatomic, copy, nullable) RCTBubblingEventBlock onSpellCheckChange;
48
49
  @property (nonatomic, copy, nullable) RCTBubblingEventBlock onGrammarCheckChange;
50
+ @property (nonatomic, assign) BOOL clearTextOnSubmit;
51
+ @property (nonatomic, copy, nullable) RCTDirectEventBlock onSubmitEditing;
52
+ @property (nonatomic, copy) NSArray<NSDictionary *> *submitKeyEvents;
49
53
  #endif // TODO(macOS GH#774)
50
-
51
54
  @property (nonatomic, assign) NSInteger mostRecentEventCount;
52
55
  @property (nonatomic, assign, readonly) NSInteger nativeEventCount;
53
56
  @property (nonatomic, assign) BOOL autoFocus;
@@ -14,10 +14,12 @@
14
14
  #import <React/RCTUtils.h>
15
15
  #import <React/UIView+React.h>
16
16
 
17
+ #import <React/RCTViewKeyboardEvent.h> // TODO(macOS GH#774)
17
18
  #import <React/RCTInputAccessoryView.h>
18
19
  #import <React/RCTInputAccessoryViewContent.h>
19
20
  #import <React/RCTTextAttributes.h>
20
21
  #import <React/RCTTextSelection.h>
22
+ #import <React/RCTUITextView.h> // TODO(macOS GH#774)
21
23
  #import "../RCTTextUIKit.h" // TODO(macOS GH#774)
22
24
 
23
25
  @implementation RCTBaseTextInputView {
@@ -428,6 +430,46 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
428
430
  _onGrammarCheckChange(@{@"enabled": [NSNumber numberWithBool:enabled]});
429
431
  }
430
432
  }
433
+
434
+ - (void)submitOnKeyDownIfNeeded:(NSEvent *)event
435
+ {
436
+ NSDictionary *currentKeyboardEvent = [RCTViewKeyboardEvent bodyFromEvent:event];
437
+ // Enter is the default clearTextOnSubmit key
438
+ BOOL shouldSubmit = NO;
439
+ if (!_submitKeyEvents) {
440
+ shouldSubmit = [currentKeyboardEvent[@"key"] isEqualToString:@"Enter"]
441
+ && ![currentKeyboardEvent[@"altKey"] boolValue]
442
+ && ![currentKeyboardEvent[@"shiftKey"] boolValue]
443
+ && ![currentKeyboardEvent[@"ctrlKey"] boolValue]
444
+ && ![currentKeyboardEvent[@"metaKey"] boolValue]
445
+ && ![currentKeyboardEvent[@"functionKey"] boolValue]; // Default clearTextOnSubmit key
446
+ } else {
447
+ for (NSDictionary *submitKeyEvent in _submitKeyEvents) {
448
+ if (
449
+ [submitKeyEvent[@"key"] isEqualToString:currentKeyboardEvent[@"key"]] &&
450
+ [submitKeyEvent[@"altKey"] boolValue] == [currentKeyboardEvent[@"altKey"] boolValue] &&
451
+ [submitKeyEvent[@"shiftKey"] boolValue] == [currentKeyboardEvent[@"shiftKey"] boolValue] &&
452
+ [submitKeyEvent[@"ctrlKey"] boolValue]== [currentKeyboardEvent[@"ctrlKey"] boolValue] &&
453
+ [submitKeyEvent[@"metaKey"] boolValue]== [currentKeyboardEvent[@"metaKey"] boolValue] &&
454
+ [submitKeyEvent[@"functionKey"] boolValue]== [currentKeyboardEvent[@"functionKey"] boolValue]
455
+ ) {
456
+ shouldSubmit = YES;
457
+ break;
458
+ }
459
+ }
460
+ }
461
+
462
+ if (shouldSubmit) {
463
+ if (_onSubmitEditing) {
464
+ _onSubmitEditing(@{});
465
+ }
466
+
467
+ if (_clearTextOnSubmit) {
468
+ self.backedTextInputView.attributedText = [NSAttributedString new];
469
+ [self.backedTextInputView.textInputDelegate textInputDidChange];
470
+ }
471
+ }
472
+ }
431
473
  #endif // ]TODO(macOS GH#774)
432
474
 
433
475
  - (BOOL)textInputShouldReturn
@@ -598,6 +640,31 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
598
640
  return [self.validKeysDown containsObject:key] || [self.validKeysUp containsObject:key];
599
641
  }
600
642
 
643
+ - (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo
644
+ {
645
+ if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
646
+ return [self draggingEntered:draggingInfo];
647
+ }
648
+ return NSDragOperationNone;
649
+ }
650
+
651
+ - (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo
652
+ {
653
+ if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
654
+ [self draggingExited:draggingInfo];
655
+ }
656
+ }
657
+
658
+ - (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo
659
+ {
660
+ if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
661
+ [self performDragOperation:draggingInfo];
662
+ return NO;
663
+ }
664
+
665
+ return YES;
666
+ }
667
+
601
668
  - (void)textInputDidCancel {
602
669
  [_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
603
670
  reactTag:self.reactTag
@@ -610,6 +677,21 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
610
677
  - (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event {
611
678
  return ![self handleKeyboardEvent:event];
612
679
  }
680
+
681
+ - (BOOL)textInputShouldHandlePaste:(__unused id)sender
682
+ {
683
+ NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
684
+ NSPasteboardType fileType = [pasteboard availableTypeFromArray:@[NSPasteboardTypeFileURL, NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
685
+ NSArray<NSPasteboardType>* pastedTypes = ((RCTUITextView*) self.backedTextInputView).readablePasteboardTypes;
686
+
687
+ // If there's a fileType that is of interest, notify JS. Also blocks notifying JS if it's a text paste
688
+ if (_onPaste && fileType != nil && [pastedTypes containsObject:fileType]) {
689
+ _onPaste([self dataTransferInfoFromPasteboard:pasteboard]);
690
+ }
691
+
692
+ // Only allow pasting text.
693
+ return fileType == nil;
694
+ }
613
695
  #endif // ]TODO(macOS GH#774)
614
696
 
615
697
  - (void)updateLocalData
@@ -71,12 +71,18 @@ RCT_EXPORT_VIEW_PROPERTY(passwordRules, NSString)
71
71
  RCT_EXPORT_VIEW_PROPERTY(onAutoCorrectChange, RCTBubblingEventBlock);
72
72
  RCT_EXPORT_VIEW_PROPERTY(onSpellCheckChange, RCTBubblingEventBlock);
73
73
  RCT_EXPORT_VIEW_PROPERTY(onGrammarCheckChange, RCTBubblingEventBlock);
74
+
75
+ // Specifically for clearing text on enter key press
76
+ RCT_EXPORT_VIEW_PROPERTY(clearTextOnSubmit, BOOL);
77
+ RCT_EXPORT_VIEW_PROPERTY(onSubmitEditing, RCTBubblingEventBlock);
78
+ RCT_EXPORT_VIEW_PROPERTY(submitKeyEvents, NSArray<NSDictionary *>);
74
79
  #endif // TODO(macOS GH#774)
75
80
 
76
81
  RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
77
82
  RCT_EXPORT_VIEW_PROPERTY(onKeyPressSync, RCTDirectEventBlock)
78
83
  RCT_EXPORT_VIEW_PROPERTY(onChangeSync, RCTDirectEventBlock)
79
84
  RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
85
+ RCT_EXPORT_VIEW_PROPERTY(onPaste, RCTDirectEventBlock)
80
86
  RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
81
87
  RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
82
88
 
@@ -151,11 +151,27 @@
151
151
 
152
152
  - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
153
153
  {
154
+ if (UIEdgeInsetsEqualToEdgeInsets(textContainerInset, _textContainerInset)) {
155
+ return;
156
+ }
157
+
154
158
  _textContainerInset = textContainerInset;
155
159
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
156
160
  [self setNeedsLayout];
157
161
  #else // [TODO(macOS GH#774)
158
162
  ((RCTUITextFieldCell*)self.cell).textContainerInset = _textContainerInset;
163
+
164
+ if (self.currentEditor) {
165
+ NSRange selectedRange = self.currentEditor.selectedRange;
166
+
167
+ // Relocate the NSTextView without changing the selection.
168
+ [self.cell selectWithFrame:self.bounds
169
+ inView:self
170
+ editor:self.currentEditor
171
+ delegate:self
172
+ start:selectedRange.location
173
+ length:selectedRange.length];
174
+ }
159
175
  #endif // ]TODO(macOS GH#774)
160
176
  }
161
177
 
@@ -1233,9 +1233,12 @@ RCT_JSON_ARRAY_CONVERTER(NSNumber)
1233
1233
  }
1234
1234
 
1235
1235
  if ([type isEqualToString:@"fileUrl"]) {
1236
- return @[NSFilenamesPboardType];
1236
+ return @[NSPasteboardTypeFileURL];
1237
+ } else if ([type isEqualToString:@"image"]) {
1238
+ return @[NSPasteboardTypePNG, NSPasteboardTypeTIFF];
1239
+ } else if ([type isEqualToString:@"string"]) {
1240
+ return @[NSPasteboardTypeString];
1237
1241
  }
1238
-
1239
1242
  return @[];
1240
1243
  }
1241
1244
 
@@ -1244,11 +1247,11 @@ RCT_JSON_ARRAY_CONVERTER(NSNumber)
1244
1247
  if ([json isKindOfClass:[NSString class]]) {
1245
1248
  return [RCTConvert NSPasteboardType:json];
1246
1249
  } else if ([json isKindOfClass:[NSArray class]]) {
1247
- NSMutableArray *mutablePastboardTypes = [NSMutableArray new];
1250
+ NSMutableArray *mutablePasteboardTypes = [NSMutableArray new];
1248
1251
  for (NSString *type in json) {
1249
- [mutablePastboardTypes addObjectsFromArray:[RCTConvert NSPasteboardType:type]];
1250
- return mutablePastboardTypes.copy;
1252
+ [mutablePasteboardTypes addObjectsFromArray:[RCTConvert NSPasteboardType:type]];
1251
1253
  }
1254
+ return mutablePasteboardTypes.copy;
1252
1255
  }
1253
1256
  return @[];
1254
1257
  }
@@ -10,6 +10,7 @@
10
10
  #if !TARGET_OS_OSX // [TODO(macOS GH#774)
11
11
  #import <UIKit/UIGestureRecognizerSubclass.h>
12
12
  #endif // ]TODO(macOS GH#774)
13
+ #import <React/RCTUITextField.h> // TODO(macOS GH#774)
13
14
 
14
15
  #import "RCTAssert.h"
15
16
  #import "RCTBridge.h"
@@ -138,6 +139,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)coder)
138
139
  _shouldSendMouseUpOnSystemBehalf = [(NSControl*)targetView isEnabled];
139
140
  } else if ([targetView isKindOfClass:[NSText class]]) {
140
141
  _shouldSendMouseUpOnSystemBehalf = [(NSText*)targetView isSelectable];
142
+ }
143
+ else if ([targetView.superview isKindOfClass:[RCTUITextField class]]) {
144
+ _shouldSendMouseUpOnSystemBehalf = [(RCTUITextField*)targetView.superview isSelectable];
141
145
  } else {
142
146
  _shouldSendMouseUpOnSystemBehalf = NO;
143
147
  }
@@ -905,9 +905,12 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL)
905
905
  }
906
906
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
907
907
  image = [UIImage imageWithContentsOfFile:filePath];
908
- #else // TODO(macOS GH#774)
909
- image = [[NSImage alloc] initWithContentsOfFile:filePath]; // TODO(macOS GH#774)
910
- #endif // TODO(macOS GH#774)
908
+ #else // [TODO(macOS GH#774)
909
+ // macOS keeps file handles in open state for lifetime of image if "initWithContentsOfFile:" is used with path inside app bundle
910
+ // Workaround is to load file in data and then convert data to image
911
+ NSData *data = [NSData dataWithContentsOfFile:filePath];
912
+ image = [[NSImage alloc] initWithData:data];
913
+ #endif // ]TODO(macOS GH#774)
911
914
  }
912
915
  }
913
916
 
@@ -28,7 +28,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
28
28
  RCTVersionMajor: @(0),
29
29
  RCTVersionMinor: @(0),
30
30
  RCTVersionPatch: @(0),
31
- RCTVersionPrerelease: @"8b8fc6196",
31
+ RCTVersionPrerelease: @"8c3fcb33d",
32
32
  };
33
33
  });
34
34
  return __rnVersion;
@@ -176,7 +176,7 @@ RCT_EXPORT_MODULE()
176
176
  {
177
177
  if (!_devMenuItem) {
178
178
  __weak __typeof__(self) weakSelf = self;
179
- __weak RCTDevSettings *devSettings = [self->_moduleRegistry moduleForName:"DevSettings"];
179
+ __weak RCTDevSettings *devSettings = [[self bridge] devSettings]; // TODO(macOS GH#774)
180
180
  if (devSettings.isPerfMonitorShown) {
181
181
  [weakSelf show];
182
182
  }
@@ -31,6 +31,7 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
31
31
  - (BOOL)resignFirstResponder;
32
32
 
33
33
  #if TARGET_OS_OSX
34
+ - (NSDictionary*)dataTransferInfoFromPasteboard:(NSPasteboard*)pasteboard;
34
35
  - (BOOL)handleKeyboardEvent:(NSEvent *)event;
35
36
  #endif
36
37
  // ]TODO(OSS Candidate ISS#2710739)
@@ -1527,13 +1527,9 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1527
1527
  block(body);
1528
1528
  }
1529
1529
 
1530
- - (NSDictionary*)dataTransferInfoFromPastboard:(NSPasteboard*)pastboard
1530
+ - (NSDictionary*)dataTransferInfoFromPasteboard:(NSPasteboard*)pasteboard
1531
1531
  {
1532
- if (![pastboard.types containsObject:NSFilenamesPboardType]) {
1533
- return @{};
1534
- }
1535
-
1536
- NSArray *fileNames = [pastboard propertyListForType:NSFilenamesPboardType];
1532
+ NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType] ?: @[];
1537
1533
  NSMutableArray *files = [[NSMutableArray alloc] initWithCapacity:fileNames.count];
1538
1534
  NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:fileNames.count];
1539
1535
  NSMutableArray *types = [[NSMutableArray alloc] initWithCapacity:fileNames.count];
@@ -1559,11 +1555,21 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1559
1555
  BOOL success = [fileURL getResourceValue:&fileSizeValue
1560
1556
  forKey:NSURLFileSizeKey
1561
1557
  error:&fileSizeError];
1562
-
1558
+
1559
+ NSNumber *width = nil;
1560
+ NSNumber *height = nil;
1561
+ if ([MIMETypeString hasPrefix:@"image/"]) {
1562
+ NSImage *image = [[NSImage alloc] initWithContentsOfURL:fileURL];
1563
+ width = @(image.size.width);
1564
+ height = @(image.size.height);
1565
+ }
1566
+
1563
1567
  [files addObject:@{@"name": RCTNullIfNil(fileURL.lastPathComponent),
1564
1568
  @"type": RCTNullIfNil(MIMETypeString),
1565
- @"uri": RCTNullIfNil(fileURL.absoluteString),
1566
- @"size": success ? fileSizeValue : (id)kCFNull
1569
+ @"uri": RCTNullIfNil(fileURL.path),
1570
+ @"size": success ? fileSizeValue : (id)kCFNull,
1571
+ @"width": RCTNullIfNil(width),
1572
+ @"height": RCTNullIfNil(height)
1567
1573
  }];
1568
1574
 
1569
1575
  [items addObject:@{@"kind": @"file",
@@ -1573,7 +1579,27 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1573
1579
  [types addObject:RCTNullIfNil(MIMETypeString)];
1574
1580
  }
1575
1581
  }
1576
-
1582
+
1583
+ NSPasteboardType imageType = [pasteboard availableTypeFromArray:@[NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
1584
+ if (imageType && fileNames.count == 0) {
1585
+ NSString *MIMETypeString = imageType == NSPasteboardTypePNG ? @"image/png" : @"image/tiff";
1586
+ NSData *imageData = [pasteboard dataForType:imageType];
1587
+ NSImage *image = [[NSImage alloc] initWithData:imageData];
1588
+
1589
+ [files addObject:@{@"type": RCTNullIfNil(MIMETypeString),
1590
+ @"uri": RCTDataURL(MIMETypeString, imageData).absoluteString,
1591
+ @"size": @(imageData.length),
1592
+ @"width": @(image.size.width),
1593
+ @"height": @(image.size.height),
1594
+ }];
1595
+
1596
+ [items addObject:@{@"kind": @"image",
1597
+ @"type": RCTNullIfNil(MIMETypeString),
1598
+ }];
1599
+
1600
+ [types addObject:RCTNullIfNil(MIMETypeString)];
1601
+ }
1602
+
1577
1603
  return @{@"dataTransfer": @{@"files": files,
1578
1604
  @"items": items,
1579
1605
  @"types": types}};
@@ -1598,9 +1624,9 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1598
1624
  [self sendMouseEventWithBlock:self.onDragEnter
1599
1625
  locationInfo:[self locationInfoFromDraggingLocation:sender.draggingLocation]
1600
1626
  modifierFlags:0
1601
- additionalData:[self dataTransferInfoFromPastboard:pboard]];
1602
-
1603
- if ([pboard.types containsObject:NSFilenamesPboardType]) {
1627
+ additionalData:[self dataTransferInfoFromPasteboard:pboard]];
1628
+
1629
+ if ([pboard availableTypeFromArray:self.registeredDraggedTypes]) {
1604
1630
  if (sourceDragMask & NSDragOperationLink) {
1605
1631
  return NSDragOperationLink;
1606
1632
  } else if (sourceDragMask & NSDragOperationCopy) {
@@ -1615,7 +1641,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1615
1641
  [self sendMouseEventWithBlock:self.onDragLeave
1616
1642
  locationInfo:[self locationInfoFromDraggingLocation:sender.draggingLocation]
1617
1643
  modifierFlags:0
1618
- additionalData:[self dataTransferInfoFromPastboard:sender.draggingPasteboard]];
1644
+ additionalData:[self dataTransferInfoFromPasteboard:sender.draggingPasteboard]];
1619
1645
  }
1620
1646
 
1621
1647
  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
@@ -1623,7 +1649,7 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1623
1649
  [self sendMouseEventWithBlock:self.onDrop
1624
1650
  locationInfo:[self locationInfoFromDraggingLocation:sender.draggingLocation]
1625
1651
  modifierFlags:0
1626
- additionalData:[self dataTransferInfoFromPastboard:[sender draggingPasteboard]]];
1652
+ additionalData:[self dataTransferInfoFromPasteboard:sender.draggingPasteboard]];
1627
1653
  return YES;
1628
1654
  }
1629
1655
  #endif // ]TODO(macOS GH#774)
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.0.0-8b8fc6196
1
+ VERSION_NAME=0.0.0-8c3fcb33d
2
2
  GROUP=com.facebook.react
3
3
 
4
4
  POM_NAME=ReactNative
@@ -22,5 +22,5 @@ public class ReactNativeVersion {
22
22
  "major", 0,
23
23
  "minor", 0,
24
24
  "patch", 0,
25
- "prerelease", "8b8fc6196");
25
+ "prerelease", "8c3fcb33d");
26
26
  }
@@ -22,7 +22,7 @@ constexpr struct {
22
22
  int32_t Major = 0;
23
23
  int32_t Minor = 0;
24
24
  int32_t Patch = 0;
25
- std::string_view Prerelease = "8b8fc6196";
25
+ std::string_view Prerelease = "8c3fcb33d";
26
26
  } ReactNativeVersion;
27
27
 
28
28
  } // namespace facebook::react
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.0.0-8b8fc6196",
3
+ "version": "0.0.0-8c3fcb33d",
4
4
  "bin": "./cli.js",
5
5
  "description": "React Native for macOS",
6
6
  "license": "MIT",
@@ -79,9 +79,6 @@ def use_react_native! (options={})
79
79
  pod 'boost', :podspec => "#{prefix}/third-party-podspecs/boost.podspec"
80
80
  pod 'RCT-Folly', :podspec => "#{prefix}/third-party-podspecs/RCT-Folly.podspec"
81
81
 
82
- # TODO(macOS GH#214)
83
- pod 'boost-for-react-native', :podspec => "#{prefix}/third-party-podspecs/boost-for-react-native.podspec"
84
-
85
82
  if ENV['USE_CODEGEN_DISCOVERY'] == '1'
86
83
  app_path = options[:app_path]
87
84
  config_file_dir = options[:config_file_dir]
@@ -3,7 +3,7 @@ GEM
3
3
  specs:
4
4
  CFPropertyList (3.0.5)
5
5
  rexml
6
- activesupport (6.1.6.1)
6
+ activesupport (6.1.7)
7
7
  concurrent-ruby (~> 1.0, >= 1.0.2)
8
8
  i18n (>= 1.6, < 2)
9
9
  minitest (>= 5.1)
@@ -97,4 +97,4 @@ RUBY VERSION
97
97
  ruby 3.0.4p208
98
98
 
99
99
  BUNDLED WITH
100
- 2.3.21
100
+ 2.3.22
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "react": "17.0.2",
15
15
  "react-native-macos": "1000.0.0",
16
- "react-native": "0.0.0-8b8fc6196"
16
+ "react-native": "0.0.0-8c3fcb33d"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@babel/core": "^7.12.9",
@@ -1,20 +0,0 @@
1
- # TODO(macOS GH#214)
2
- Pod::Spec.new do |spec|
3
- spec.name = 'boost-for-react-native'
4
- spec.version = '1.63.0'
5
- spec.license = { :type => 'Boost Software License', :file => "LICENSE_1_0.txt" }
6
- spec.homepage = 'http://www.boost.org'
7
- spec.summary = 'Boost provides free peer-reviewed portable C++ source libraries.'
8
- spec.authors = 'Rene Rivera'
9
- spec.source = { :git => 'https://github.com/react-native-community/boost-for-react-native.git',
10
- :tag => 'v1.63.0-0' }
11
-
12
- # Pinning to the same version as React.podspec.
13
- # TODO: Move this osx addition back upstream to https://github.com/react-native-community/boost-for-react-native
14
- spec.platforms = { :ios => '8.0', :osx => "10.15" }
15
- spec.requires_arc = false
16
-
17
- spec.module_name = 'boost'
18
- spec.header_dir = 'boost'
19
- spec.preserve_path = 'boost'
20
- end