From 56c284e152aedd3155ae34ed959fc745f970a451 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Wed, 29 Jul 2026 04:15:34 -0700 Subject: [PATCH] Preserve TextInput selection color when changing multiline (#57748) Summary: - Preserve the native text input tint color when switching between single-line and multiline backing views. - Add a native regression test for copying the tint from `RCTUITextField` to `RCTUITextView`. Fabric replaces the backing text input view when `multiline` changes. `RCTCopyBackedTextInput` preserved the other native presentation properties but omitted `tintColor`, which implements `selectionColor` on iOS. Since the React prop itself was unchanged, the normal prop diff did not apply it again and the selection color fell back to the system tint. Fixes https://github.com/react/react-native/issues/57105 ## Changelog: [IOS] [FIXED] - Preserve TextInput selection color when changing multiline. Pull Request resolved: https://github.com/react/react-native/pull/57748 Test Plan: - Added `RCTTextInputUtilsTest.testCopyBackedTextInputPreservesTintColor`. - Ran clang-format validation and `git diff --check`. Reviewed By: javache Differential Revision: D113980213 Pulled By: Abbondanzo fbshipit-source-id: 73a5f87e1b45b504f4640572b8c1a26b4d97f43f --- .../TextInput/RCTTextInputUtils.mm | 1 + .../React/Tests/Text/RCTTextInputUtilsTest.mm | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 packages/react-native/React/Tests/Text/RCTTextInputUtilsTest.mm diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm index 95142a605c0..ea70105798a 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm @@ -25,6 +25,7 @@ void RCTCopyBackedTextInput( toTextInput.attributedText = RCTSanitizeAttributedString(fromTextInput.attributedText); toTextInput.placeholder = fromTextInput.placeholder; toTextInput.placeholderColor = fromTextInput.placeholderColor; + toTextInput.tintColor = fromTextInput.tintColor; toTextInput.textContainerInset = fromTextInput.textContainerInset; toTextInput.inputAccessoryView = fromTextInput.inputAccessoryView; toTextInput.textInputDelegate = fromTextInput.textInputDelegate; diff --git a/packages/react-native/React/Tests/Text/RCTTextInputUtilsTest.mm b/packages/react-native/React/Tests/Text/RCTTextInputUtilsTest.mm new file mode 100644 index 00000000000..2559670f865 --- /dev/null +++ b/packages/react-native/React/Tests/Text/RCTTextInputUtilsTest.mm @@ -0,0 +1,29 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import +#import +#import +#import + +@interface RCTTextInputUtilsTest : XCTestCase +@end + +@implementation RCTTextInputUtilsTest + +- (void)testCopyBackedTextInputPreservesTintColor +{ + RCTUITextField *source = [RCTUITextField new]; + RCTUITextView *destination = [RCTUITextView new]; + source.tintColor = UIColor.redColor; + + RCTCopyBackedTextInput(source, destination); + + XCTAssertEqualObjects(destination.tintColor, UIColor.redColor); +} + +@end