From 83cf7623e9fe7aadcf5b9254b03911614c412711 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 18 Oct 2023 15:51:37 +0200 Subject: [PATCH 1/3] Rename RNTextInput --- src/components/{RNTextInput.js => RNTextInput.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/components/{RNTextInput.js => RNTextInput.tsx} (100%) diff --git a/src/components/RNTextInput.js b/src/components/RNTextInput.tsx similarity index 100% rename from src/components/RNTextInput.js rename to src/components/RNTextInput.tsx From d77a4cf15b5a0cac2bde3c08019dce4986768f28 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Wed, 18 Oct 2023 16:21:59 +0200 Subject: [PATCH 2/3] [TS migration] Migrate 'RNTextInput.js' component to TypeScript --- src/components/RNTextInput.tsx | 36 ++++++++++------------------------ 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/components/RNTextInput.tsx b/src/components/RNTextInput.tsx index 5a790cde91d7..98ccd8b1a20d 100644 --- a/src/components/RNTextInput.tsx +++ b/src/components/RNTextInput.tsx @@ -1,32 +1,24 @@ -import React from 'react'; -import _ from 'underscore'; +import React, {ForwardedRef} from 'react'; // eslint-disable-next-line no-restricted-imports -import {TextInput} from 'react-native'; -import Animated from 'react-native-reanimated'; -import PropTypes from 'prop-types'; +import {TextInput, TextInputProps} from 'react-native'; +import Animated, {AnimateProps} from 'react-native-reanimated'; -const propTypes = { - /** A ref to forward to the text input */ - forwardedRef: PropTypes.func, -}; - -const defaultProps = { - forwardedRef: () => {}, -}; +type RNTextInputProps = Record; // Convert the underlying TextInput into an Animated component so that we can take an animated ref and pass it to a worklet const AnimatedTextInput = Animated.createAnimatedComponent(TextInput); -function RNTextInput(props) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function RNTextInput(props: RNTextInputProps, ref: ForwardedRef>>) { return ( { - if (!_.isFunction(props.forwardedRef)) { + ref={(refHandle) => { + if (typeof ref !== 'function') { return; } - props.forwardedRef(ref); + ref(refHandle); }} // eslint-disable-next-line {...props} @@ -34,14 +26,6 @@ function RNTextInput(props) { ); } -RNTextInput.propTypes = propTypes; -RNTextInput.defaultProps = defaultProps; RNTextInput.displayName = 'RNTextInput'; -export default React.forwardRef((props, ref) => ( - -)); +export default React.forwardRef(RNTextInput); From ac4a37ea77fd4e61a58f3bb2480c576e11a047e9 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Fri, 20 Oct 2023 09:46:38 +0200 Subject: [PATCH 3/3] Remove unnecessary type --- src/components/RNTextInput.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/RNTextInput.tsx b/src/components/RNTextInput.tsx index 98ccd8b1a20d..77a98154c601 100644 --- a/src/components/RNTextInput.tsx +++ b/src/components/RNTextInput.tsx @@ -3,13 +3,11 @@ import React, {ForwardedRef} from 'react'; import {TextInput, TextInputProps} from 'react-native'; import Animated, {AnimateProps} from 'react-native-reanimated'; -type RNTextInputProps = Record; - // Convert the underlying TextInput into an Animated component so that we can take an animated ref and pass it to a worklet const AnimatedTextInput = Animated.createAnimatedComponent(TextInput); // eslint-disable-next-line @typescript-eslint/no-explicit-any -function RNTextInput(props: RNTextInputProps, ref: ForwardedRef>>) { +function RNTextInput(props: TextInputProps, ref: ForwardedRef>>) { return (