diff --git a/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js b/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js index 61e37c54bea..27f7abbe7d1 100644 --- a/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +++ b/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js @@ -183,7 +183,6 @@ export type NativeProps = $ReadOnly<{| /** * When `false`, it will prevent the soft keyboard from showing when the field is focused. * Defaults to `true`. - * @platform android */ showSoftInputOnFocus?: ?boolean, diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index da0e0bd77b3..75a7c417d5c 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -408,7 +408,6 @@ type AndroidProps = $ReadOnly<{| /** * When `false`, it will prevent the soft keyboard from showing when the field is focused. * Defaults to `true`. - * @platform android */ showSoftInputOnFocus?: ?boolean, |}>; diff --git a/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js b/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js index 275d607b948..52a4714d84e 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js @@ -616,7 +616,6 @@ module.exports = { /** * When `false`, it will prevent the soft keyboard from showing when the field is focused. * Defaults to `true`. - * @platform android */ showSoftInputOnFocus: PropTypes.bool, }; diff --git a/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h b/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h index 5c4c28de027..2fd80897eb8 100644 --- a/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +++ b/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readonly) BOOL textWasPasted; @property (nonatomic, assign) UIEdgeInsets textContainerInset; @property (nonatomic, strong, nullable) UIView *inputAccessoryView; +@property (nonatomic, strong, nullable) UIView *inputView; @property (nonatomic, weak, nullable) id textInputDelegate; @property (nonatomic, readonly) CGSize contentSize; @property (nonatomic, strong, nullable) NSDictionary *defaultTextAttributes; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.h b/Libraries/Text/TextInput/RCTBaseTextInputView.h index fb5f02ec5ad..d7fc54bed85 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.h +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.h @@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, nullable) NSAttributedString *attributedText; @property (nonatomic, copy) NSString *inputAccessoryViewID; @property (nonatomic, assign) UIKeyboardType keyboardType; +@property (nonatomic, assign) BOOL showSoftInputOnFocus; /** Sets selection intext input if both start and end are within range of the text input. diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index aa69593f68f..37b849c2776 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -302,6 +302,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) } } +- (void)setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus +{ + if (showSoftInputOnFocus) { + // Resets to default keyboard. + self.backedTextInputView.inputView = nil; + } else { + // Hides keyboard, but keeps blinking cursor. + self.backedTextInputView.inputView = [[UIView alloc] init]; + } +} + #pragma mark - RCTBackedTextInputDelegate - (BOOL)textInputShouldBeginEditing diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index dca143760a1..34994ca4fd1 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -52,6 +52,7 @@ RCT_EXPORT_VIEW_PROPERTY(autoFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL) RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType) +RCT_EXPORT_VIEW_PROPERTY(showSoftInputOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber) RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL) RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection) diff --git a/RNTester/js/examples/TextInput/TextInputExample.ios.js b/RNTester/js/examples/TextInput/TextInputExample.ios.js index 7e1673070e0..311efa1179b 100644 --- a/RNTester/js/examples/TextInput/TextInputExample.ios.js +++ b/RNTester/js/examples/TextInput/TextInputExample.ios.js @@ -707,4 +707,16 @@ exports.examples = ([ ); }, }, + { + title: 'showSoftInputOnFocus', + render: function(): React.Node { + return ( + + + + + + ); + }, + }, ]: Array); diff --git a/ReactCommon/fabric/components/textinput/iostextinput/primitives.h b/ReactCommon/fabric/components/textinput/iostextinput/primitives.h index 1bd7caa9386..f10fa2b42e3 100644 --- a/ReactCommon/fabric/components/textinput/iostextinput/primitives.h +++ b/ReactCommon/fabric/components/textinput/iostextinput/primitives.h @@ -180,6 +180,12 @@ class TextInputTraits final { */ KeyboardType keyboardType{KeyboardType::Default}; + /* + * iOS & Android + * Default value: `true`. + */ + bool showSoftInputOnFocus{true}; + /* * Some values iOS- or Android-only (inherently particular-OS-specific) * Default value: `Default`. diff --git a/ReactCommon/fabric/components/textinput/iostextinput/propsConversions.h b/ReactCommon/fabric/components/textinput/iostextinput/propsConversions.h index 6c12a5716a1..6b5150d0aae 100644 --- a/ReactCommon/fabric/components/textinput/iostextinput/propsConversions.h +++ b/ReactCommon/fabric/components/textinput/iostextinput/propsConversions.h @@ -88,6 +88,11 @@ static TextInputTraits convertRawProp( "keyboardType", sourceTraits.keyboardType, defaultTraits.keyboardType); + traits.showSoftInputOnFocus = convertRawProp( + rawProps, + "showSoftInputOnFocus", + sourceTraits.showSoftInputOnFocus, + defaultTraits.showSoftInputOnFocus); traits.returnKeyType = convertRawProp( rawProps, "returnKeyType",