1
1
import React , { Component } from 'react' ;
2
- import { View , Text , StyleSheet , ListView } from 'react-native' ;
2
+ import { View , Text , StyleSheet , ListView , FlatList } from 'react-native' ;
3
3
import StepIndicator from 'react-native-step-indicator' ;
4
4
import dummyData from './data' ;
5
5
@@ -29,11 +29,10 @@ export default class VerticalStepIndicator extends Component {
29
29
constructor ( ) {
30
30
super ( ) ;
31
31
32
- const ds = new ListView . DataSource ( { rowHasChanged : ( r1 , r2 ) => r1 !== r2 } ) ;
33
32
this . state = {
34
- dataSource : ds . cloneWithRows ( dummyData . data ) ,
35
33
currentPage :0
36
34
} ;
35
+ this . viewabilityConfig = { itemVisiblePercentThreshold : 40 }
37
36
}
38
37
39
38
render ( ) {
@@ -48,27 +47,32 @@ export default class VerticalStepIndicator extends Component {
48
47
labels = { dummyData . data . map ( item => item . title ) }
49
48
/>
50
49
</ View >
51
- < ListView
52
- dataSource = { this . state . dataSource }
53
- renderRow = { this . renderPage }
54
- onChangeVisibleRows = { this . getVisibleRows }
55
- />
50
+ < FlatList
51
+ style = { { flexGrow :1 } }
52
+ data = { dummyData . data }
53
+ renderItem = { this . renderPage }
54
+ onViewableItemsChanged = { this . onViewableItemsChanged }
55
+ viewabilityConfig = { this . viewabilityConfig }
56
+ />
56
57
</ View >
57
58
) ;
58
59
}
59
60
60
61
renderPage = ( rowData ) => {
62
+ const item = rowData . item
61
63
return (
62
64
< View style = { styles . rowItem } >
63
- < Text style = { styles . title } > { rowData . title } </ Text >
64
- < Text style = { styles . body } > { rowData . body } </ Text >
65
+ < Text style = { styles . title } > { item . title } </ Text >
66
+ < Text style = { styles . body } > { item . body } </ Text >
65
67
</ View >
66
68
)
67
69
}
68
70
69
- getVisibleRows = ( visibleRows ) => {
70
- const visibleRowNumbers = Object . keys ( visibleRows . s1 ) . map ( ( row ) => parseInt ( row ) ) ;
71
- this . setState ( { currentPage :visibleRowNumbers [ 0 ] } )
71
+ onViewableItemsChanged = ( { viewableItems, changed } ) => {
72
+ const visibleItemsCount = viewableItems . length ;
73
+ if ( visibleItemsCount != 0 ) {
74
+ this . setState ( { currentPage :viewableItems [ visibleItemsCount - 1 ] . index } )
75
+ } ;
72
76
}
73
77
}
74
78
0 commit comments