-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30056 from software-mansion-labs/ts-migration/rn-…
…text-input-component [TS migration] Migrate 'RNTextInput.js' component to TypeScript
- Loading branch information
Showing
2 changed files
with
29 additions
and
51 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<React.Component<AnimatedProps<TextInputProps>>>) { | ||
return ( | ||
<AnimatedTextInput | ||
allowFontScaling={false} | ||
textBreakStrategy="simple" | ||
ref={(refHandle) => { | ||
if (typeof ref !== 'function') { | ||
return; | ||
} | ||
ref(refHandle); | ||
}} | ||
// eslint-disable-next-line | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
RNTextInputWithRef.displayName = 'RNTextInputWithRef'; | ||
|
||
export default React.forwardRef(RNTextInputWithRef); |