Skip to content

Commit 83a76fa

Browse files
cipolleschimeta-codesync[bot]
authored andcommitted
Derive multiline TextInput state from props (#59218)
Summary: Pull Request resolved: #59218 Use `TextInputProps::multiline` as the source of truth for multiline checks instead of inferring it from the backed UIKit class. This keeps responder offset and selection restoration logic aligned with the declarative props. Changelog: [Internal] Reviewed By: Abbondanzo Differential Revision: D126285220 fbshipit-source-id: 42274a5f57189257ee27e21de2940c3df28b6205
1 parent 54b5f22 commit 83a76fa

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollViewComponentView *)sc
180180
} else {
181181
// Focus on text selection frame
182182
focusRect = selection.rect;
183-
BOOL isMultiline = [_backedTextInputView isKindOfClass:[UITextView class]];
183+
BOOL isMultiline = _props ? static_cast<const TextInputProps &>(*_props).multiline
184+
: [_backedTextInputView isKindOfClass:[UITextView class]];
184185
if (!isMultiline) {
185186
focusRect.size.height += kSingleLineKeyboardBottomOffset;
186187
}
@@ -859,7 +860,8 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
859860
// A single-line input that is not being edited has no cursor to keep: UIKit places one when editing begins.
860861
// Restoring it anyway makes UIKit scroll the field editor to it when the text doesn't fit, and the editor keeps
861862
// that offset after the text fits again, so text typed later in this view (also after recycling) is drawn too high.
862-
BOOL isMultiline = [_backedTextInputView isKindOfClass:[UITextView class]];
863+
BOOL isMultiline = _props ? static_cast<const TextInputProps &>(*_props).multiline
864+
: [_backedTextInputView isKindOfClass:[UITextView class]];
863865
if (isMultiline || _backedTextInputView.isFirstResponder) {
864866
// Updating the UITextView attributedText, for example changing the lineHeight, the color or adding
865867
// a new paragraph with \n, causes the cursor to move to the end of the Text and scroll.

0 commit comments

Comments
 (0)