react-native-macos 0.0.0-fdcec4d55 → 0.0.0-fe1f016b6

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 (129) hide show
  1. package/Libraries/Components/ScrollView/ScrollView.js +11 -45
  2. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  3. package/Libraries/Components/TextInput/TextInput.js +118 -1
  4. package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
  5. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  6. package/Libraries/Components/View/ReactNativeViewViewConfig.js +1 -0
  7. package/Libraries/Components/View/ReactNativeViewViewConfigMacOS.js +3 -3
  8. package/Libraries/Components/View/View.js +0 -7
  9. package/Libraries/Components/View/ViewPropTypes.js +10 -6
  10. package/Libraries/Core/ReactNativeVersion.js +1 -1
  11. package/Libraries/Image/RCTImageCache.m +1 -1
  12. package/Libraries/Image/RCTImageView.mm +14 -10
  13. package/Libraries/LinkingIOS/RCTLinkingManager.h +1 -0
  14. package/Libraries/LinkingIOS/macos/RCTLinkingManager.mm +12 -5
  15. package/Libraries/Lists/FlatList.js +25 -1
  16. package/Libraries/Lists/VirtualizedList.js +118 -113
  17. package/Libraries/Lists/VirtualizedSectionList.js +9 -5
  18. package/Libraries/StyleSheet/StyleSheetTypes.js +25 -0
  19. package/Libraries/Text/BaseText/RCTBaseTextViewManager.m +1 -0
  20. package/Libraries/Text/RCTTextAttributes.h +2 -0
  21. package/Libraries/Text/RCTTextAttributes.m +14 -5
  22. package/Libraries/Text/Text/RCTDynamicTypeRamp.h +40 -0
  23. package/Libraries/Text/Text/RCTDynamicTypeRamp.m +77 -0
  24. package/Libraries/Text/Text/RCTTextView.m +118 -47
  25. package/Libraries/Text/Text.js +0 -8
  26. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h +8 -0
  27. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +57 -2
  28. package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +13 -0
  29. package/Libraries/Text/TextInput/Multiline/RCTUITextView.h +2 -1
  30. package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +88 -3
  31. package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +13 -1
  32. package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +12 -3
  33. package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +1 -0
  34. package/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m +12 -0
  35. package/Libraries/Text/TextInput/RCTBaseTextInputView.h +9 -1
  36. package/Libraries/Text/TextInput/RCTBaseTextInputView.m +120 -2
  37. package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +12 -1
  38. package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +40 -0
  39. package/Libraries/Text/TextNativeComponent.js +2 -0
  40. package/Libraries/Text/TextProps.js +29 -0
  41. package/Libraries/Types/CoreEventTypes.js +0 -1
  42. package/Libraries/Utilities/codegenNativeComponent.js +1 -0
  43. package/React/Base/RCTAssert.h +4 -3
  44. package/React/Base/RCTAssert.m +11 -2
  45. package/React/Base/RCTBridge.m +1 -1
  46. package/React/Base/RCTConstants.h +3 -3
  47. package/React/Base/RCTConstants.m +6 -6
  48. package/React/Base/RCTConvert.m +8 -4
  49. package/React/Base/RCTEventDispatcherProtocol.h +5 -0
  50. package/React/Base/RCTRootView.m +0 -9
  51. package/React/Base/RCTTouchHandler.m +4 -0
  52. package/React/Base/RCTUIKit.h +8 -13
  53. package/React/Base/RCTUtils.m +33 -3
  54. package/React/Base/RCTVersion.m +1 -1
  55. package/React/Base/macOS/RCTUIKit.m +40 -0
  56. package/React/CoreModules/RCTAppearance.mm +21 -5
  57. package/React/CoreModules/RCTEventDispatcher.mm +6 -1
  58. package/React/CoreModules/RCTPerfMonitor.mm +1 -1
  59. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.h +1 -0
  60. package/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +76 -19
  61. package/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +2 -1
  62. package/React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm +0 -1
  63. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +1 -1
  64. package/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +35 -9
  65. package/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +8 -1
  66. package/React/Fabric/Mounting/RCTComponentViewFactory.mm +2 -9
  67. package/React/Fabric/Mounting/RCTComponentViewRegistry.h +0 -5
  68. package/React/Fabric/Mounting/RCTComponentViewRegistry.mm +0 -39
  69. package/React/Fabric/Mounting/RCTMountingManager.h +1 -1
  70. package/React/Fabric/Mounting/RCTMountingManager.mm +10 -9
  71. package/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h +5 -3
  72. package/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.mm +10 -8
  73. package/React/Fabric/Mounting/RCTMountingTransactionObserving.h +5 -3
  74. package/React/Fabric/RCTConversions.h +9 -1
  75. package/React/Fabric/RCTImageResponseObserverProxy.h +1 -0
  76. package/React/Fabric/RCTLocalizationProvider.mm +10 -4
  77. package/React/Fabric/RCTScheduler.h +7 -0
  78. package/React/Fabric/RCTScheduler.mm +15 -0
  79. package/React/Fabric/RCTSurfacePresenter.h +2 -0
  80. package/React/Fabric/RCTSurfacePresenter.mm +44 -23
  81. package/React/Fabric/RCTSurfaceTouchHandler.mm +0 -1
  82. package/React/Modules/RCTUIManager.m +2 -1
  83. package/React/React-RCTFabric.podspec +1 -1
  84. package/React/Tests/Mounting/RCTComponentViewRegistryTests.mm +1 -0
  85. package/React/Views/RCTActivityIndicatorView.m +2 -1
  86. package/React/Views/RCTCursor.h +39 -0
  87. package/React/Views/RCTCursor.m +105 -0
  88. package/React/Views/RCTView.h +16 -0
  89. package/React/Views/RCTView.m +141 -191
  90. package/React/Views/RCTViewKeyboardEvent.h +6 -28
  91. package/React/Views/RCTViewKeyboardEvent.m +66 -61
  92. package/React/Views/RCTViewManager.m +18 -13
  93. package/React/Views/ScrollView/RCTScrollContentView.h +4 -0
  94. package/React/Views/ScrollView/RCTScrollContentView.m +18 -0
  95. package/React/Views/ScrollView/RCTScrollContentViewManager.m +2 -0
  96. package/React/Views/ScrollView/RCTScrollView.h +2 -1
  97. package/React/Views/ScrollView/RCTScrollView.m +70 -63
  98. package/React/Views/ScrollView/RCTScrollViewManager.m +1 -1
  99. package/React/Views/UIView+React.h +2 -0
  100. package/React/Views/UIView+React.m +23 -14
  101. package/ReactAndroid/gradle.properties +1 -1
  102. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  103. package/ReactCommon/React-Fabric.podspec +1 -1
  104. package/ReactCommon/React-rncore.podspec +1 -1
  105. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  106. package/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm +5 -0
  107. package/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm +4 -2
  108. package/ReactCommon/react/renderer/core/EventDispatcher.cpp +21 -0
  109. package/ReactCommon/react/renderer/core/EventDispatcher.h +15 -0
  110. package/ReactCommon/react/renderer/core/EventListener.cpp +39 -0
  111. package/ReactCommon/react/renderer/core/EventListener.h +44 -0
  112. package/ReactCommon/react/renderer/graphics/React-graphics.podspec +1 -1
  113. package/ReactCommon/react/renderer/mounting/TelemetryController.cpp +6 -9
  114. package/ReactCommon/react/renderer/mounting/TelemetryController.h +7 -7
  115. package/ReactCommon/react/renderer/scheduler/Scheduler.cpp +18 -0
  116. package/ReactCommon/react/renderer/scheduler/Scheduler.h +9 -0
  117. package/ReactCommon/react/utils/ManagedObjectWrapper.h +1 -1
  118. package/ReactCommon/react/utils/ManagedObjectWrapper.mm +1 -3
  119. package/package.json +1 -1
  120. package/scripts/generate-artifacts.js +21 -17
  121. package/scripts/react_native_pods.rb +0 -3
  122. package/template/Gemfile.lock +7 -7
  123. package/template/android/gradlew.bat +89 -89
  124. package/template/ios/HelloWorldTests/HelloWorldTests.m +1 -0
  125. package/template/package.json +1 -1
  126. package/Libraries/Types/RootTagTypes.js~merged +0 -23
  127. package/ReactCommon/react/renderer/mounting/MountingTransactionMetadata.cpp +0 -12
  128. package/ReactCommon/react/renderer/mounting/MountingTransactionMetadata.h +0 -32
  129. package/third-party-podspecs/boost-for-react-native.podspec +0 -20
@@ -22,6 +22,27 @@
22
22
 
23
23
  #import <QuartzCore/QuartzCore.h> // TODO(macOS GH#774)
24
24
 
25
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
26
+
27
+ // We are managing the key view loop using the RCTTextView.
28
+ // Disable key view for backed NSTextView so we don't get double focus.
29
+ @interface RCTUnfocusableTextView : NSTextView
30
+ @end
31
+
32
+ @implementation RCTUnfocusableTextView
33
+
34
+ - (BOOL)canBecomeKeyView
35
+ {
36
+ return NO;
37
+ }
38
+
39
+ @end
40
+
41
+ @interface RCTTextView () <NSTextViewDelegate>
42
+ @end
43
+
44
+ #endif // ]TODO(macOS GH#774)
45
+
25
46
  @implementation RCTTextView
26
47
  {
27
48
  CAShapeLayer *_highlightLayer;
@@ -29,6 +50,7 @@
29
50
  UILongPressGestureRecognizer *_longPressGestureRecognizer;
30
51
  #else // [TODO(macOS GH#774)
31
52
  NSString * _accessibilityLabel;
53
+ NSTextView *_textView;
32
54
  #endif // ]TODO(macOS GH#774)
33
55
 
34
56
  RCTEventDispatcher *_eventDispatcher; // TODO(OSS Candidate ISS#2710739)
@@ -57,6 +79,18 @@
57
79
  self.accessibilityRole = NSAccessibilityStaticTextRole;
58
80
  // Fix blurry text on non-retina displays.
59
81
  self.canDrawSubviewsIntoLayer = YES;
82
+ // The NSTextView is responsible for drawing text and managing selection.
83
+ _textView = [[RCTUnfocusableTextView alloc] initWithFrame:self.bounds];
84
+ _textView.delegate = self;
85
+ _textView.usesFontPanel = NO;
86
+ _textView.drawsBackground = NO;
87
+ _textView.linkTextAttributes = @{};
88
+ _textView.editable = NO;
89
+ _textView.selectable = NO;
90
+ _textView.verticallyResizable = NO;
91
+ _textView.layoutManager.usesFontLeading = NO;
92
+ _textStorage = _textView.textStorage;
93
+ [self addSubview:_textView];
60
94
  #endif // ]TODO(macOS GH#774)
61
95
  self.opaque = NO;
62
96
  RCTUIViewSetContentModeRedraw(self); // TODO(macOS GH#774) and TODO(macOS ISS#3536887)
@@ -65,40 +99,7 @@
65
99
  }
66
100
 
67
101
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
68
- - (void)dealloc
69
- {
70
- [self removeAllTextStorageLayoutManagers];
71
- }
72
-
73
- - (void)removeAllTextStorageLayoutManagers
74
- {
75
- // On macOS AppKit can throw an uncaught exception
76
- // (-[NSConcretePointerArray pointerAtIndex:]: attempt to access pointer at index ...)
77
- // during the dealloc of NSLayoutManager. The _textStorage and its
78
- // associated NSLayoutManager dealloc later in an autorelease pool.
79
- // Manually removing the layout managers from _textStorage prior to release
80
- // works around this issue in AppKit.
81
- NSArray<NSLayoutManager *> *managers = [[_textStorage layoutManagers] copy];
82
- for (NSLayoutManager *manager in managers) {
83
- [_textStorage removeLayoutManager:manager];
84
- }
85
- }
86
102
 
87
- - (BOOL)canBecomeKeyView
88
- {
89
- // RCTText should not get any keyboard focus unless its `selectable` prop is true
90
- return _selectable;
91
- }
92
-
93
- - (void)drawFocusRingMask {
94
- if ([self enableFocusRing]) {
95
- NSRectFill([self bounds]);
96
- }
97
- }
98
-
99
- - (NSRect)focusRingMaskBounds {
100
- return [self bounds];
101
- }
102
103
  #endif // ]TODO(macOS GH#774)
103
104
 
104
105
  #if DEBUG // TODO(macOS GH#774) description is a debug-only feature
@@ -119,14 +120,19 @@
119
120
 
120
121
  _selectable = selectable;
121
122
 
122
- #if !TARGET_OS_OSX // TODO(macOS GH#774)
123
+ #if !TARGET_OS_OSX // [TODO(macOS GH#774)
123
124
  if (_selectable) {
124
125
  [self enableContextMenu];
125
126
  }
126
127
  else {
127
128
  [self disableContextMenu];
128
129
  }
129
- #endif // TODO(macOS GH#774)
130
+ #else
131
+ _textView.selectable = _selectable;
132
+ if (_selectable) {
133
+ [self setFocusable:YES];
134
+ }
135
+ #endif // ]TODO(macOS GH#774)
130
136
  }
131
137
 
132
138
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
@@ -149,13 +155,37 @@
149
155
  contentFrame:(CGRect)contentFrame
150
156
  descendantViews:(NSArray<RCTUIView *> *)descendantViews // TODO(macOS ISS#3536887)
151
157
  {
152
- #if TARGET_OS_OSX // [TODO(macOS GH#774)
153
- [self removeAllTextStorageLayoutManagers];
158
+ // This lets the textView own its text storage on macOS
159
+ // We update and replace the text container `_textView.textStorage.attributedString` when text/layout changes
160
+ #if !TARGET_OS_OSX // [TODO(macOS GH#774)
161
+ _textStorage = textStorage;
154
162
  #endif // ]TODO(macOS GH#774)
155
163
 
156
- _textStorage = textStorage;
157
164
  _contentFrame = contentFrame;
158
165
 
166
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
167
+ NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
168
+ NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
169
+
170
+ [_textView replaceTextContainer:textContainer];
171
+
172
+ // On macOS AppKit can throw an uncaught exception
173
+ // (-[NSConcretePointerArray pointerAtIndex:]: attempt to access pointer at index ...)
174
+ // during the dealloc of NSLayoutManager. The textStorage and its
175
+ // associated NSLayoutManager dealloc later in an autorelease pool.
176
+ // Manually removing the layout managers from textStorage prior to release
177
+ // works around this issue in AppKit.
178
+ NSArray<NSLayoutManager *> *managers = [[textStorage layoutManagers] copy];
179
+ for (NSLayoutManager *manager in managers) {
180
+ [textStorage removeLayoutManager:manager];
181
+ }
182
+
183
+ _textView.minSize = contentFrame.size;
184
+ _textView.maxSize = contentFrame.size;
185
+ _textView.frame = contentFrame;
186
+ _textView.textStorage.attributedString = textStorage;
187
+ #endif // ]TODO(macOS GH#774)
188
+
159
189
  // FIXME: Optimize this.
160
190
  for (RCTUIView *view in _descendantViews) { // TODO(macOS ISS#3536887)
161
191
  [view removeFromSuperview];
@@ -173,6 +203,13 @@
173
203
  - (void)drawRect:(CGRect)rect
174
204
  {
175
205
  [super drawRect:rect];
206
+
207
+ // For iOS, UITextView api is not used for legacy performance reasons. A custom draw implementation is used instead.
208
+ // On desktop, we use NSTextView to access api's for arbitrary selection, custom cursors etc...
209
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
210
+ return;
211
+ #endif // ]TODO(macOS GH#774)
212
+
176
213
  if (!_textStorage) {
177
214
  return;
178
215
  }
@@ -408,6 +445,39 @@
408
445
  }
409
446
  }
410
447
  }
448
+ #endif // ]TODO(macOS GH#774)
449
+
450
+ #pragma mark - Selection
451
+
452
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
453
+ - (void)textDidEndEditing:(NSNotification *)notification
454
+ {
455
+ _textView.selectedRange = NSMakeRange(NSNotFound, 0);
456
+ }
457
+ #endif // ]TODO(macOS GH#774)
458
+
459
+ #pragma mark - Responder chain
460
+
461
+ #if !TARGET_OS_OSX // TODO(macOS GH#774)
462
+ - (BOOL)canBecomeFirstResponder
463
+ {
464
+ return _selectable;
465
+ }
466
+ #else
467
+ - (BOOL)canBecomeKeyView
468
+ {
469
+ return self.focusable;
470
+ }
471
+
472
+ - (void)drawFocusRingMask {
473
+ if (self.focusable && self.enableFocusRing) {
474
+ NSRectFill([self bounds]);
475
+ }
476
+ }
477
+
478
+ - (NSRect)focusRingMaskBounds {
479
+ return [self bounds];
480
+ }
411
481
 
412
482
  - (BOOL)becomeFirstResponder
413
483
  {
@@ -423,22 +493,19 @@
423
493
 
424
494
  - (BOOL)resignFirstResponder
425
495
  {
426
- if (![super resignFirstResponder]) {
496
+ // Don't relinquish first responder while selecting text.
497
+ if (_selectable && NSRunLoop.currentRunLoop.currentMode == NSEventTrackingRunLoopMode) {
427
498
  return NO;
428
499
  }
429
-
430
- // If we've lost focus, notify listeners
431
- [_eventDispatcher sendEvent:[RCTFocusChangeEvent blurEventWithReactTag:self.reactTag]];
432
-
433
- return YES;
500
+
501
+ return [super resignFirstResponder];
434
502
  }
435
503
 
436
- #endif // ]TODO(macOS GH#774)
437
-
438
504
  - (BOOL)canBecomeFirstResponder
439
505
  {
440
- return _selectable;
506
+ return self.focusable;
441
507
  }
508
+ #endif
442
509
 
443
510
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
444
511
  - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
@@ -451,6 +518,8 @@
451
518
  }
452
519
  #endif // TODO(macOS GH#774)
453
520
 
521
+ #pragma mark - Copy/Paste
522
+
454
523
  - (void)copy:(id)sender
455
524
  {
456
525
  NSAttributedString *attributedText = _textStorage;
@@ -470,6 +539,8 @@
470
539
  UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
471
540
  pasteboard.items = @[item];
472
541
  #elif TARGET_OS_OSX // TODO(macOS GH#774)
542
+ [_textView copy:sender];
543
+
473
544
  NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
474
545
  [pasteboard clearContents];
475
546
  [pasteboard writeObjects:[NSArray arrayWithObjects:attributedText.string, rtf, nil]];
@@ -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,7 +162,6 @@
106
162
  - (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // TODO(macOS ISS#3536887)
107
163
  {
108
164
  RCTDirectEventBlock onScroll = self.onScroll;
109
-
110
165
  if (onScroll) {
111
166
  CGPoint contentOffset = scrollView.contentOffset;
112
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()
@@ -125,6 +128,24 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
125
128
  }
126
129
 
127
130
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
131
+ - (void)toggleAutomaticSpellingCorrection:(id)sender
132
+ {
133
+ self.automaticSpellingCorrectionEnabled = !self.isAutomaticSpellingCorrectionEnabled;
134
+ [_textInputDelegate automaticSpellingCorrectionDidChange:self.isAutomaticSpellingCorrectionEnabled];
135
+ }
136
+
137
+ - (void)toggleContinuousSpellChecking:(id)sender
138
+ {
139
+ self.continuousSpellCheckingEnabled = !self.isContinuousSpellCheckingEnabled;
140
+ [_textInputDelegate continuousSpellCheckingDidChange:self.isContinuousSpellCheckingEnabled];
141
+ }
142
+
143
+ - (void)toggleGrammarChecking:(id)sender
144
+ {
145
+ self.grammarCheckingEnabled = !self.isGrammarCheckingEnabled;
146
+ [_textInputDelegate grammarCheckingDidChange:self.isGrammarCheckingEnabled];
147
+ }
148
+
128
149
  - (void)setSelectionColor:(RCTUIColor *)selectionColor
129
150
  {
130
151
  NSMutableDictionary *selectTextAttributes = self.selectedTextAttributes.mutableCopy;
@@ -159,6 +180,11 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
159
180
  self.string = text;
160
181
  }
161
182
 
183
+ - (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes
184
+ {
185
+ _readablePasteboardTypes = readablePasteboardTypes;
186
+ }
187
+
162
188
  - (void)setTypingAttributes:(__unused NSDictionary *)typingAttributes
163
189
  {
164
190
  // Prevent NSTextView from changing its own typing attributes out from under us.
@@ -172,7 +198,7 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
172
198
 
173
199
  - (BOOL)becomeFirstResponder
174
200
  {
175
- BOOL success = [[self window] makeFirstResponder:self];
201
+ BOOL success = [super becomeFirstResponder];
176
202
 
177
203
  if (success) {
178
204
  id<RCTBackedTextInputDelegate> textInputDelegate = [self textInputDelegate];
@@ -302,12 +328,45 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
302
328
  {
303
329
  return [super selectedRange];
304
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
+
305
358
  #endif // ]TODO(macOS GH#774)
306
359
 
307
360
  - (void)paste:(id)sender
308
361
  {
309
- [super paste:sender];
310
- _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
311
370
  }
312
371
 
313
372
  // Turn off scroll animation to fix flaky scrolling.
@@ -365,6 +424,10 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
365
424
  // UI/NSTextField do NOT have textContainerInset properties
366
425
  _textContainerInsets = textContainerInsets;
367
426
  super.textContainerInset = NSMakeSize(MIN(textContainerInsets.left, textContainerInsets.right), MIN(textContainerInsets.top, textContainerInsets.bottom));
427
+
428
+ if (self.shouldDrawInsertionPoint) {
429
+ [self updateInsertionPointStateAndRestartTimer:NO];
430
+ }
368
431
  }
369
432
 
370
433
  #endif // ]TODO(macOS GH#774)
@@ -496,6 +559,28 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
496
559
  [super deleteBackward];
497
560
  }
498
561
  }
562
+ #else
563
+ - (void)keyDown:(NSEvent *)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]) {
574
+ [super keyDown:event];
575
+ [self.textInputDelegate submitOnKeyDownIfNeeded:event];
576
+ }
577
+ }
578
+
579
+ - (void)keyUp:(NSEvent *)event {
580
+ if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
581
+ [super keyUp:event];
582
+ }
583
+ }
499
584
  #endif // ]TODO(OSS Candidate ISS#2710739)
500
585
 
501
586
  - (void)_updatePlaceholder
@@ -22,6 +22,13 @@ 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
+ - (void)submitOnKeyDownIfNeeded:(NSEvent *)event;
30
+ #endif // ]TODO(macOS GH#774)
31
+
25
32
  /*
26
33
  * Called before any change in the TextInput. The delegate has the opportunity to change the replacement string or reject the change completely.
27
34
  * To change the replacement, return the changed version of the `text`.
@@ -36,8 +43,13 @@ NS_ASSUME_NONNULL_BEGIN
36
43
  - (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
44
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
38
45
  - (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
39
-
46
+ - (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event; // Return `YES` to have the key event handled normally. Return `NO` to disallow it and handle it yourself.
47
+ - (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key;
48
+ - (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo;
49
+ - (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
50
+ - (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;
40
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.
41
53
  #endif // ]TODO(macOS GH#774)
42
54
 
43
55
  @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)
@@ -225,7 +225,19 @@
225
225
 
226
226
  if (!_textStorage) {
227
227
  _textContainer = [NSTextContainer new];
228
+ #if !TARGET_OS_OSX // TODO(macOS GH#774)
228
229
  _textContainer.lineFragmentPadding = 0.0; // Note, the default value is 5.
230
+ #else
231
+ // macOS has a bug in multiline where setting the real text view's lineFragmentPadding to 0 will
232
+ // cause the scroll view to scroll to top when inserting a newline at the bottom of
233
+ // a NSTextView when it has more rows than can be displayed on screen. The shadow needs to match
234
+ // the NSTextView that it is tracking.
235
+ if (_maximumNumberOfLines != 1) {
236
+ _textContainer.lineFragmentPadding = 1;
237
+ } else {
238
+ _textContainer.lineFragmentPadding = 0.0; // Note, the default value is 5.
239
+ }
240
+ #endif // ]TODO(macOS GH#774)
229
241
  _layoutManager = [NSLayoutManager new];
230
242
  [_layoutManager addTextContainer:_textContainer];
231
243
  _textStorage = [NSTextStorage new];