react-native-macos 0.0.0-081d66e4e → 0.0.0-08d0c3b4f

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 (84) hide show
  1. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  2. package/Libraries/Components/TextInput/TextInput.js +77 -1
  3. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  4. package/Libraries/Core/ReactNativeVersion.js +1 -1
  5. package/Libraries/Image/RCTImageView.mm +14 -10
  6. package/Libraries/Lists/VirtualizedList.js +13 -1
  7. package/Libraries/Text/BaseText/RCTBaseTextViewManager.m +1 -0
  8. package/Libraries/Text/RCTTextAttributes.h +2 -0
  9. package/Libraries/Text/RCTTextAttributes.m +9 -0
  10. package/Libraries/Text/Text/RCTDynamicTypeRamp.h +40 -0
  11. package/Libraries/Text/Text/RCTDynamicTypeRamp.m +77 -0
  12. package/Libraries/Text/Text/RCTTextView.m +118 -47
  13. package/Libraries/Text/Text.js +0 -8
  14. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h +8 -0
  15. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +57 -4
  16. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +13 -0
  17. package/Libraries/Text/TextInput/Multiline/RCTUITextView.h +2 -1
  18. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +36 -4
  19. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +2 -0
  20. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +6 -1
  21. package/Libraries/Text/TextInput/RCTBaseTextInputView.h +4 -1
  22. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +57 -0
  23. package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +6 -1
  24. package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +16 -0
  25. package/Libraries/Text/TextNativeComponent.js +2 -0
  26. package/Libraries/Text/TextProps.js +29 -0
  27. package/React/Base/RCTAssert.h +4 -3
  28. package/React/Base/RCTAssert.m +11 -2
  29. package/React/Base/RCTBridge.m +1 -1
  30. package/React/Base/RCTConstants.h +6 -0
  31. package/React/Base/RCTConstants.m +15 -0
  32. package/React/Base/RCTConvert.m +7 -4
  33. package/React/Base/RCTTouchHandler.m +4 -0
  34. package/React/Base/RCTUIKit.h +8 -13
  35. package/React/Base/RCTUtils.m +6 -3
  36. package/React/Base/RCTVersion.m +1 -1
  37. package/React/Base/macOS/RCTUIKit.m +33 -0
  38. package/React/CoreModules/RCTPerfMonitor.mm +1 -1
  39. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +6 -2
  40. package/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +2 -1
  41. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +1 -1
  42. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +35 -9
  43. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +8 -1
  44. package/React/Fabric/Mounting/RCTComponentViewFactory.mm +2 -2
  45. package/React/Fabric/Mounting/RCTMountingManager.h +1 -1
  46. package/React/Fabric/Mounting/RCTMountingManager.mm +10 -9
  47. package/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h +5 -3
  48. package/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.mm +10 -8
  49. package/React/Fabric/Mounting/RCTMountingTransactionObserving.h +5 -3
  50. package/React/Fabric/RCTConversions.h +9 -1
  51. package/React/Fabric/RCTLocalizationProvider.mm +10 -4
  52. package/React/Fabric/RCTScheduler.h +5 -0
  53. package/React/Fabric/RCTScheduler.mm +10 -0
  54. package/React/Fabric/RCTSurfacePresenter.h +2 -0
  55. package/React/Fabric/RCTSurfacePresenter.mm +12 -11
  56. package/React/Fabric/RCTSurfaceTouchHandler.mm +0 -1
  57. package/React/React-RCTFabric.podspec +1 -1
  58. package/React/Views/RCTView.h +1 -0
  59. package/React/Views/RCTView.m +47 -16
  60. package/React/Views/RCTViewManager.m +1 -1
  61. package/React/Views/ScrollView/RCTScrollView.m +1 -1
  62. package/ReactAndroid/gradle.properties +1 -1
  63. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  64. package/ReactCommon/React-Fabric.podspec +1 -1
  65. package/ReactCommon/React-rncore.podspec +1 -1
  66. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  67. package/ReactCommon/react/renderer/core/EventDispatcher.cpp +21 -0
  68. package/ReactCommon/react/renderer/core/EventDispatcher.h +15 -0
  69. package/ReactCommon/react/renderer/core/EventListener.cpp +39 -0
  70. package/ReactCommon/react/renderer/core/EventListener.h +44 -0
  71. package/ReactCommon/react/renderer/graphics/React-graphics.podspec +1 -1
  72. package/ReactCommon/react/renderer/mounting/TelemetryController.cpp +6 -9
  73. package/ReactCommon/react/renderer/mounting/TelemetryController.h +7 -7
  74. package/ReactCommon/react/renderer/scheduler/Scheduler.cpp +14 -0
  75. package/ReactCommon/react/renderer/scheduler/Scheduler.h +6 -0
  76. package/ReactCommon/react/utils/ManagedObjectWrapper.h +1 -1
  77. package/ReactCommon/react/utils/ManagedObjectWrapper.mm +1 -3
  78. package/package.json +1 -1
  79. package/scripts/react_native_pods.rb +0 -3
  80. package/template/Gemfile.lock +4 -4
  81. package/template/package.json +1 -1
  82. package/ReactCommon/react/renderer/mounting/MountingTransactionMetadata.cpp +0 -12
  83. package/ReactCommon/react/renderer/mounting/MountingTransactionMetadata.h +0 -32
  84. package/third-party-podspecs/boost-for-react-native.podspec +0 -20
@@ -42,12 +42,9 @@ const Text: React.AbstractComponent<
42
42
  onResponderTerminationRequest,
43
43
  onStartShouldSetResponder,
44
44
  pressRetentionOffset,
45
- suppressHighlighting,
46
45
  ...restProps
47
46
  } = props;
48
47
 
49
- const [isHighlighted, setHighlighted] = useState(false);
50
-
51
48
  const isPressable =
52
49
  (onPress != null ||
53
50
  onLongPress != null ||
@@ -64,11 +61,9 @@ const Text: React.AbstractComponent<
64
61
  onLongPress,
65
62
  onPress,
66
63
  onPressIn(event) {
67
- setHighlighted(!suppressHighlighting);
68
64
  onPressIn?.(event);
69
65
  },
70
66
  onPressOut(event) {
71
- setHighlighted(false);
72
67
  onPressOut?.(event);
73
68
  },
74
69
  onResponderTerminationRequest_DEPRECATED:
@@ -86,7 +81,6 @@ const Text: React.AbstractComponent<
86
81
  onPressOut,
87
82
  onResponderTerminationRequest,
88
83
  onStartShouldSetResponder,
89
- suppressHighlighting,
90
84
  ],
91
85
  );
92
86
 
@@ -162,7 +156,6 @@ const Text: React.AbstractComponent<
162
156
  <NativeVirtualText
163
157
  {...restProps}
164
158
  {...eventHandlersForText}
165
- isHighlighted={isHighlighted}
166
159
  isPressable={isPressable}
167
160
  numberOfLines={numberOfLines}
168
161
  selectionColor={selectionColor}
@@ -177,7 +170,6 @@ const Text: React.AbstractComponent<
177
170
  accessible={accessible !== false}
178
171
  allowFontScaling={allowFontScaling !== false}
179
172
  ellipsizeMode={ellipsizeMode ?? 'tail'}
180
- isHighlighted={isHighlighted}
181
173
  numberOfLines={numberOfLines}
182
174
  selectionColor={selectionColor}
183
175
  style={style}
@@ -11,6 +11,14 @@ NS_ASSUME_NONNULL_BEGIN
11
11
 
12
12
  @interface RCTMultilineTextInputView : RCTBaseTextInputView
13
13
 
14
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
15
+
16
+ @property (nonatomic, assign) BOOL scrollEnabled;
17
+
18
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
19
+ @property (nonatomic, assign) BOOL hideVerticalScrollIndicator;
20
+ #endif // ]TODO(macOS GH#774)
21
+
14
22
  @end
15
23
 
16
24
  NS_ASSUME_NONNULL_END
@@ -15,6 +15,7 @@
15
15
  {
16
16
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
17
17
  RCTUIScrollView *_scrollView;
18
+ RCTClipView *_clipView;
18
19
  #endif // ]TODO(macOS GH#774)
19
20
  RCTUITextView *_backedTextInputView;
20
21
  }
@@ -28,6 +29,7 @@
28
29
  _backedTextInputView = [[RCTUITextView alloc] initWithFrame:self.bounds];
29
30
  _backedTextInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
30
31
  #if TARGET_OS_OSX // TODO(macOS GH#774)
32
+ self.hideVerticalScrollIndicator = NO;
31
33
  _scrollView = [[RCTUIScrollView alloc] initWithFrame:self.bounds]; // TODO(macOS ISS#3536887)
32
34
  _scrollView.backgroundColor = [RCTUIColor clearColor];
33
35
  _scrollView.drawsBackground = NO;
@@ -35,6 +37,10 @@
35
37
  _scrollView.hasHorizontalRuler = NO;
36
38
  _scrollView.hasVerticalRuler = NO;
37
39
  _scrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
40
+ [_scrollView setHasVerticalScroller:YES];
41
+
42
+ _clipView = [[RCTClipView alloc] initWithFrame:_scrollView.frame];
43
+ [_scrollView setContentView:_clipView];
38
44
 
39
45
  _backedTextInputView.verticallyResizable = YES;
40
46
  _backedTextInputView.horizontallyResizable = YES;
@@ -92,13 +98,63 @@
92
98
  [self setNeedsLayout];
93
99
  }
94
100
 
95
- - (void)setEnableFocusRing:(BOOL)enableFocusRing {
101
+ - (void)setEnableFocusRing:(BOOL)enableFocusRing
102
+ {
96
103
  [super setEnableFocusRing:enableFocusRing];
97
104
  if ([_scrollView respondsToSelector:@selector(setEnableFocusRing:)]) {
98
105
  [_scrollView setEnableFocusRing:enableFocusRing];
99
106
  }
100
107
  }
101
108
 
109
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes
110
+ {
111
+ [_backedTextInputView setReadablePasteBoardTypes:readablePasteboardTypes];
112
+ }
113
+
114
+ - (void)setScrollEnabled:(BOOL)scrollEnabled
115
+ {
116
+ if (scrollEnabled) {
117
+ _scrollView.scrollEnabled = YES;
118
+ [_clipView setConstrainScrolling:NO];
119
+ } else {
120
+ _scrollView.scrollEnabled = NO;
121
+ [_clipView setConstrainScrolling:YES];
122
+ }
123
+ }
124
+
125
+ - (BOOL)scrollEnabled
126
+ {
127
+ return _scrollView.isScrollEnabled;
128
+ }
129
+
130
+ - (BOOL)shouldShowVerticalScrollbar
131
+ {
132
+ // Hide vertical scrollbar if explicity set to NO
133
+ if (self.hideVerticalScrollIndicator) {
134
+ return NO;
135
+ }
136
+
137
+ // Hide vertical scrollbar if attributed text overflows view
138
+ CGSize textViewSize = [_backedTextInputView intrinsicContentSize];
139
+ NSClipView *clipView = (NSClipView *)_scrollView.contentView;
140
+ if (textViewSize.height > clipView.bounds.size.height) {
141
+ return YES;
142
+ };
143
+
144
+ return NO;
145
+ }
146
+
147
+ - (void)textInputDidChange
148
+ {
149
+ [_scrollView setHasVerticalScroller:[self shouldShowVerticalScrollbar]];
150
+ }
151
+
152
+ - (void)setAttributedText:(NSAttributedString *)attributedText
153
+ {
154
+ [_backedTextInputView setAttributedText:attributedText];
155
+ [_scrollView setHasVerticalScroller:[self shouldShowVerticalScrollbar]];
156
+ }
157
+
102
158
  #endif // ]TODO(macOS GH#774)
103
159
 
104
160
  #pragma mark - UIScrollViewDelegate
@@ -106,9 +162,6 @@
106
162
  - (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // TODO(macOS ISS#3536887)
107
163
  {
108
164
  RCTDirectEventBlock onScroll = self.onScroll;
109
- #if TARGET_OS_OSX // [TODO(macOS GH#774)
110
- [_scrollView setHasVerticalScroller:YES];
111
- #endif // ]TODO(macOS GH#774)
112
165
  if (onScroll) {
113
166
  CGPoint contentOffset = scrollView.contentOffset;
114
167
  CGSize contentSize = scrollView.contentSize;
@@ -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,16 @@ 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_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
28
+ RCT_EXPORT_VIEW_PROPERTY(hideVerticalScrollIndicator, BOOL)
29
+ RCT_CUSTOM_VIEW_PROPERTY(pastedTypes, NSArray<NSPasteboardType>*, RCTUITextView)
30
+ {
31
+ NSArray<NSPasteboardType> *types = json ? [RCTConvert NSPasteboardTypeArray:json] : nil;
32
+ if ([view respondsToSelector:@selector(setReadablePasteBoardTypes:)]) {
33
+ [view setReadablePasteBoardTypes: types];
34
+ }
35
+ }
36
+ #endif // ]TODO(macOS GH#774)
37
+
25
38
  @end
@@ -46,13 +46,14 @@ NS_ASSUME_NONNULL_BEGIN
46
46
  @property (nonatomic, strong, nullable) NSString *inputAccessoryViewID;
47
47
 
48
48
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
49
- @property (nonatomic, assign) BOOL scrollEnabled;
49
+ @property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
50
50
  @property (nonatomic, strong, nullable) RCTUIColor *selectionColor; // TODO(OSS Candidate ISS#2710739)
51
51
  @property (nonatomic, assign) UIEdgeInsets textContainerInsets;
52
52
  @property (nonatomic, copy) NSString *text;
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.
@@ -342,12 +350,23 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
342
350
  }
343
351
  return YES;
344
352
  }
353
+ - (NSArray *)readablePasteboardTypes
354
+ {
355
+ return _readablePasteboardTypes ? _readablePasteboardTypes : [super readablePasteboardTypes];
356
+ }
357
+
345
358
  #endif // ]TODO(macOS GH#774)
346
359
 
347
360
  - (void)paste:(id)sender
348
361
  {
349
- [super paste:sender];
350
- _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
351
370
  }
352
371
 
353
372
  // Turn off scroll animation to fix flaky scrolling.
@@ -405,6 +424,10 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
405
424
  // UI/NSTextField do NOT have textContainerInset properties
406
425
  _textContainerInsets = textContainerInsets;
407
426
  super.textContainerInset = NSMakeSize(MIN(textContainerInsets.left, textContainerInsets.right), MIN(textContainerInsets.top, textContainerInsets.bottom));
427
+
428
+ if (self.shouldDrawInsertionPoint) {
429
+ [self updateInsertionPointStateAndRestartTimer:NO];
430
+ }
408
431
  }
409
432
 
410
433
  #endif // ]TODO(macOS GH#774)
@@ -538,9 +561,18 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
538
561
  }
539
562
  #else
540
563
  - (void)keyDown:(NSEvent *)event {
541
- // If hasMarkedText is true then an IME is open, so don't send event to JS.
542
- 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]) {
543
574
  [super keyDown:event];
575
+ [self.textInputDelegate submitOnKeyDownIfNeeded:event];
544
576
  }
545
577
  }
546
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
  /*
@@ -48,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
48
49
  - (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
49
50
  - (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;
50
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.
51
53
  #endif // ]TODO(macOS GH#774)
52
54
 
53
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
@@ -635,6 +677,21 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
635
677
  - (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event {
636
678
  return ![self handleKeyboardEvent:event];
637
679
  }
680
+
681
+ - (BOOL)textInputShouldHandlePaste:(__unused id)sender
682
+ {
683
+ NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
684
+ NSPasteboardType fileType = [pasteboard availableTypeFromArray:@[NSFilenamesPboardType, 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
+ }
638
695
  #endif // ]TODO(macOS GH#774)
639
696
 
640
697
  - (void)updateLocalData
@@ -53,7 +53,6 @@ RCT_REMAP_NOT_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.spellCheckingTyp
53
53
  RCT_REMAP_OSX_VIEW_PROPERTY(spellCheck, backedTextInputView.continuousSpellCheckingEnabled, BOOL) // TODO(macOS GH#774)
54
54
  RCT_REMAP_NOT_OSX_VIEW_PROPERTY(caretHidden, backedTextInputView.caretHidden, BOOL) // TODO(macOS GH#774)
55
55
  RCT_REMAP_NOT_OSX_VIEW_PROPERTY(clearButtonMode, backedTextInputView.clearButtonMode, UITextFieldViewMode) // TODO(macOS GH#774)
56
- RCT_REMAP_VIEW_PROPERTY(scrollEnabled, backedTextInputView.scrollEnabled, BOOL)
57
56
  RCT_REMAP_NOT_OSX_VIEW_PROPERTY(secureTextEntry, backedTextInputView.secureTextEntry, BOOL) // TODO(macOS GH#774)
58
57
  RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL)
59
58
  RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
@@ -71,12 +70,18 @@ RCT_EXPORT_VIEW_PROPERTY(passwordRules, NSString)
71
70
  RCT_EXPORT_VIEW_PROPERTY(onAutoCorrectChange, RCTBubblingEventBlock);
72
71
  RCT_EXPORT_VIEW_PROPERTY(onSpellCheckChange, RCTBubblingEventBlock);
73
72
  RCT_EXPORT_VIEW_PROPERTY(onGrammarCheckChange, RCTBubblingEventBlock);
73
+
74
+ // Specifically for clearing text on enter key press
75
+ RCT_EXPORT_VIEW_PROPERTY(clearTextOnSubmit, BOOL);
76
+ RCT_EXPORT_VIEW_PROPERTY(onSubmitEditing, RCTBubblingEventBlock);
77
+ RCT_EXPORT_VIEW_PROPERTY(submitKeyEvents, NSArray<NSDictionary *>);
74
78
  #endif // TODO(macOS GH#774)
75
79
 
76
80
  RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
77
81
  RCT_EXPORT_VIEW_PROPERTY(onKeyPressSync, RCTDirectEventBlock)
78
82
  RCT_EXPORT_VIEW_PROPERTY(onChangeSync, RCTDirectEventBlock)
79
83
  RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
84
+ RCT_EXPORT_VIEW_PROPERTY(onPaste, RCTDirectEventBlock)
80
85
  RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
81
86
  RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
82
87
 
@@ -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
 
@@ -33,7 +33,9 @@ export const NativeText: HostComponent<NativeTextProps> =
33
33
  isPressable: true,
34
34
  numberOfLines: true,
35
35
  ellipsizeMode: true,
36
+ focusable: true,
36
37
  allowFontScaling: true,
38
+ dynamicTypeRamp: true,
37
39
  maxFontSizeMultiplier: true,
38
40
  disabled: true,
39
41
  selectable: true,
@@ -186,6 +186,23 @@ export type TextProps = $ReadOnly<{|
186
186
  */
187
187
  adjustsFontSizeToFit?: ?boolean,
188
188
 
189
+ /**
190
+ * The Dynamic Text scale ramp to apply to this element on iOS.
191
+ */
192
+ dynamicTypeRamp?: ?(
193
+ | 'caption2'
194
+ | 'caption1'
195
+ | 'footnote'
196
+ | 'subheadline'
197
+ | 'callout'
198
+ | 'body'
199
+ | 'headline'
200
+ | 'title3'
201
+ | 'title2'
202
+ | 'title1'
203
+ | 'largeTitle'
204
+ ),
205
+
189
206
  /**
190
207
  * Smallest possible scale a font can reach.
191
208
  *
@@ -208,4 +225,16 @@ export type TextProps = $ReadOnly<{|
208
225
  * Specifies the Tooltip for the button view
209
226
  */
210
227
  tooltip?: ?string,
228
+
229
+ /**
230
+ * When `true`, indicates that the text can be focused in key view loop
231
+ * By default, when `selectable={true}` the text view will be focusable unless disabled
232
+ */
233
+ focusable?: ?boolean,
234
+
235
+ /**
236
+ * Specifies whether focus ring should be drawn when the view has the first responder status.
237
+ * Only works when `focusable={true}`
238
+ */
239
+ enableFocusRing?: ?boolean, // TODO(macOS GH#774)
211
240
  |}>;
@@ -183,7 +183,8 @@ __attribute__((used)) RCT_EXTERN void RCTEnableNewArchitectureViolationReporting
183
183
 
184
184
  // When reporting is enabled, trigger an assertion.
185
185
  __attribute__((used)) RCT_EXTERN void RCTEnforceNotAllowedForNewArchitecture(id context, NSString *extra);
186
-
187
- // When reporting is enabled, warn about the violation. Use this to prepare a specific callsite
186
+ // When reporting is enabled, trigger an error but do not crash. Use this to prepare a specific callsite
188
187
  // for stricter enforcement. When ready, switch it to use the variant above.
189
- __attribute__((used)) RCT_EXTERN void RCTWarnNotAllowedForNewArchitecture(id context, NSString *extra);
188
+ __attribute__((used)) RCT_EXTERN void RCTErrorNotAllowedForNewArchitecture(id context, NSString *extra);
189
+ // When reporting is enabled, log an message. When ready, switch it to use the variant above.
190
+ __attribute__((used)) RCT_EXTERN void RCTLogNotAllowedForNewArchitecture(id context, NSString *extra);
@@ -274,11 +274,20 @@ void RCTEnforceNotAllowedForNewArchitecture(id context, NSString *extra)
274
274
  RCTAssert(0, @"%@", getNewArchitectureViolationMessage(context, extra));
275
275
  }
276
276
 
277
- void RCTWarnNotAllowedForNewArchitecture(id context, NSString *extra)
277
+ void RCTErrorNotAllowedForNewArchitecture(id context, NSString *extra)
278
278
  {
279
279
  if (!newArchitectureViolationReporting) {
280
280
  return;
281
281
  }
282
282
 
283
- RCTLogWarn(@"%@", getNewArchitectureViolationMessage(context, extra));
283
+ RCTLogError(@"%@", getNewArchitectureViolationMessage(context, extra));
284
+ }
285
+
286
+ void RCTLogNotAllowedForNewArchitecture(id context, NSString *extra)
287
+ {
288
+ if (!newArchitectureViolationReporting) {
289
+ return;
290
+ }
291
+
292
+ RCTLogInfo(@"%@", getNewArchitectureViolationMessage(context, extra));
284
293
  }
@@ -60,7 +60,7 @@ NSArray<Class> *RCTGetModuleClasses(void)
60
60
  void RCTRegisterModule(Class);
61
61
  void RCTRegisterModule(Class moduleClass)
62
62
  {
63
- RCTWarnNotAllowedForNewArchitecture(
63
+ RCTLogNotAllowedForNewArchitecture(
64
64
  @"RCTRegisterModule()", [NSString stringWithFormat:@"'%@' was registered unexpectedly", moduleClass]);
65
65
 
66
66
  static dispatch_once_t onceToken;
@@ -15,3 +15,9 @@ RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollec
15
15
  */
16
16
  RCT_EXTERN BOOL RCTExperimentGetPreemptiveViewAllocationDisabled(void);
17
17
  RCT_EXTERN void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value);
18
+
19
+ /*
20
+ * W3C Pointer Events
21
+ */
22
+ RCT_EXTERN BOOL RCTGetDispatchW3CPointerEvents(void);
23
+ RCT_EXTERN void RCTSetDispatchW3CPointerEvents(BOOL value);
@@ -24,3 +24,18 @@ void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value)
24
24
  {
25
25
  RCTExperimentPreemptiveViewAllocationDisabled = value;
26
26
  }
27
+
28
+ /*
29
+ * W3C Pointer Events
30
+ */
31
+ static BOOL RCTDispatchW3CPointerEvents = NO;
32
+
33
+ BOOL RCTGetDispatchW3CPointerEvents()
34
+ {
35
+ return RCTDispatchW3CPointerEvents;
36
+ }
37
+
38
+ void RCTSetDispatchW3CPointerEvents(BOOL value)
39
+ {
40
+ RCTDispatchW3CPointerEvents = value;
41
+ }
@@ -1234,8 +1234,11 @@ 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];
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
  }