From 32e83dc11945ce1165a0f2f59fad97fb19551a6a Mon Sep 17 00:00:00 2001 From: chiuam <67026167+chiuam@users.noreply.github.com> Date: Mon, 25 Jul 2022 14:52:07 -0400 Subject: [PATCH] Turn on focus ring for multiline textinput (#1276) (#1285) --- .../TextInput/Multiline/RCTMultilineTextInputView.m | 10 ++++++++++ React/Base/RCTUIKit.h | 2 ++ React/Base/macOS/RCTUIKit.m | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m b/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m index bddcb563ae565a..fd37f9a4fc36ea 100644 --- a/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +++ b/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m @@ -48,6 +48,8 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge #else // [TODO(macOS GH#774) _scrollView.documentView = _backedTextInputView; _scrollView.contentView.postsBoundsChangedNotifications = YES; + // Enable focus ring by default + _scrollView.enableFocusRing = YES; [self addSubview:_scrollView]; // a register for those notifications on the content view. @@ -89,6 +91,14 @@ - (void)setReactBorderInsets:(UIEdgeInsets)reactBorderInsets _scrollView.frame = UIEdgeInsetsInsetRect(self.bounds, reactBorderInsets); [self setNeedsLayout]; } + +- (void)setEnableFocusRing:(BOOL)enableFocusRing { + [super setEnableFocusRing:enableFocusRing]; + if ([_scrollView respondsToSelector:@selector(setEnableFocusRing:)]) { + [_scrollView setEnableFocusRing:YES]; + } +} + #endif // ]TODO(macOS GH#774) #pragma mark - UIScrollViewDelegate diff --git a/React/Base/RCTUIKit.h b/React/Base/RCTUIKit.h index 70439f162b9f48..f0c249efe294dd 100644 --- a/React/Base/RCTUIKit.h +++ b/React/Base/RCTUIKit.h @@ -425,6 +425,8 @@ CGPathRef UIBezierPathCreateCGPathRef(UIBezierPath *path); @property (nonatomic, assign) CGFloat zoomScale; @property (nonatomic, assign) BOOL alwaysBounceHorizontal; @property (nonatomic, assign) BOOL alwaysBounceVertical; +// macOS specific properties +@property (nonatomic, assign) BOOL enableFocusRing; @end diff --git a/React/Base/macOS/RCTUIKit.m b/React/Base/macOS/RCTUIKit.m index daed5ca08d6d33..b7ee45c50841eb 100644 --- a/React/Base/macOS/RCTUIKit.m +++ b/React/Base/macOS/RCTUIKit.m @@ -429,6 +429,19 @@ - (void)setBackgroundColor:(NSColor *)backgroundColor @implementation RCTUIScrollView // TODO(macOS ISS#3536887) +- (void)setEnableFocusRing:(BOOL)enableFocusRing { + if (_enableFocusRing != enableFocusRing) { + _enableFocusRing = enableFocusRing; + } + + if (enableFocusRing) { + // NSTextView has no focus ring by default so let's use the standard Aqua focus ring. + [self setFocusRingType:NSFocusRingTypeExterior]; + } else { + [self setFocusRingType:NSFocusRingTypeNone]; + } +} + // UIScrollView properties missing from NSScrollView - (CGPoint)contentOffset {