Skip to content

Commit f462fc1

Browse files
Preserve TextInput returnKeyType when changing multiline
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.
1 parent 8cfde6d commit f462fc1

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void RCTCopyBackedTextInput(
4343
toTextInput.scrollEnabled = fromTextInput.scrollEnabled;
4444
toTextInput.secureTextEntry = fromTextInput.secureTextEntry;
4545
toTextInput.keyboardType = fromTextInput.keyboardType;
46+
toTextInput.returnKeyType = fromTextInput.returnKeyType;
4647
toTextInput.textContentType = fromTextInput.textContentType;
4748
toTextInput.smartInsertDeleteType = fromTextInput.smartInsertDeleteType;
4849
toTextInput.passwordRules = fromTextInput.passwordRules;

packages/react-native/React/Tests/Text/RCTTextInputUtilsTest.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ - (void)testCopyBackedTextInputPreservesTintColor
2626
XCTAssertEqualObjects(destination.tintColor, UIColor.redColor);
2727
}
2828

29+
- (void)testCopyBackedTextInputPreservesReturnKeyType
30+
{
31+
RCTUITextField *source = [RCTUITextField new];
32+
RCTUITextView *destination = [RCTUITextView new];
33+
source.returnKeyType = UIReturnKeyDone;
34+
35+
RCTCopyBackedTextInput(source, destination);
36+
37+
XCTAssertEqual(destination.returnKeyType, UIReturnKeyDone);
38+
}
39+
2940
@end

0 commit comments

Comments
 (0)