@@ -18,13 +18,13 @@ import {
18
18
Keyboard ,
19
19
KeyboardEvent ,
20
20
Modal ,
21
+ StatusBar ,
21
22
StyleSheet ,
22
23
Text ,
23
24
TouchableHighlight ,
24
25
TouchableWithoutFeedback ,
25
26
View ,
26
27
ViewStyle ,
27
- StatusBar ,
28
28
} from 'react-native' ;
29
29
import { useDetectDevice } from '../../toolkits' ;
30
30
import { useDeviceOrientation } from '../../useDeviceOrientation' ;
@@ -265,24 +265,31 @@ const DropdownComponent: <T>(
265
265
} , [ value , data , getValue ] ) ;
266
266
267
267
const scrollIndex = useCallback ( ( ) => {
268
- if ( autoScroll && data . length > 0 && listData . length === data . length ) {
268
+ if ( autoScroll && data . length > 0 && listData ? .length === data ? .length ) {
269
269
setTimeout ( ( ) => {
270
270
if ( refList && refList ?. current ) {
271
271
const defaultValue =
272
272
typeof value === 'object' ? _ . get ( value , valueField ) : value ;
273
273
274
- const index = _ . findIndex ( listData , ( e : any ) =>
274
+ const index = _ . findIndex ( listData , ( e ) =>
275
275
_ . isEqual ( defaultValue , _ . get ( e , valueField ) )
276
276
) ;
277
- if (
278
- listData . length > 0 &&
279
- index > - 1 &&
280
- index <= listData . length - 1
281
- ) {
282
- refList ?. current ?. scrollToIndex ( {
283
- index : index ,
284
- animated : false ,
285
- } ) ;
277
+
278
+ if ( index > - 1 && index < listData . length ) {
279
+ try {
280
+ refList . current . scrollToIndex ( {
281
+ index : index ,
282
+ animated : false ,
283
+ } ) ;
284
+ } catch ( error ) {
285
+ console . warn ( `scrollToIndex error: ${ error } ` ) ;
286
+ }
287
+ } else {
288
+ console . warn (
289
+ `scrollToIndex out of range: requested index ${ index } is out of 0 to ${
290
+ listData . length - 1
291
+ } `
292
+ ) ;
286
293
}
287
294
}
288
295
} , 200 ) ;
0 commit comments