From 76717f39f936010294be89a7b9147decdf99a556 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Thu, 18 Aug 2022 01:29:12 -0300 Subject: [PATCH] feat: Add readOnly prop to TextInput --- Libraries/Components/TextInput/TextInput.js | 9 ++++++ .../TextInput/TextInputExample.android.js | 29 +++++++++++++++++++ .../TextInput/TextInputExample.ios.js | 29 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 8e3296f5d2cf20..c0fa000f771140 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -532,6 +532,13 @@ export type Props = $ReadOnly<{| */ editable?: ?boolean, + /** `readOnly` works like the `readonly` attribute in HTML. + * If `true`, text is not editable. The default value is `false`. + * See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly + * for more details. + */ + readOnly?: ?boolean, + forwardedRef?: ?ReactRefSetter< React.ElementRef> & ImperativeMethods, >, @@ -1381,6 +1388,7 @@ const ExportedForwardRef: React.AbstractComponent< allowFontScaling = true, rejectResponderTermination = true, underlineColorAndroid = 'transparent', + readOnly = false, ...restProps }, forwardedRef: ReactRefSetter< @@ -1392,6 +1400,7 @@ const ExportedForwardRef: React.AbstractComponent< allowFontScaling={allowFontScaling} rejectResponderTermination={rejectResponderTermination} underlineColorAndroid={underlineColorAndroid} + editable={!readOnly} {...restProps} forwardedRef={forwardedRef} /> diff --git a/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js b/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js index bf41299b8d3016..5db65783b86883 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputExample.android.js @@ -347,6 +347,35 @@ exports.examples = ([ ); }, }, + { + title: 'Editable and Read only', + render: function (): React.Node { + return ( + + + + + + + ); + }, + }, { title: 'Fixed number of lines', platform: 'android', diff --git a/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js b/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js index ba2be2aaf8e29f..b3940a1f8332d5 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js @@ -621,6 +621,35 @@ exports.examples = ([ ); }, }, + { + title: 'Editable and Read only', + render: function (): React.Node { + return ( + + + + + + + ); + }, + }, { title: 'TextInput Intrinsic Size', render: function (): React.Node {