@@ -85,21 +85,20 @@ const inputPlaceholderSlots = Array.from(Array(CONST.MAGIC_CODE_LENGTH).keys());
85
85
86
86
function MagicCodeInput ( props ) {
87
87
const inputRefs = useRef ( [ ] ) ;
88
-
89
88
const [ input , setInput ] = useState ( '' ) ;
90
89
const [ focusedIndex , setFocusedIndex ] = useState ( 0 ) ;
91
90
const [ editIndex , setEditIndex ] = useState ( 0 ) ;
92
91
93
92
useImperativeHandle ( props . innerRef , ( ) => ( {
94
93
focus ( ) {
95
94
setFocusedIndex ( 0 ) ;
96
- inputRefs [ 0 ] . focus ( ) ;
95
+ inputRefs . current [ 0 ] . focus ( ) ;
97
96
} ,
98
97
clear ( ) {
99
98
setInput ( '' ) ;
100
99
setFocusedIndex ( 0 ) ;
101
100
setEditIndex ( 0 ) ;
102
- inputRefs [ 0 ] . focus ( ) ;
101
+ inputRefs . current [ 0 ] . focus ( ) ;
103
102
props . onChangeText ( '' ) ;
104
103
} ,
105
104
} ) ) ;
@@ -111,7 +110,7 @@ function MagicCodeInput(props) {
111
110
if ( ! props . shouldSubmitOnComplete || _ . filter ( numbers , n => ValidationUtils . isNumeric ( n ) ) . length !== CONST . MAGIC_CODE_LENGTH ) {
112
111
return ;
113
112
}
114
- inputRefs [ editIndex ] . blur ( ) ;
113
+ inputRefs . current [ editIndex ] . blur ( ) ;
115
114
setFocusedIndex ( undefined ) ;
116
115
props . onFulfill ( props . value ) ;
117
116
@@ -126,10 +125,10 @@ function MagicCodeInput(props) {
126
125
127
126
let focusTimeout = null ;
128
127
if ( props . shouldDelayFocus ) {
129
- focusTimeout = setTimeout ( ( ) => inputRefs [ 0 ] . focus ( ) , CONST . ANIMATED_TRANSITION ) ;
128
+ focusTimeout = setTimeout ( ( ) => inputRefs . current [ 0 ] . focus ( ) , CONST . ANIMATED_TRANSITION ) ;
130
129
}
131
130
132
- inputRefs [ 0 ] . focus ( ) ;
131
+ inputRefs . current [ 0 ] . focus ( ) ;
133
132
134
133
return ( ) => {
135
134
if ( ! focusTimeout ) {
@@ -249,20 +248,20 @@ function MagicCodeInput(props) {
249
248
props . onChangeText ( composeToString ( numbers ) ) ;
250
249
251
250
if ( ! _ . isUndefined ( newFocusedIndex ) ) {
252
- inputRefs [ newFocusedIndex ] . focus ( ) ;
251
+ inputRefs . current [ newFocusedIndex ] . focus ( ) ;
253
252
}
254
253
} if ( keyValue === 'ArrowLeft' && ! _ . isUndefined ( focusedIndex ) ) {
255
254
const newFocusedIndex = Math . max ( 0 , focusedIndex - 1 ) ;
256
255
setInput ( '' ) ;
257
256
setFocusedIndex ( newFocusedIndex ) ;
258
257
setEditIndex ( newFocusedIndex ) ;
259
- inputRefs [ newFocusedIndex ] . focus ( ) ;
258
+ inputRefs . current [ newFocusedIndex ] . focus ( ) ;
260
259
} else if ( keyValue === 'ArrowRight' && ! _ . isUndefined ( focusedIndex ) ) {
261
260
const newFocusedIndex = Math . min ( focusedIndex + 1 , CONST . MAGIC_CODE_LENGTH - 1 ) ;
262
261
setInput ( '' ) ;
263
262
setFocusedIndex ( newFocusedIndex ) ;
264
263
setEditIndex ( newFocusedIndex ) ;
265
- inputRefs [ newFocusedIndex ] . focus ( ) ;
264
+ inputRefs . current [ newFocusedIndex ] . focus ( ) ;
266
265
} else if ( keyValue === 'Enter' ) {
267
266
setInput ( '' ) ;
268
267
props . onFulfill ( props . value ) ;
@@ -286,7 +285,7 @@ function MagicCodeInput(props) {
286
285
</ View >
287
286
< View style = { [ StyleSheet . absoluteFillObject , styles . w100 , styles . opacity0 ] } >
288
287
< TextInput
289
- ref = { ref => inputRefs [ index ] = ref }
288
+ ref = { ref => inputRefs . current [ index ] = ref }
290
289
autoFocus = { index === 0 && props . autoFocus }
291
290
inputMode = "numeric"
292
291
textContentType = "oneTimeCode"
0 commit comments