-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
RNTextInput.tsx
36 lines (30 loc) · 1.22 KB
/
RNTextInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type {ForwardedRef} from 'react';
import React from 'react';
import type {TextInputProps} from 'react-native';
import {TextInput} from 'react-native';
import Animated from 'react-native-reanimated';
import useTheme from '@hooks/useTheme';
// 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);
type AnimatedTextInputRef = typeof AnimatedTextInput & TextInput & HTMLInputElement;
function RNTextInputWithRef(props: TextInputProps, ref: ForwardedRef<AnimatedTextInputRef>) {
const theme = useTheme();
return (
<AnimatedTextInput
allowFontScaling={false}
textBreakStrategy="simple"
keyboardAppearance={theme.colorScheme}
ref={(refHandle) => {
if (typeof ref !== 'function') {
return;
}
ref(refHandle as AnimatedTextInputRef);
}}
// eslint-disable-next-line
{...props}
/>
);
}
RNTextInputWithRef.displayName = 'RNTextInputWithRef';
export default React.forwardRef(RNTextInputWithRef);
export type {AnimatedTextInputRef};