-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextInput.tsx
37 lines (31 loc) · 1.06 KB
/
TextInput.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
37
import React, { forwardRef, useRef, useCallback } from 'react';
import {Platform, StyleSheet, TextInput, TextInputProps} from 'react-native';
const CustomTextInput = forwardRef<TextInput, TextInputProps>((props, ref) => {
const inputRef = useRef<TextInput | null>(null);
const setRef = useCallback(
(node: TextInput | null) => {
if (node) {
inputRef.current = node;
if (typeof ref === 'function') {
ref(node);
} else if (ref) {
const mutableRef = ref as React.MutableRefObject<TextInput | null>;
mutableRef.current = node;
}
// Workaround for Android to apply style before setting placeholder
// to apply font family correctly
if (Platform.OS === 'android') {
node.setNativeProps({
style: StyleSheet.flatten([{
fontFamily: 'Roboto',
fontWeight: '400',
}, props.style ?? {}]),
});
}
}
},
[ref],
);
return <TextInput ref={setRef} {...props} />;
});
export default CustomTextInput;