Skip to content

Commit ce56c6c

Browse files
authored
iOS: reload input views when autoCapitalize/autoCorrect/spellCheck change on a focused TextInput (#60319)
1 parent 98e424c commit ce56c6c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,22 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
208208
const auto &newTextInputProps = static_cast<const TextInputProps &>(*props);
209209

210210
// Traits:
211+
BOOL needsReloadInputViews = NO;
212+
211213
if (newTextInputProps.multiline != oldTextInputProps.multiline) {
212214
[self _setMultiline:newTextInputProps.multiline];
213215
}
214216

215217
if (newTextInputProps.traits.autocapitalizationType != oldTextInputProps.traits.autocapitalizationType) {
216218
_backedTextInputView.autocapitalizationType =
217219
RCTUITextAutocapitalizationTypeFromAutocapitalizationType(newTextInputProps.traits.autocapitalizationType);
220+
needsReloadInputViews = YES;
218221
}
219222

220223
if (newTextInputProps.traits.autoCorrect != oldTextInputProps.traits.autoCorrect) {
221224
_backedTextInputView.autocorrectionType =
222225
RCTUITextAutocorrectionTypeFromOptionalBool(newTextInputProps.traits.autoCorrect);
226+
needsReloadInputViews = YES;
223227
}
224228

225229
if (newTextInputProps.traits.contextMenuHidden != oldTextInputProps.traits.contextMenuHidden) {
@@ -251,6 +255,14 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
251255
if (newTextInputProps.traits.spellCheck != oldTextInputProps.traits.spellCheck) {
252256
_backedTextInputView.spellCheckingType =
253257
RCTUITextSpellCheckingTypeFromOptionalBool(newTextInputProps.traits.spellCheck);
258+
needsReloadInputViews = YES;
259+
}
260+
261+
// Without the call to reloadInputViews, a change to the capitalization, autocorrection or spell checking of the
262+
// focused field (the first responder) doesn't reach the keyboard until the field loses and regains focus. One
263+
// reload covers all three when they change together.
264+
if (needsReloadInputViews && _backedTextInputView.isFirstResponder) {
265+
[_backedTextInputView reloadInputViews];
254266
}
255267

256268
if (newTextInputProps.traits.caretHidden != oldTextInputProps.traits.caretHidden) {

0 commit comments

Comments
 (0)