Skip to content

Commit 39c5727

Browse files
committed
stuff
1 parent aee891a commit 39c5727

File tree

18 files changed

+330
-141
lines changed

18 files changed

+330
-141
lines changed

packages/react-native/Libraries/Text/BaseText/RCTBaseTextViewManager.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ - (RCTShadowView *)shadowView
6060

6161
#if TARGET_OS_OSX // [macOS
6262
RCT_REMAP_SHADOW_PROPERTY(cursor, textAttributes.cursor, RCTCursor)
63+
RCT_REMAP_SHADOW_PROPERTY(href, textAttributes.href, NSString)
6364
#endif // macOS]
6465

6566
@end

packages/react-native/Libraries/Text/RCTTextAttributes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern NSString *const RCTTextAttributesTagAttributeName;
6161

6262
#if TARGET_OS_OSX // [macOS
6363
@property (nonatomic, assign) RCTCursor cursor;
64+
@property (nonatomic, copy, nullable) NSString *href;
6465
#endif // macOS]
6566

6667
#pragma mark - Inheritance

packages/react-native/Libraries/Text/RCTTextAttributes.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes
111111
textAttributes->_textTransform != RCTTextTransformUndefined ? textAttributes->_textTransform : _textTransform;
112112
#if TARGET_OS_OSX // [macOS
113113
_cursor = textAttributes->_cursor != RCTCursorAuto ? textAttributes->_cursor : _cursor;
114+
_href = textAttributes->_href ?: _href;
114115
#endif // macOS]
115116
}
116117

@@ -237,6 +238,9 @@ - (NSParagraphStyle *)effectiveParagraphStyle
237238
if (_cursor != RCTCursorAuto) {
238239
attributes[NSCursorAttributeName] = NSCursorFromRCTCursor(_cursor);
239240
}
241+
if (_href) {
242+
attributes[NSLinkAttributeName] = [RCTConvert NSURL:_href];
243+
}
240244
#endif // macOS]
241245

242246
return [attributes copy];

packages/react-native/Libraries/Text/Text/RCTTextViewManager.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ @implementation RCTTextViewManager {
3535

3636
RCT_EXPORT_VIEW_PROPERTY(selectable, BOOL)
3737

38+
RCT_EXPORT_OSX_VIEW_PROPERTY(focusable, BOOL)
39+
3840
- (void)setBridge:(RCTBridge *)bridge
3941
{
4042
[super setBridge:bridge];

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
221221

222222
textNeedsUpdate = ([self textOf:attributedTextCopy equals:backedTextInputViewTextCopy] == NO);
223223

224+
#if TARGET_OS_OSX // [macOS
225+
// If we are in a language that uses conversion (e.g. Japanese), ignore updates if we have unconverted text.
226+
if ([self.backedTextInputView hasMarkedText]) {
227+
textNeedsUpdate = NO;
228+
}
229+
#endif // [macOS
230+
224231
if ((eventLag == 0 || self.backedTextInputView.ghostTextChanging) && textNeedsUpdate) { // [macOS]
225232
#if !TARGET_OS_OSX // [macOS]
226233
UITextRange *selection = self.backedTextInputView.selectedTextRange;
@@ -229,6 +236,8 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
229236
#endif // macOS]
230237
NSAttributedString *oldAttributedText = [self.backedTextInputView.attributedText copy];
231238
NSInteger oldTextLength = oldAttributedText.string.length;
239+
NSInteger oldSelectionStart = selection.location; // [macOS]
240+
NSInteger oldSelectionEnd = selection.location + selection.length; // [macOS]
232241

233242
// Ghost text changes should not be part of the undo stack
234243
if (!self.backedTextInputView.ghostTextChanging) {
@@ -238,6 +247,7 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
238247
[self.backedTextInputView.undoManager registerUndoWithTarget:self handler:^(RCTBaseTextInputView *strongSelf) {
239248
strongSelf.attributedText = oldAttributedTextWithoutGhostText;
240249
[strongSelf textInputDidChange];
250+
[strongSelf setSelectionStart:oldSelectionStart selectionEnd:oldSelectionEnd]; // [macOS]
241251
}];
242252
}
243253

@@ -315,7 +325,7 @@ - (void)setSelection:(RCTTextSelection *)selection
315325
NSInteger length = end - selection.start;
316326
NSRange selectedTextRange = NSMakeRange(start, length);
317327
#endif // macOS]
318-
328+
319329
NSInteger eventLag = _nativeEventCount - _mostRecentEventCount;
320330
if (eventLag == 0 && !RCTTextSelectionEqual(previousSelectedTextRange, selectedTextRange)) { // [macOS]
321331
[backedTextInputView setSelectedTextRange:selectedTextRange notifyDelegate:NO];
@@ -341,7 +351,7 @@ - (void)setSelectionStart:(NSInteger)start selectionEnd:(NSInteger)end
341351
#else // [macOS
342352
NSInteger startPosition = MIN(start, end);
343353
NSInteger endPosition = MAX(start, end);
344-
[self.backedTextInputView setSelectedTextRange:NSMakeRange(startPosition, endPosition - startPosition) notifyDelegate:NO];
354+
[self.backedTextInputView setSelectedTextRange:NSMakeRange(startPosition, endPosition - startPosition) notifyDelegate:YES];
345355
#endif // macOS]
346356
}
347357

@@ -605,7 +615,7 @@ - (void)submitOnKeyDownIfNeeded:(NSEvent *)event
605615
}
606616
}
607617
}
608-
618+
609619
if (shouldSubmit) {
610620
if (_onSubmitEditing) {
611621
_onSubmitEditing(@{});
@@ -706,7 +716,7 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range
706716
[backedTextInputView setSelectedTextRange:NSMakeRange(range.location + allowedLength, 0)
707717
notifyDelegate:YES];
708718
#endif // macOS]
709-
719+
710720
[self textInputDidChange];
711721
}
712722

@@ -761,17 +771,20 @@ - (void)textInputDidChangeSelection
761771
{
762772
self.ghostText = nil; // [macOS]
763773

764-
if (!_onSelectionChange || self.backedTextInputView.ghostTextChanging) { // [macOS]
765-
return;
766-
}
774+
// Run this async to match iOS order of events where we get the onChange first and then onSelectionChange.
775+
dispatch_async(dispatch_get_main_queue(), ^{ // [macOS]
776+
if (!_onSelectionChange || self.backedTextInputView.ghostTextChanging) {
777+
return;
778+
}
767779

768-
RCTTextSelection *selection = self.selection;
780+
RCTTextSelection *selection = self.selection;
769781

770-
_onSelectionChange(@{
771-
@"selection" : @{
772-
@"start" : @(selection.start),
773-
@"end" : @(selection.end),
774-
},
782+
_onSelectionChange(@{
783+
@"selection": @{
784+
@"start": @(selection.start),
785+
@"end": @(selection.end),
786+
},
787+
});
775788
});
776789
}
777790

@@ -834,7 +847,7 @@ - (BOOL)textInputShouldHandlePaste:(__unused id)sender
834847
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
835848
NSPasteboardType fileType = [pasteboard availableTypeFromArray:@[NSFilenamesPboardType, NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
836849
NSArray<NSPasteboardType>* pastedTypes = ((RCTUITextView*) self.backedTextInputView).readablePasteboardTypes;
837-
850+
838851
// If there's a fileType that is of interest, notify JS. Also blocks notifying JS if it's a text paste
839852
if (_onPaste && fileType != nil && [pastedTypes containsObject:fileType]) {
840853
_onPaste([self dataTransferInfoFromPasteboard:pasteboard]);

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputViewManager.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ - (void)setBridge:(RCTBridge *)bridge
161161
if (eventLag != 0) {
162162
return;
163163
}
164+
if (!value) { // [macOS]
165+
[view setSelectionStart:start selectionEnd:end];
166+
return;
167+
}
164168
RCTExecuteOnUIManagerQueue(^{
165169
RCTBaseTextInputShadowView *shadowView =
166170
(RCTBaseTextInputShadowView *)[self.bridge.uiManager shadowViewForReactTag:viewTag];

packages/react-native/Libraries/Text/TextNativeComponent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ const textViewConfig = {
4848
dataDetectorType: true,
4949
android_hyphenationFrequency: true,
5050
lineBreakStrategyIOS: true,
51+
focusable: true, // [macOS]
5152
tooltip: true, // [macOS]
53+
href: true, // [macOS]
5254
},
5355
directEventTypes: {
5456
topTextLayout: {

packages/react-native/React/Base/RCTRootView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ - (BOOL)canBecomeFirstResponder
204204
#endif // macOS]
205205
}
206206

207+
#if TARGET_OS_OSX // [macOS
208+
- (void)viewDidEndLiveResize {
209+
[super viewDidEndLiveResize];
210+
[self setNeedsLayout];
211+
}
212+
#endif // macOS]
213+
207214
- (void)setLoadingView:(RCTUIView *)loadingView // [macOS]
208215
{
209216
_loadingView = loadingView;

0 commit comments

Comments
 (0)