Skip to content

Commit 3968a53

Browse files
CopilotSaadnajmi
andcommitted
Simplify fix to just set clipsToBounds in initWithFrame on macOS
Co-authored-by: Saadnajmi <[email protected]>
1 parent c8712e8 commit 3968a53

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ - (instancetype)initWithFrame:(CGRect)frame
114114
_originalTypingAttributes = [_backedTextInputView.typingAttributes copy];
115115

116116
#if TARGET_OS_OSX // [macOS
117-
// Ensure the backing text view doesn't interfere with border rendering
118-
// by making sure it doesn't draw outside its bounds
119-
if (_backedTextInputView.layer) {
120-
_backedTextInputView.layer.masksToBounds = YES;
121-
}
117+
[self setClipsToBounds:YES];
122118
#endif // macOS]
123119

124120
[self addSubview:_backedTextInputView];
@@ -421,24 +417,6 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
421417
{
422418
CGSize previousContentSize = _backedTextInputView.contentSize;
423419

424-
#if TARGET_OS_OSX // [macOS
425-
// On macOS, ensure proper border rendering by enabling clip to bounds
426-
// when borders are present. This forces Core Animation border rendering
427-
// which displays correctly with the native text field subview.
428-
const auto &props = static_cast<const TextInputProps &>(*_props);
429-
const auto borderMetrics = props.resolveBorderMetrics(layoutMetrics);
430-
BOOL hasBorder = borderMetrics.borderWidths.left > 0 || borderMetrics.borderWidths.right > 0 ||
431-
borderMetrics.borderWidths.top > 0 || borderMetrics.borderWidths.bottom > 0;
432-
if (hasBorder) {
433-
// Note: Setting clipsToBounds ensures Core Animation border rendering is used,
434-
// which properly displays with the native text field subview on macOS
435-
self.clipsToBounds = YES;
436-
} else {
437-
// Reset clipsToBounds when no borders are present
438-
self.clipsToBounds = NO;
439-
}
440-
#endif // macOS]
441-
442420
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
443421

444422
#if TARGET_OS_OSX // [macOS
@@ -465,10 +443,6 @@ - (void)prepareForRecycle
465443
_ignoreNextTextInputCall = NO;
466444
_didMoveToWindow = NO;
467445
[_backedTextInputView resignFirstResponder];
468-
#if TARGET_OS_OSX // [macOS
469-
// Reset clipsToBounds to prevent state leakage in recycled components
470-
self.clipsToBounds = NO;
471-
#endif // macOS]
472446
}
473447

474448
#pragma mark - RCTBackedTextInputDelegate

0 commit comments

Comments
 (0)