Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ @implementation RCTUITextView {
#endif // [macOS]
NSArray<NSString *> *_acceptDragAndDropTypes;
#if TARGET_OS_OSX // [macOS
BOOL _enableFocusRing;
NSArray<NSPasteboardType> *_readablePasteboardTypes;
#endif // macOS]
}
Expand Down Expand Up @@ -64,6 +65,7 @@ - (instancetype)initWithFrame:(CGRect)frame
// Fix blurry text on non-retina displays.
self.canDrawSubviewsIntoLayer = YES;
self.allowsUndo = YES;
_enableFocusRing = YES;
#endif // macOS]

_textInputDelegateAdapter = [[RCTBackedTextViewDelegateAdapter alloc] initWithTextView:self];
Expand Down Expand Up @@ -258,6 +260,21 @@ - (BOOL)resignFirstResponder

return success;
}

- (NSFocusRingType)focusRingType
{
return _enableFocusRing ? NSFocusRingTypeDefault : NSFocusRingTypeNone;
}

- (void)setEnableFocusRing:(BOOL)enableFocusRing
{
if (_enableFocusRing != enableFocusRing) {
_enableFocusRing = enableFocusRing;
}

[super setFocusRingType:self.focusRingType];
[self setKeyboardFocusRingNeedsDisplayInRect:self.bounds];
}
#endif // macOS]

- (void)setDefaultTextAttributes:(NSDictionary<NSAttributedStringKey, id> *)defaultTextAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ - (instancetype)initWithFrame:(CGRect)frame
_forwardingTextView.textContainer.containerSize = NSMakeSize(FLT_MAX, FLT_MAX);
_forwardingTextView.textContainer.widthTracksTextView = YES;
_forwardingTextView.textInputDelegate = self;
if ([_forwardingTextView respondsToSelector:@selector(setEnableFocusRing:)]) {
[_forwardingTextView setEnableFocusRing:YES];
}

_scrollView.documentView = _forwardingTextView;
_scrollView.contentView.postsBoundsChangedNotifications = YES;
Expand Down Expand Up @@ -197,12 +200,19 @@ - (void)setTextContainerInset:(UIEdgeInsets)textContainerInsets

- (BOOL)enableFocusRing
{
if ([_forwardingTextView respondsToSelector:@selector(enableFocusRing)]) {
return [_forwardingTextView enableFocusRing];
}

return _scrollView.enableFocusRing;
}

- (void)setEnableFocusRing:(BOOL)enableFocusRing
{
_scrollView.enableFocusRing = enableFocusRing;
if ([_forwardingTextView respondsToSelector:@selector(setEnableFocusRing:)]) {
[_forwardingTextView setEnableFocusRing:enableFocusRing];
}
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,10 @@ - (void)focus
[_backedTextInputView becomeFirstResponder];
#else // [macOS
NSWindow *window = [_backedTextInputView window];
[window makeFirstResponder:_backedTextInputView];
NSResponder *responder = [_backedTextInputView respondsToSelector:@selector(responder)]
? _backedTextInputView.responder
: (NSResponder *)_backedTextInputView;
[window makeFirstResponder:responder];
#endif // macOS]

const auto &props = static_cast<const TextInputProps &>(*_props);
Expand Down Expand Up @@ -993,8 +996,13 @@ - (void)blur
if ([_backedTextInputView isKindOfClass:[NSTextField class]] &&
[(NSTextField *)_backedTextInputView currentEditor] != nil) {
[window makeFirstResponder:nil];
} else if ([window firstResponder] == _backedTextInputView.responder) {
[window makeFirstResponder:nil];
} else {
NSResponder *responder = [_backedTextInputView respondsToSelector:@selector(responder)]
? _backedTextInputView.responder
: (NSResponder *)_backedTextInputView;
if ([window firstResponder] == responder) {
[window makeFirstResponder:nil];
}
}
#endif // macOS]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ void RCTCopyBackedTextInput(
toTextInput.clearButtonMode = fromTextInput.clearButtonMode;
#endif // [macOS]
toTextInput.scrollEnabled = fromTextInput.scrollEnabled;
toTextInput.disableKeyboardShortcuts = fromTextInput.disableKeyboardShortcuts;
toTextInput.acceptDragAndDropTypes = fromTextInput.acceptDragAndDropTypes;
#if !TARGET_OS_OSX // [macOS]
toTextInput.secureTextEntry = fromTextInput.secureTextEntry;
toTextInput.keyboardType = fromTextInput.keyboardType;
toTextInput.textContentType = fromTextInput.textContentType;
toTextInput.smartInsertDeleteType = fromTextInput.smartInsertDeleteType;
toTextInput.passwordRules = fromTextInput.passwordRules;
toTextInput.disableKeyboardShortcuts = fromTextInput.disableKeyboardShortcuts;
toTextInput.acceptDragAndDropTypes = fromTextInput.acceptDragAndDropTypes;

[toTextInput setSelectedTextRange:fromTextInput.selectedTextRange notifyDelegate:NO];
#else // [macOS]
toTextInput.enableFocusRing = fromTextInput.enableFocusRing;
toTextInput.pointScaleFactor = fromTextInput.pointScaleFactor;
toTextInput.automaticSpellingCorrectionEnabled = fromTextInput.automaticSpellingCorrectionEnabled;
toTextInput.grammarCheckingEnabled = fromTextInput.grammarCheckingEnabled;
toTextInput.continuousSpellCheckingEnabled = fromTextInput.continuousSpellCheckingEnabled;
[toTextInput setSelectedTextRange:[fromTextInput selectedTextRange] notifyDelegate:NO];
#endif // [macOS]
}

Expand Down
Loading