@@ -18,62 +18,64 @@ type Props = {
18
18
}
19
19
) => React . ReactElement ;
20
20
chainTo ?: string ;
21
- ref : React . RefObject < RNTextInput > ;
21
+ ref ? : React . RefObject < RNTextInput > ;
22
22
} ;
23
23
24
- export const TextInput = ( props : Props ) => {
25
- const id = React . useId ( ) ;
26
- const name = React . useRef ( props . name ?? id ) ;
27
- const textInputRef = React . useRef < RNTextInput > ( null ) ;
24
+ export const TextInput = React . forwardRef < RNTextInput , Props > (
25
+ ( props , inputRef ) => {
26
+ const id = React . useId ( ) ;
27
+ const name = React . useRef ( props . name ?? id ) ;
28
+ const textInputRef = React . useRef < RNTextInput > ( null ) ;
28
29
29
- const ref = mergeRefs ( [ textInputRef , props . ref ] ) ;
30
+ const ref = mergeRefs ( [ textInputRef , inputRef ] ) ;
30
31
31
- const { onBlur, onFocus, onSubmitEditing, ...textInputProps } =
32
- props . textInputProps ?? { } ;
32
+ const { onBlur, onFocus, onSubmitEditing, ...textInputProps } =
33
+ props . textInputProps ?? { } ;
33
34
34
- const { registerInput, baseTextInputProps, chainInput } =
35
- useFormSmartScroll ( ) ;
35
+ const { registerInput, baseTextInputProps, chainInput } =
36
+ useFormSmartScroll ( ) ;
36
37
37
- React . useEffect ( ( ) => {
38
- registerInput ( name . current , textInputRef ) ;
39
- } , [ ] ) ;
38
+ React . useEffect ( ( ) => {
39
+ registerInput ( name . current , textInputRef ) ;
40
+ } , [ ] ) ;
40
41
41
- return (
42
- < ViewWrapper name = { name . current } style = { props . containerStyle } >
43
- { typeof props . renderInput === 'function' ? (
44
- props . renderInput ( {
45
- ...( textInputProps ?? { } ) ,
46
- onSubmitEditing : ( e ) => {
47
- if ( props . chainTo ) {
48
- chainInput ( props . chainTo ) ;
49
- }
50
-
51
- onSubmitEditing ?.( e ) ;
52
- } ,
53
- ...baseTextInputProps ( name . current , {
54
- onFocus,
55
- onBlur,
56
- } ) ,
57
- ref,
58
- } )
59
- ) : (
60
- < >
61
- { props . renderTop ?.( ) }
62
- < RNTextInput
63
- ref = { ref }
64
- { ...baseTextInputProps ( name . current , { onFocus, onBlur } ) }
65
- { ...textInputProps }
66
- onSubmitEditing = { ( e ) => {
42
+ return (
43
+ < ViewWrapper name = { name . current } style = { props . containerStyle } >
44
+ { typeof props . renderInput === 'function' ? (
45
+ props . renderInput ( {
46
+ ...( textInputProps ?? { } ) ,
47
+ onSubmitEditing : ( e ) => {
67
48
if ( props . chainTo ) {
68
49
chainInput ( props . chainTo ) ;
69
50
}
70
51
71
52
onSubmitEditing ?.( e ) ;
72
- } }
73
- />
74
- { props . renderBottom ?.( ) }
75
- </ >
76
- ) }
77
- </ ViewWrapper >
78
- ) ;
79
- } ;
53
+ } ,
54
+ ...baseTextInputProps ( name . current , {
55
+ onFocus,
56
+ onBlur,
57
+ } ) ,
58
+ ref,
59
+ } )
60
+ ) : (
61
+ < >
62
+ { props . renderTop ?.( ) }
63
+ < RNTextInput
64
+ ref = { ref }
65
+ { ...baseTextInputProps ( name . current , { onFocus, onBlur } ) }
66
+ { ...textInputProps }
67
+ onSubmitEditing = { ( e ) => {
68
+ if ( props . chainTo ) {
69
+ chainInput ( props . chainTo ) ;
70
+ }
71
+
72
+ onSubmitEditing ?.( e ) ;
73
+ } }
74
+ />
75
+ { props . renderBottom ?.( ) }
76
+ </ >
77
+ ) }
78
+ </ ViewWrapper >
79
+ ) ;
80
+ }
81
+ ) ;
0 commit comments