Preserve TextInput returnKeyType when changing multiline - #58355
Preserve TextInput returnKeyType when changing multiline#58355jamfromouterspace wants to merge 1 commit into
Conversation
RCTCopyBackedTextInput copies the keyboard traits over to the replacement backing view when a TextInput switches between single-line and multiline, but omits returnKeyType. The prop itself is unchanged across the transition, so the prop diff does not re-run the setter and the new view keeps its default Return key. Copy returnKeyType alongside keyboardType, and add a regression test next to the existing tintColor one.
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
RCTCopyBackedTextInputis called when aTextInputswitches betweensingle-line and multiline and the Fabric component view swaps its backing
UIKit view (
RCTUITextField<->RCTUITextView). It copies the keyboardtraits across to the replacement view, but
returnKeyTypeis not among them —keyboardTypeis copied on the line directly above it.Because the prop itself has not changed across the transition, the prop diff in
RCTTextInputComponentViewseesdone->doneand does not re-run thesetter. The replacement view therefore keeps its default Return key, so an
input declared
returnKeyType="done"renders the newline key instead of Doneonce it has flipped to multiline.
This is the same class of omission that was fixed for
tintColorin #57748,and the fix is the same shape: copy the property along with its neighbours.
Repro: a
TextInputwith a stable key andreturnKeyType="done"whosemultilineprop goesfalse->true. After the transition, focusing it showsthe default Return key. Fabric view recycling can produce the same backing-view
transition even for an input that is always multiline, which makes it
intermittent in real apps.
Verified against 0.86.3; the line is still missing on 0.87.1 and on
main.Changelog:
[IOS] [FIXED] - Preserve TextInput returnKeyType when switching between single-line and multiline backing views.
Test Plan:
Added
testCopyBackedTextInputPreservesReturnKeyTypetoReact/Tests/Text/RCTTextInputUtilsTest.mm, alongside the existingtestCopyBackedTextInputPreservesTintColoradded in #57748. It setsreturnKeyType = UIReturnKeyDoneon anRCTUITextField, runsRCTCopyBackedTextInputinto anRCTUITextView, and asserts the valuesurvives. The test fails without the one-line change and passes with it.
Also confirmed in a production app: a multiline
TextInputwithreturnKeyType="done"intermittently displayed the newline key, and addingthis single line fixed it.