Skip to content

Commit 11ab6cd

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Use wrapped text view for multiline TextInput
Summary: This diff updates the core TextInput RN component to use the wrapped text view for multiline TextInput. Switching to `RCTWrappedTextView` enables correct `borderWidth` and `contentInsets` support for multi line text inputs while maintaining the same functionality for single line text input. Scrolling text views are also supported correctly, with vertical height dependent scrollers. Test Plan: - Build Zeratul with Fabric enabled. - Type in the search field to test the layout of the text contents - Type in the composer to test multi line support and the layout of the text contents | Before | After | |--| | https://pxl.cl/3Xrrx | https://pxl.cl/3Xrr9 | Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D51962396 Tasks: T167538822, T157889591
1 parent c7ecd3c commit 11ab6cd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#import <React/RCTUITextField.h>
1717
#import <React/RCTUITextView.h>
1818
#import <React/RCTUtils.h>
19+
#if TARGET_OS_OSX // [macOS
20+
#import <React/RCTWrappedTextView.h>
21+
#endif // macOS]
1922

2023
#import "RCTConversions.h"
2124
#import "RCTTextInputNativeCommands.h"
@@ -86,7 +89,11 @@ - (instancetype)initWithFrame:(CGRect)frame
8689
const auto &defaultProps = TextInputShadowNode::defaultSharedProps();
8790
_props = defaultProps;
8891

92+
#if !TARGET_OS_OSX // [macOS]
8993
_backedTextInputView = defaultProps->multiline ? [RCTUITextView new] : [RCTUITextField new];
94+
#else // [macOS
95+
_backedTextInputView = defaultProps->multiline ? [[RCTWrappedTextView alloc] initWithFrame:self.bounds] : [RCTUITextField new];
96+
#endif // macOS]
9097
_backedTextInputView.textInputDelegate = self;
9198
_ignoreNextTextInputCall = NO;
9299
_comingFromJS = NO;
@@ -672,7 +679,7 @@ - (void)blur
672679
[_backedTextInputView resignFirstResponder];
673680
#else // [macOS
674681
NSWindow *window = [_backedTextInputView window];
675-
if ([window firstResponder] == _backedTextInputView) {
682+
if ([window firstResponder] == _backedTextInputView.responder) {
676683
[window makeFirstResponder:nil];
677684
}
678685
#endif // macOS]
@@ -967,7 +974,7 @@ - (void)_setMultiline:(BOOL)multiline
967974
#if !TARGET_OS_OSX // [macOS]
968975
RCTUIView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTUITextView new] : [RCTUITextField new];
969976
#else // [macOS
970-
RCTUITextView<RCTBackedTextInputViewProtocol> *backedTextInputView = [RCTUITextView new];
977+
RCTPlatformView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTWrappedTextView new] : [RCTUITextField new];
971978
#endif // macOS]
972979
backedTextInputView.frame = _backedTextInputView.frame;
973980
RCTCopyBackedTextInput(_backedTextInputView, backedTextInputView);

0 commit comments

Comments
 (0)