diff --git a/src/components/RNTextInput.js b/src/components/RNTextInput.js deleted file mode 100644 index d308c42f4947..000000000000 --- a/src/components/RNTextInput.js +++ /dev/null @@ -1,51 +0,0 @@ -import PropTypes from 'prop-types'; -import React from 'react'; -// eslint-disable-next-line no-restricted-imports -import {TextInput} from 'react-native'; -import Animated from 'react-native-reanimated'; -import _ from 'underscore'; - -const propTypes = { - /** A ref to forward to the text input */ - forwardedRef: PropTypes.func, -}; - -const defaultProps = { - forwardedRef: () => {}, -}; - -// 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) { - return ( - { - if (!_.isFunction(props.forwardedRef)) { - return; - } - props.forwardedRef(ref); - }} - // eslint-disable-next-line - {...props} - /> - ); -} - -RNTextInput.propTypes = propTypes; -RNTextInput.defaultProps = defaultProps; -RNTextInput.displayName = 'RNTextInput'; - -const RNTextInputWithRef = React.forwardRef((props, ref) => ( - -)); - -RNTextInputWithRef.displayName = 'RNTextInputWithRef'; - -export default RNTextInputWithRef; diff --git a/src/components/RNTextInput.tsx b/src/components/RNTextInput.tsx new file mode 100644 index 000000000000..28555abe3266 --- /dev/null +++ b/src/components/RNTextInput.tsx @@ -0,0 +1,29 @@ +import React, {ForwardedRef} from 'react'; +// eslint-disable-next-line no-restricted-imports +import {TextInput, TextInputProps} from 'react-native'; +import Animated, {AnimatedProps} from 'react-native-reanimated'; + +// 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 RNTextInputWithRef(props: TextInputProps, ref: ForwardedRef>>) { + return ( + { + if (typeof ref !== 'function') { + return; + } + ref(refHandle); + }} + // eslint-disable-next-line + {...props} + /> + ); +} + +RNTextInputWithRef.displayName = 'RNTextInputWithRef'; + +export default React.forwardRef(RNTextInputWithRef);