react-native-macos 0.0.0-8c5d0eced → 0.0.0-8f5b6f691

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 (58) hide show
  1. package/Libraries/Components/ScrollView/ScrollView.js +11 -45
  2. package/Libraries/Components/TextInput/TextInput.js +69 -1
  3. package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
  4. package/Libraries/Components/View/ReactNativeViewViewConfig.js +1 -0
  5. package/Libraries/Components/View/ReactNativeViewViewConfigMacOS.js +3 -3
  6. package/Libraries/Components/View/ViewPropTypes.js +10 -6
  7. package/Libraries/Core/ReactNativeVersion.js +1 -1
  8. package/Libraries/LinkingIOS/RCTLinkingManager.h +1 -0
  9. package/Libraries/LinkingIOS/macos/RCTLinkingManager.mm +12 -5
  10. package/Libraries/Lists/FlatList.js +25 -1
  11. package/Libraries/Lists/VirtualizedList.js +106 -113
  12. package/Libraries/Lists/VirtualizedSectionList.js +9 -5
  13. package/Libraries/StyleSheet/StyleSheetTypes.js +25 -0
  14. package/Libraries/Text/RCTTextAttributes.m +5 -5
  15. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +3 -1
  16. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +68 -2
  17. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +12 -1
  18. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +12 -3
  19. package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +1 -0
  20. package/Libraries/Text/TextInput/RCTBaseTextInputView.h +6 -0
  21. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +77 -2
  22. package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +7 -0
  23. package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +24 -0
  24. package/Libraries/Types/CoreEventTypes.js +0 -1
  25. package/React/Base/RCTConvert.m +3 -0
  26. package/React/Base/RCTRootView.m +0 -9
  27. package/React/Base/RCTUtils.m +27 -0
  28. package/React/Base/RCTVersion.m +1 -1
  29. package/React/Base/macOS/RCTUIKit.m +7 -0
  30. package/React/CoreModules/RCTAppearance.mm +21 -5
  31. package/React/CoreModules/RCTPerfMonitor.mm +1 -1
  32. package/React/Modules/RCTUIManager.m +2 -1
  33. package/React/Views/RCTActivityIndicatorView.m +2 -1
  34. package/React/Views/RCTCursor.h +39 -0
  35. package/React/Views/RCTCursor.m +105 -0
  36. package/React/Views/RCTView.h +16 -0
  37. package/React/Views/RCTView.m +135 -190
  38. package/React/Views/RCTViewKeyboardEvent.h +6 -28
  39. package/React/Views/RCTViewKeyboardEvent.m +66 -61
  40. package/React/Views/RCTViewManager.m +17 -12
  41. package/React/Views/ScrollView/RCTScrollContentView.h +4 -0
  42. package/React/Views/ScrollView/RCTScrollContentView.m +18 -0
  43. package/React/Views/ScrollView/RCTScrollContentViewManager.m +2 -0
  44. package/React/Views/ScrollView/RCTScrollView.h +2 -1
  45. package/React/Views/ScrollView/RCTScrollView.m +69 -62
  46. package/React/Views/ScrollView/RCTScrollViewManager.m +1 -1
  47. package/React/Views/UIView+React.h +2 -0
  48. package/React/Views/UIView+React.m +22 -13
  49. package/ReactAndroid/gradle.properties +1 -1
  50. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  51. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  52. package/package.json +1 -1
  53. package/scripts/generate-artifacts.js +21 -17
  54. package/scripts/react_native_pods.rb +0 -3
  55. package/template/Gemfile.lock +5 -5
  56. package/template/android/gradlew.bat +89 -89
  57. package/template/package.json +1 -1
  58. package/third-party-podspecs/boost-for-react-native.podspec +0 -20
@@ -12,7 +12,7 @@ const Platform = require('../Utilities/Platform'); // TODO(macOS GH#774)
12
12
  import invariant from 'invariant';
13
13
  import type {ViewToken} from './ViewabilityHelper';
14
14
  import type {SelectedRowIndexPathType} from './VirtualizedList'; // TODO(macOS GH#774)
15
- import type {ScrollEvent} from '../Types/CoreEventTypes'; // TODO(macOS GH#774)
15
+ import type {KeyEvent} from '../Types/CoreEventTypes'; // TODO(macOS GH#774)
16
16
  import {keyExtractor as defaultKeyExtractor} from './VirtualizeUtils';
17
17
  import {View, VirtualizedList} from 'react-native';
18
18
  import * as React from 'react';
@@ -311,8 +311,12 @@ class VirtualizedSectionList<
311
311
  }
312
312
  };
313
313
 
314
- _handleKeyDown = (e: ScrollEvent) => {
314
+ _handleKeyDown = (e: KeyEvent) => {
315
315
  if (Platform.OS === 'macos') {
316
+ if (e.defaultPrevented) {
317
+ return;
318
+ }
319
+
316
320
  const event = e.nativeEvent;
317
321
  const key = event.key;
318
322
  let prevIndexPath = this.state.selectedRowIndexPath;
@@ -320,7 +324,7 @@ class VirtualizedSectionList<
320
324
  const sectionIndex = this.state.selectedRowIndexPath.sectionIndex;
321
325
  const rowIndex = this.state.selectedRowIndexPath.rowIndex;
322
326
 
323
- if (key === 'DOWN_ARROW') {
327
+ if (key === 'ArrowDown') {
324
328
  nextIndexPath = this._selectRowBelowIndexPath(prevIndexPath);
325
329
  this._ensureItemAtIndexPathIsVisible(nextIndexPath);
326
330
 
@@ -332,7 +336,7 @@ class VirtualizedSectionList<
332
336
  item: item,
333
337
  });
334
338
  }
335
- } else if (key === 'UP_ARROW') {
339
+ } else if (key === 'ArrowUp') {
336
340
  nextIndexPath = this._selectRowAboveIndexPath(prevIndexPath);
337
341
  this._ensureItemAtIndexPathIsVisible(nextIndexPath);
338
342
 
@@ -344,7 +348,7 @@ class VirtualizedSectionList<
344
348
  item: item,
345
349
  });
346
350
  }
347
- } else if (key === 'ENTER') {
351
+ } else if (key === 'Enter') {
348
352
  if (this.props.onSelectionEntered) {
349
353
  const item = this.props.sections[sectionIndex].data[rowIndex];
350
354
  this.props.onSelectionEntered(item);
@@ -16,6 +16,29 @@ import type {NativeColorValue} from './PlatformColorValueTypes';
16
16
 
17
17
  export type ____ColorValue_Internal = null | string | NativeColorValue;
18
18
 
19
+ export type CursorValue = ?(
20
+ | 'alias'
21
+ | 'auto'
22
+ | 'col-resize'
23
+ | 'context-menu'
24
+ | 'copy'
25
+ | 'crosshair'
26
+ | 'default'
27
+ | 'disappearing-item'
28
+ | 'e-resize'
29
+ | 'grab'
30
+ | 'grabbing'
31
+ | 'n-resize'
32
+ | 'no-drop'
33
+ | 'not-allowed'
34
+ | 'pointer'
35
+ | 'row-resize'
36
+ | 's-resize'
37
+ | 'text'
38
+ | 'vertical-text'
39
+ | 'w-resize'
40
+ );
41
+
19
42
  export type ColorArrayValue = null | $ReadOnlyArray<____ColorValue_Internal>;
20
43
  export type PointValue = {|
21
44
  x: number,
@@ -584,6 +607,7 @@ export type ____ViewStyle_Internal = $ReadOnly<{|
584
607
  borderTopWidth?: number | AnimatedNode,
585
608
  opacity?: number | AnimatedNode,
586
609
  elevation?: number,
610
+ cursor?: CursorValue,
587
611
  |}>;
588
612
 
589
613
  export type ____FontWeight_Internal =
@@ -638,6 +662,7 @@ export type ____TextStyle_Internal = $ReadOnly<{|
638
662
  textDecorationColor?: ____ColorValue_Internal,
639
663
  textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase',
640
664
  writingDirection?: 'auto' | 'ltr' | 'rtl',
665
+ cursor?: CursorValue,
641
666
  |}>;
642
667
 
643
668
  export type ____ImageStyle_Internal = $ReadOnly<{|
@@ -109,27 +109,27 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib
109
109
  alignment = NSTextAlignmentRight;
110
110
  }
111
111
  }
112
-
112
+
113
113
  paragraphStyle.alignment = alignment;
114
114
  isParagraphStyleUsed = YES;
115
115
  }
116
-
116
+
117
117
  if (_baseWritingDirection != NSWritingDirectionNatural) {
118
118
  paragraphStyle.baseWritingDirection = _baseWritingDirection;
119
119
  isParagraphStyleUsed = YES;
120
120
  }
121
-
121
+
122
122
  if (!isnan(_lineHeight)) {
123
123
  CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier;
124
124
  paragraphStyle.minimumLineHeight = lineHeight;
125
125
  paragraphStyle.maximumLineHeight = lineHeight;
126
126
  isParagraphStyleUsed = YES;
127
127
  }
128
-
128
+
129
129
  if (isParagraphStyleUsed) {
130
130
  return [paragraphStyle copy];
131
131
  }
132
-
132
+
133
133
  return nil;
134
134
  }
135
135
 
@@ -106,7 +106,9 @@
106
106
  - (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // TODO(macOS ISS#3536887)
107
107
  {
108
108
  RCTDirectEventBlock onScroll = self.onScroll;
109
-
109
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
110
+ [_scrollView setHasVerticalScroller:YES];
111
+ #endif // ]TODO(macOS GH#774)
110
112
  if (onScroll) {
111
113
  CGPoint contentOffset = scrollView.contentOffset;
112
114
  CGSize contentSize = scrollView.contentSize;
@@ -125,6 +125,24 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
125
125
  }
126
126
 
127
127
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
128
+ - (void)toggleAutomaticSpellingCorrection:(id)sender
129
+ {
130
+ self.automaticSpellingCorrectionEnabled = !self.isAutomaticSpellingCorrectionEnabled;
131
+ [_textInputDelegate automaticSpellingCorrectionDidChange:self.isAutomaticSpellingCorrectionEnabled];
132
+ }
133
+
134
+ - (void)toggleContinuousSpellChecking:(id)sender
135
+ {
136
+ self.continuousSpellCheckingEnabled = !self.isContinuousSpellCheckingEnabled;
137
+ [_textInputDelegate continuousSpellCheckingDidChange:self.isContinuousSpellCheckingEnabled];
138
+ }
139
+
140
+ - (void)toggleGrammarChecking:(id)sender
141
+ {
142
+ self.grammarCheckingEnabled = !self.isGrammarCheckingEnabled;
143
+ [_textInputDelegate grammarCheckingDidChange:self.isGrammarCheckingEnabled];
144
+ }
145
+
128
146
  - (void)setSelectionColor:(RCTUIColor *)selectionColor
129
147
  {
130
148
  NSMutableDictionary *selectTextAttributes = self.selectedTextAttributes.mutableCopy;
@@ -302,12 +320,47 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
302
320
  {
303
321
  return [super selectedRange];
304
322
  }
323
+
324
+ - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)draggingInfo
325
+ {
326
+ NSDragOperation dragOperation = [self.textInputDelegate textInputDraggingEntered:draggingInfo];
327
+ NSDragOperation superOperation = [super draggingEntered:draggingInfo];
328
+ // The delegate's operation should take precedence.
329
+ return dragOperation != NSDragOperationNone ? dragOperation : superOperation;
330
+ }
331
+
332
+ - (void)draggingExited:(id<NSDraggingInfo>)draggingInfo
333
+ {
334
+ [self.textInputDelegate textInputDraggingExited:draggingInfo];
335
+ [super draggingExited:draggingInfo];
336
+ }
337
+
338
+ - (BOOL)performDragOperation:(id<NSDraggingInfo>)draggingInfo
339
+ {
340
+ if ([self.textInputDelegate textInputShouldHandleDragOperation:draggingInfo]) {
341
+ return [super performDragOperation:draggingInfo];
342
+ }
343
+ return YES;
344
+ }
345
+ - (NSArray *)readablePasteboardTypes
346
+ {
347
+ NSArray *types = [super readablePasteboardTypes];
348
+ // TODO: Optionally support files/images with a prop
349
+ return [types arrayByAddingObjectsFromArray:@[NSFilenamesPboardType, NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
350
+ }
351
+
305
352
  #endif // ]TODO(macOS GH#774)
306
353
 
307
354
  - (void)paste:(id)sender
308
355
  {
309
- [super paste:sender];
310
- _textWasPasted = YES;
356
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
357
+ if ([self.textInputDelegate textInputShouldHandlePaste:self]) {
358
+ #endif
359
+ [super paste:sender];
360
+ _textWasPasted = YES;
361
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
362
+ }
363
+ #endif
311
364
  }
312
365
 
313
366
  // Turn off scroll animation to fix flaky scrolling.
@@ -496,6 +549,19 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
496
549
  [super deleteBackward];
497
550
  }
498
551
  }
552
+ #else
553
+ - (void)keyDown:(NSEvent *)event {
554
+ // If hasMarkedText is true then an IME is open, so don't send event to JS.
555
+ if (self.hasMarkedText || [self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
556
+ [super keyDown:event];
557
+ }
558
+ }
559
+
560
+ - (void)keyUp:(NSEvent *)event {
561
+ if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
562
+ [super keyUp:event];
563
+ }
564
+ }
499
565
  #endif // ]TODO(OSS Candidate ISS#2710739)
500
566
 
501
567
  - (void)_updatePlaceholder
@@ -22,6 +22,12 @@ NS_ASSUME_NONNULL_BEGIN
22
22
  - (BOOL)textInputShouldReturn; // May be called right before `textInputShouldEndEditing` if "Return" button was pressed.
23
23
  - (void)textInputDidReturn;
24
24
 
25
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
26
+ - (void)automaticSpellingCorrectionDidChange:(BOOL)enabled;
27
+ - (void)continuousSpellCheckingDidChange:(BOOL)enabled;
28
+ - (void)grammarCheckingDidChange:(BOOL)enabled;
29
+ #endif // ]TODO(macOS GH#774)
30
+
25
31
  /*
26
32
  * Called before any change in the TextInput. The delegate has the opportunity to change the replacement string or reject the change completely.
27
33
  * To change the replacement, return the changed version of the `text`.
@@ -36,8 +42,13 @@ NS_ASSUME_NONNULL_BEGIN
36
42
  - (BOOL)textInputShouldHandleDeleteBackward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteBackward event handled normally. Return `NO` to disallow it and handle it yourself. TODO(OSS Candidate ISS#2710739)
37
43
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
38
44
  - (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
39
-
45
+ - (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event; // Return `YES` to have the key event handled normally. Return `NO` to disallow it and handle it yourself.
46
+ - (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key;
47
+ - (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo;
48
+ - (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
49
+ - (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;
40
50
  - (void)textInputDidCancel; // Handle `Escape` key press.
51
+ - (BOOL)textInputShouldHandlePaste:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the paste event handled normally. Return `NO` to disallow it and handle it yourself.
41
52
  #endif // ]TODO(macOS GH#774)
42
53
 
43
54
  @optional
@@ -213,11 +213,18 @@ 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];
220
- [[_backedTextInputView window] makeFirstResponder:nil];
225
+ if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
226
+ [[_backedTextInputView window] makeFirstResponder:nil];
227
+ }
221
228
  commandHandled = YES;
222
229
  }
223
230
 
@@ -421,7 +428,9 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
421
428
  //escape
422
429
  } else if (commandSelector == @selector(cancelOperation:)) {
423
430
  [textInputDelegate textInputDidCancel];
424
- [_backedTextInputView.window makeFirstResponder:nil];
431
+ if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
432
+ [[_backedTextInputView window] makeFirstResponder:nil];
433
+ }
425
434
  commandHandled = YES;
426
435
 
427
436
  }
@@ -76,6 +76,7 @@ NS_ASSUME_NONNULL_BEGIN
76
76
  #endif // ]TODO(macOS GH#774)
77
77
 
78
78
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
79
+ - (BOOL)hasMarkedText;
79
80
  // UITextInput method for OSX
80
81
  - (CGSize)sizeThatFits:(CGSize)size;
81
82
  #endif // ]TODO(macOS GH#774)
@@ -39,9 +39,15 @@ 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
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
47
+ @property (nonatomic, copy, nullable) RCTBubblingEventBlock onAutoCorrectChange;
48
+ @property (nonatomic, copy, nullable) RCTBubblingEventBlock onSpellCheckChange;
49
+ @property (nonatomic, copy, nullable) RCTBubblingEventBlock onGrammarCheckChange;
50
+ #endif // TODO(macOS GH#774)
45
51
 
46
52
  @property (nonatomic, assign) NSInteger mostRecentEventCount;
47
53
  @property (nonatomic, assign, readonly) NSInteger nativeEventCount;
@@ -32,7 +32,7 @@
32
32
  {
33
33
  RCTAssertParam(bridge);
34
34
 
35
- if (self = [super initWithFrame:CGRectZero]) {
35
+ if (self = [super initWithEventDispatcher:bridge.eventDispatcher]) { // TODO(OSS Candidate GH#774)
36
36
  _bridge = bridge;
37
37
  _eventDispatcher = bridge.eventDispatcher;
38
38
  }
@@ -42,7 +42,6 @@
42
42
 
43
43
  RCT_NOT_IMPLEMENTED(- (instancetype)init)
44
44
  RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
45
- RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
46
45
 
47
46
  - (RCTUIView<RCTBackedTextInputViewProtocol> *)backedTextInputView // TODO(macOS ISS#3536887)
48
47
  {
@@ -153,6 +152,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
153
152
  range:NSMakeRange(0, attributedTextCopy.length)];
154
153
 
155
154
  textNeedsUpdate = ([self textOf:attributedTextCopy equals:backedTextInputViewTextCopy] == NO);
155
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
156
+ // If we are in a language that uses conversion (e.g. Japanese), ignore updates if we have unconverted text.
157
+ if ([self.backedTextInputView hasMarkedText]) {
158
+ textNeedsUpdate = NO;
159
+ }
160
+ #endif // ]TODO(macOS GH#774)
156
161
 
157
162
  if (eventLag == 0 && textNeedsUpdate) {
158
163
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
@@ -402,6 +407,29 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
402
407
  eventCount:_nativeEventCount];
403
408
  }
404
409
 
410
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
411
+ - (void)automaticSpellingCorrectionDidChange:(BOOL)enabled
412
+ {
413
+ if (_onAutoCorrectChange) {
414
+ _onAutoCorrectChange(@{@"enabled": [NSNumber numberWithBool:enabled]});
415
+ }
416
+ }
417
+
418
+ - (void)continuousSpellCheckingDidChange:(BOOL)enabled
419
+ {
420
+ if (_onSpellCheckChange) {
421
+ _onSpellCheckChange(@{@"enabled": [NSNumber numberWithBool:enabled]});
422
+ }
423
+ }
424
+
425
+ - (void)grammarCheckingDidChange:(BOOL)enabled
426
+ {
427
+ if (_onGrammarCheckChange) {
428
+ _onGrammarCheckChange(@{@"enabled": [NSNumber numberWithBool:enabled]});
429
+ }
430
+ }
431
+ #endif // ]TODO(macOS GH#774)
432
+
405
433
  - (BOOL)textInputShouldReturn
406
434
  {
407
435
  // We send `submit` event here, in `textInputShouldReturn`
@@ -566,6 +594,35 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
566
594
  return YES;
567
595
  }
568
596
 
597
+ - (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key {
598
+ return [self.validKeysDown containsObject:key] || [self.validKeysUp containsObject:key];
599
+ }
600
+
601
+ - (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo
602
+ {
603
+ if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
604
+ return [self draggingEntered:draggingInfo];
605
+ }
606
+ return NSDragOperationNone;
607
+ }
608
+
609
+ - (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo
610
+ {
611
+ if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
612
+ [self draggingExited:draggingInfo];
613
+ }
614
+ }
615
+
616
+ - (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo
617
+ {
618
+ if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
619
+ [self performDragOperation:draggingInfo];
620
+ return NO;
621
+ }
622
+
623
+ return YES;
624
+ }
625
+
569
626
  - (void)textInputDidCancel {
570
627
  [_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
571
628
  reactTag:self.reactTag
@@ -574,6 +631,24 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
574
631
  eventCount:_nativeEventCount];
575
632
  [self textInputDidEndEditing];
576
633
  }
634
+
635
+ - (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event {
636
+ return ![self handleKeyboardEvent:event];
637
+ }
638
+
639
+ - (BOOL)textInputShouldHandlePaste:(__unused id)sender
640
+ {
641
+ NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
642
+ NSPasteboardType fileType = [pasteboard availableTypeFromArray:@[NSFilenamesPboardType, NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
643
+
644
+ // If there's a fileType that is of interest, notify JS. Also blocks notifying JS if it's a text paste
645
+ if (_onPaste && fileType != nil) {
646
+ _onPaste([self dataTransferInfoFromPasteboard:pasteboard]);
647
+ }
648
+
649
+ // Only allow pasting text.
650
+ return fileType == nil;
651
+ }
577
652
  #endif // ]TODO(macOS GH#774)
578
653
 
579
654
  - (void)updateLocalData
@@ -67,10 +67,17 @@ RCT_EXPORT_VIEW_PROPERTY(inputAccessoryViewID, NSString)
67
67
  RCT_EXPORT_VIEW_PROPERTY(textContentType, NSString)
68
68
  RCT_EXPORT_VIEW_PROPERTY(passwordRules, NSString)
69
69
 
70
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
71
+ RCT_EXPORT_VIEW_PROPERTY(onAutoCorrectChange, RCTBubblingEventBlock);
72
+ RCT_EXPORT_VIEW_PROPERTY(onSpellCheckChange, RCTBubblingEventBlock);
73
+ RCT_EXPORT_VIEW_PROPERTY(onGrammarCheckChange, RCTBubblingEventBlock);
74
+ #endif // TODO(macOS GH#774)
75
+
70
76
  RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
71
77
  RCT_EXPORT_VIEW_PROPERTY(onKeyPressSync, RCTDirectEventBlock)
72
78
  RCT_EXPORT_VIEW_PROPERTY(onChangeSync, RCTDirectEventBlock)
73
79
  RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
80
+ RCT_EXPORT_VIEW_PROPERTY(onPaste, RCTDirectEventBlock)
74
81
  RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
75
82
  RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
76
83
 
@@ -127,6 +127,13 @@
127
127
  #endif // ]TODO(macOS GH#774)
128
128
  }
129
129
 
130
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
131
+ - (BOOL)hasMarkedText
132
+ {
133
+ return ((NSTextView *)self.currentEditor).hasMarkedText;
134
+ }
135
+ #endif // ]TODO(macOS GH#774)
136
+
130
137
  #pragma mark - Accessibility
131
138
 
132
139
  #if !TARGET_OS_OSX // [TODO(macOS GH#774)
@@ -482,6 +489,17 @@
482
489
  }
483
490
  return isFirstResponder;
484
491
  }
492
+
493
+ - (BOOL)performKeyEquivalent:(NSEvent *)event
494
+ {
495
+ // The currentEditor is NSText for historical reasons, but documented to be NSTextView.
496
+ NSTextView *currentEditor = (NSTextView *)self.currentEditor;
497
+ // The currentEditor is non-nil when focused and hasMarkedText means an IME is open.
498
+ if (currentEditor && !currentEditor.hasMarkedText && ![self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
499
+ return YES; // Don't send currentEditor the keydown event.
500
+ }
501
+ return [super performKeyEquivalent:event];
502
+ }
485
503
  #endif // ]TODO(macOS GH#774)
486
504
 
487
505
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
@@ -563,6 +581,12 @@
563
581
  [super deleteBackward];
564
582
  }
565
583
  }
584
+ #else
585
+ - (void)keyUp:(NSEvent *)event {
586
+ if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
587
+ [super keyUp:event];
588
+ }
589
+ }
566
590
  #endif // ]TODO(OSS Candidate ISS#2710739)
567
591
 
568
592
  @end
@@ -133,7 +133,6 @@ export type ScrollEvent = SyntheticEvent<
133
133
  |}>,
134
134
  zoomScale?: number,
135
135
  responderIgnoreScroll?: boolean,
136
- key?: string, // TODO(macOS GH#774)
137
136
  preferredScrollerStyle?: string, // TODO(macOS GH#774)
138
137
  |}>,
139
138
  >;
@@ -1234,6 +1234,8 @@ RCT_JSON_ARRAY_CONVERTER(NSNumber)
1234
1234
 
1235
1235
  if ([type isEqualToString:@"fileUrl"]) {
1236
1236
  return @[NSFilenamesPboardType];
1237
+ } else if ([type isEqualToString:@"image"]) {
1238
+ return @[NSPasteboardTypePNG, NSPasteboardTypeTIFF];
1237
1239
  }
1238
1240
 
1239
1241
  return @[];
@@ -1461,6 +1463,7 @@ RCT_ENUM_CONVERTER(
1461
1463
  @"list": NSAccessibilityListRole,
1462
1464
  @"popupbutton": NSAccessibilityPopUpButtonRole,
1463
1465
  @"menubutton": NSAccessibilityMenuButtonRole,
1466
+ @"table": NSAccessibilityTableRole,
1464
1467
  };
1465
1468
  });
1466
1469
 
@@ -431,15 +431,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
431
431
  RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey : self.traitCollection,
432
432
  }];
433
433
  }
434
- #else // [TODO(macOS GH#774)
435
- - (void)viewDidChangeEffectiveAppearance {
436
- [[NSNotificationCenter defaultCenter] postNotificationName:RCTUserInterfaceStyleDidChangeNotification
437
- object:self
438
- userInfo:@{
439
- RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey: self.effectiveAppearance,
440
- }];
441
-
442
- }
443
434
  #endif // ]TODO(macOS GH#774)
444
435
 
445
436
 
@@ -21,6 +21,8 @@
21
21
  #import "RCTAssert.h"
22
22
  #import "RCTLog.h"
23
23
 
24
+ static const NSUInteger RCTMaxCachableImageCount = 100;
25
+
24
26
  NSString *const RCTErrorUnspecified = @"EUNSPECIFIED";
25
27
 
26
28
  // Returns the Path of Home directory
@@ -829,11 +831,29 @@ UIImage *__nullable RCTImageFromLocalBundleAssetURL(NSURL *imageURL)
829
831
  return RCTImageFromLocalAssetURL(bundleImageUrl);
830
832
  }
831
833
 
834
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
835
+ static NSCache<NSURL *, UIImage *> *RCTLocalImageCache()
836
+ {
837
+ static NSCache *imageCache;
838
+ static dispatch_once_t onceToken;
839
+ dispatch_once(&onceToken, ^{
840
+ imageCache = [NSCache new];
841
+ imageCache.countLimit = RCTMaxCachableImageCount;
842
+ });
843
+ return imageCache;
844
+ }
845
+ #endif // ]TODO(macOS GH#774)
846
+
832
847
  UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL)
833
848
  {
834
849
  NSString *imageName = RCTBundlePathForURL(imageURL);
835
850
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
836
851
  NSURL *bundleImageURL = nil;
852
+
853
+ UIImage *cachedImage = [RCTLocalImageCache() objectForKey:imageURL];
854
+ if (cachedImage) {
855
+ return cachedImage;
856
+ }
837
857
  #endif // ]TODO(macOS GH#774)
838
858
 
839
859
  NSBundle *bundle = nil;
@@ -911,6 +931,13 @@ UIImage *__nullable RCTImageFromLocalAssetURL(NSURL *imageURL)
911
931
  }
912
932
  }
913
933
  }
934
+
935
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
936
+ if (image) {
937
+ [RCTLocalImageCache() setObject:image forKey:imageURL];
938
+ }
939
+ #endif // ]TODO(macOS GH#774)
940
+
914
941
  return image;
915
942
  }
916
943
 
@@ -28,7 +28,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
28
28
  RCTVersionMajor: @(0),
29
29
  RCTVersionMinor: @(0),
30
30
  RCTVersionPatch: @(0),
31
- RCTVersionPrerelease: @"8c5d0eced",
31
+ RCTVersionPrerelease: @"8f5b6f691",
32
32
  };
33
33
  });
34
34
  return __rnVersion;
@@ -423,6 +423,13 @@ static RCTUIView *RCTUIViewCommonInit(RCTUIView *self)
423
423
  }
424
424
  }
425
425
 
426
+ // We purposely don't use RCTCursor for the parameter type here because it would introduce an import cycle:
427
+ // RCTUIKit > RCTCursor > RCTConvert > RCTUIKit
428
+ - (void)setCursor:(NSInteger)cursor
429
+ {
430
+ // This method is required to be defined due to [RCTVirtualTextViewManager view] returning a RCTUIView.
431
+ }
432
+
426
433
  @end
427
434
 
428
435
  // RCTUIScrollView