Skip to content

Commit

Permalink
Turn on focus ring for multiline textinput (facebook#1276) (facebook#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chiuam authored Jul 25, 2022
1 parent ffa3c99 commit 32e83dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions React/Base/RCTUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions React/Base/macOS/RCTUIKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 32e83dc

Please sign in to comment.