From 4a22f2c816e20bf05191ce111a989ac5362e01e1 Mon Sep 17 00:00:00 2001 From: Yunlong Wu Date: Tue, 10 Sep 2024 09:08:23 -0700 Subject: [PATCH] Add TextInput.editable and BaseTextInputProps (#46356) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46356 # Changelog: [Internal]- Currently TextInput does not expose `editable` and `readOnly` (only `editable` is exposed as Android-specific prop). This change is to add them to BaseTextInputProps so they can be supported cross-platform. Reviewed By: rshest Differential Revision: D62180722 fbshipit-source-id: 6cb82589f1d36b61167761f5a2e70e8d4b31b01b --- .../components/textinput/BaseTextInputProps.cpp | 14 ++++++++++++++ .../components/textinput/BaseTextInputProps.h | 3 +++ .../androidtextinput/AndroidTextInputProps.cpp | 4 ---- .../androidtextinput/AndroidTextInputProps.h | 1 - 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp index ec0f350b5a4..a8330828df1 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp @@ -102,6 +102,18 @@ BaseTextInputProps::BaseTextInputProps( rawProps, "autoCapitalize", sourceProps.autoCapitalize, + {})), + editable(convertRawProp( + context, + rawProps, + "editable", + sourceProps.editable, + {})), + readOnly(convertRawProp( + context, + rawProps, + "readOnly", + sourceProps.readOnly, {})) {} void BaseTextInputProps::setProp( @@ -180,6 +192,8 @@ void BaseTextInputProps::setProp( RAW_SET_PROP_SWITCH_CASE_BASIC(text); RAW_SET_PROP_SWITCH_CASE_BASIC(mostRecentEventCount); RAW_SET_PROP_SWITCH_CASE_BASIC(autoCapitalize); + RAW_SET_PROP_SWITCH_CASE_BASIC(editable); + RAW_SET_PROP_SWITCH_CASE_BASIC(readOnly); } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.h index bff69fef7c8..d6476254d7a 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.h @@ -63,6 +63,9 @@ class BaseTextInputProps : public ViewProps, public BaseTextProps { bool autoFocus{false}; std::string autoCapitalize{}; + + bool editable{true}; + bool readOnly{false}; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp index 6f318ca7095..2d7e82532e1 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp @@ -87,8 +87,6 @@ AndroidTextInputProps::AndroidTextInputProps( "maxFontSizeMultiplier", sourceProps.maxFontSizeMultiplier, {0.0})), - editable(CoreFeatures::enablePropIteratorSetter? sourceProps.editable : - convertRawProp(context, rawProps, "editable", sourceProps.editable, {false})), keyboardType(CoreFeatures::enablePropIteratorSetter? sourceProps.keyboardType : convertRawProp(context, rawProps, "keyboardType", sourceProps.keyboardType, @@ -223,7 +221,6 @@ void AndroidTextInputProps::setProp( RAW_SET_PROP_SWITCH_CASE_BASIC(autoCorrect); RAW_SET_PROP_SWITCH_CASE_BASIC(allowFontScaling); RAW_SET_PROP_SWITCH_CASE_BASIC(maxFontSizeMultiplier); - RAW_SET_PROP_SWITCH_CASE_BASIC(editable); RAW_SET_PROP_SWITCH_CASE_BASIC(keyboardType); RAW_SET_PROP_SWITCH_CASE_BASIC(returnKeyType); RAW_SET_PROP_SWITCH_CASE_BASIC(multiline); @@ -313,7 +310,6 @@ folly::dynamic AndroidTextInputProps::getDynamic() const { props["autoFocus"] = autoFocus; props["allowFontScaling"] = allowFontScaling; props["maxFontSizeMultiplier"] = maxFontSizeMultiplier; - props["editable"] = editable; props["keyboardType"] = keyboardType; props["returnKeyType"] = returnKeyType; props["maxLength"] = maxLength; diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h index da41bb4ce25..6f716281867 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h @@ -87,7 +87,6 @@ class AndroidTextInputProps final : public BaseTextInputProps { bool autoCorrect{false}; bool allowFontScaling{false}; Float maxFontSizeMultiplier{0.0}; - bool editable{false}; std::string keyboardType{}; std::string returnKeyType{}; bool multiline{false};