11import React , { Component , PropTypes } from 'react' ;
2- import { SectionList , View , Text , TouchableOpacity } from 'react-native' ;
2+ import { ListView , View , Text , TouchableOpacity } from 'react-native' ;
33import style from './style' ;
44
55const SectionHeader = ( { title, selected } ) =>
@@ -30,8 +30,14 @@ ListItem.propTypes = {
3030export default class StoryListView extends Component {
3131 constructor ( props , ...args ) {
3232 super ( props , ...args ) ;
33+
34+ const ds = new ListView . DataSource ( {
35+ rowHasChanged : ( r1 , r2 ) => r1 !== r2 ,
36+ sectionHeaderHasChanged : ( s1 , s2 ) => s1 !== s2 ,
37+ } ) ;
38+
3339 this . state = {
34- sections : [ ] ,
40+ dataSource : ds . cloneWithRowsAndSections ( { } ) ,
3541 } ;
3642
3743 this . storyAddedHandler = this . handleStoryAdded . bind ( this ) ;
@@ -56,16 +62,20 @@ export default class StoryListView extends Component {
5662 handleStoryAdded ( ) {
5763 if ( this . props . stories ) {
5864 const data = this . props . stories . dumpStoryBook ( ) ;
59- this . setState ( {
60- sections : data . map ( section => ( {
61- key : section . kind ,
62- title : section . kind ,
63- data : section . stories . map ( story => ( {
65+
66+ const sections = data . reduce (
67+ ( map , section ) => ( {
68+ ... map ,
69+ [ section . kind ] : section . stories . map ( story => ( {
6470 key : story ,
65- kind : section . kind ,
6671 name : story ,
72+ kind : section . kind ,
6773 } ) ) ,
68- } ) ) ,
74+ } ) ,
75+ { }
76+ ) ;
77+ this . setState ( {
78+ dataSource : this . state . dataSource . cloneWithRowsAndSections ( sections ) ,
6979 } ) ;
7080 }
7181 }
@@ -76,22 +86,19 @@ export default class StoryListView extends Component {
7686
7787 render ( ) {
7888 return (
79- < SectionList
89+ < ListView
8090 style = { style . list }
81- renderItem = { ( { item } ) =>
91+ renderRow = { item =>
8292 < ListItem
8393 title = { item . name }
8494 selected = {
8595 item . kind === this . props . selectedKind && item . name === this . props . selectedStory
8696 }
8797 onPress = { ( ) => this . changeStory ( item . kind , item . name ) }
8898 /> }
89- renderSectionHeader = { ( { section } ) =>
90- < SectionHeader
91- title = { section . title }
92- selected = { section . title === this . props . selectedKind }
93- /> }
94- sections = { this . state . sections }
99+ renderSectionHeader = { ( sectionData , sectionName ) =>
100+ < SectionHeader title = { sectionName } selected = { sectionName === this . props . selectedKind } /> }
101+ dataSource = { this . state . dataSource }
95102 stickySectionHeadersEnabled = { false }
96103 />
97104 ) ;
0 commit comments