@@ -3,7 +3,7 @@ import React, { PureComponent } from 'react';
3
3
import {
4
4
Text ,
5
5
View ,
6
- ScrollView ,
6
+ FlatList ,
7
7
Animated ,
8
8
Modal ,
9
9
TouchableWithoutFeedback ,
@@ -149,10 +149,15 @@ export default class Dropdown extends PureComponent {
149
149
this . onClose = this . onClose . bind ( this ) ;
150
150
this . onSelect = this . onSelect . bind ( this ) ;
151
151
this . onLayout = this . onLayout . bind ( this ) ;
152
+
152
153
this . updateRippleRef = this . updateRef . bind ( this , 'ripple' ) ;
153
154
this . updateContainerRef = this . updateRef . bind ( this , 'container' ) ;
154
155
this . updateScrollRef = this . updateRef . bind ( this , 'scroll' ) ;
156
+
155
157
this . renderAccessory = this . renderAccessory . bind ( this ) ;
158
+ this . renderItem = this . renderItem . bind ( this ) ;
159
+
160
+ this . keyExtractor = this . keyExtractor . bind ( this ) ;
156
161
157
162
this . blur = this . onClose ;
158
163
this . focus = this . onPress ;
@@ -306,7 +311,7 @@ export default class Dropdown extends PureComponent {
306
311
setTimeout ( ( ( ) => {
307
312
if ( this . mounted ) {
308
313
if ( this . scroll ) {
309
- this . scroll . scrollTo ( { x : 0 , y : offset , animated : false } ) ;
314
+ this . scroll . scrollToOffset ( { offset, animated : false } ) ;
310
315
}
311
316
312
317
Animated
@@ -426,6 +431,12 @@ export default class Dropdown extends PureComponent {
426
431
this [ name ] = ref ;
427
432
}
428
433
434
+ keyExtractor ( item , index ) {
435
+ let { valueExtractor } = this . props ;
436
+
437
+ return `${ index } -${ valueExtractor ( item , index ) } ` ;
438
+ }
439
+
429
440
renderBase ( props ) {
430
441
let { value } = this . state ;
431
442
let {
@@ -512,11 +523,10 @@ export default class Dropdown extends PureComponent {
512
523
) ;
513
524
}
514
525
515
- renderItems ( ) {
526
+ renderItem ( { item , index } ) {
516
527
let { selected, leftInset, rightInset } = this . state ;
517
528
518
529
let {
519
- data,
520
530
valueExtractor,
521
531
labelExtractor,
522
532
textColor,
@@ -544,35 +554,32 @@ export default class Dropdown extends PureComponent {
544
554
} ,
545
555
} ;
546
556
547
- return data
548
- . map ( ( item , index ) => {
549
- if ( null == item ) {
550
- return null ;
551
- }
557
+ if ( null == item ) {
558
+ return null ;
559
+ }
552
560
553
- let value = valueExtractor ( item , index ) ;
554
- let label = labelExtractor ( item , index ) ;
561
+ let value = valueExtractor ( item , index ) ;
562
+ let label = labelExtractor ( item , index ) ;
555
563
556
- let title = null == label ?
557
- value :
558
- label ;
564
+ let title = null == label ?
565
+ value :
566
+ label ;
559
567
560
- let color = ~ selected ?
561
- index === selected ?
562
- selectedItemColor :
563
- itemColor :
564
- selectedItemColor ;
568
+ let color = ~ selected ?
569
+ index === selected ?
570
+ selectedItemColor :
571
+ itemColor :
572
+ selectedItemColor ;
565
573
566
- let style = { color, fontSize } ;
574
+ let style = { color, fontSize } ;
567
575
568
- return (
569
- < DropdownItem index = { index } key = { index } { ...props } >
570
- < Text style = { [ styles . item , itemTextStyle , style ] } numberOfLines = { 1 } >
571
- { title }
572
- </ Text >
573
- </ DropdownItem >
574
- ) ;
575
- } ) ;
576
+ return (
577
+ < DropdownItem index = { index } { ...props } >
578
+ < Text style = { [ styles . item , itemTextStyle , style ] } numberOfLines = { 1 } >
579
+ { title }
580
+ </ Text >
581
+ </ DropdownItem >
582
+ ) ;
576
583
}
577
584
578
585
render ( ) {
@@ -687,14 +694,15 @@ export default class Dropdown extends PureComponent {
687
694
< Animated . View
688
695
style = { [ styles . picker , pickerStyle , pickerStyleOverrides ] }
689
696
>
690
- < ScrollView
697
+ < FlatList
691
698
ref = { this . updateScrollRef }
699
+ data = { data }
692
700
style = { styles . scroll }
701
+ renderItem = { this . renderItem }
702
+ keyExtractor = { this . keyExtractor }
693
703
scrollEnabled = { visibleItemCount < itemCount }
694
704
contentContainerStyle = { styles . scrollContainer }
695
- >
696
- { this . renderItems ( ) }
697
- </ ScrollView >
705
+ />
698
706
</ Animated . View >
699
707
</ View >
700
708
</ TouchableWithoutFeedback >
0 commit comments