This repository was archived by the owner on Mar 30, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +66
-12
lines changed
Expand file tree Collapse file tree 2 files changed +66
-12
lines changed Original file line number Diff line number Diff line change @@ -96,10 +96,52 @@ import SocialIcon from 'HSSocialIcon'
9696import List from 'HSList'
9797import ListItem from 'HSListItem'
9898
99- // Can also replace map function with RN ListView implementation
99+
100+ ```
101+
102+ <List >
103+ {
104+ list1.map((l, i) => (
105+ <ListItem
106+ key={i}
107+ onPress={log}
108+ title={l.title}
109+ icon={{name: l.icon}}
110+ />
111+ ))
112+ }
113+ </List >
114+
115+ ```
116+
117+
118+ // With RN ListView implementation
119+
120+ renderRow (rowData, sectionID) {
121+ return (
122+ <ListItem
123+ key={sectionID}
124+ onPress={log}
125+ title={rowData.title}
126+ icon={{name: rowData.icon}}
127+ />
128+ )
129+ }
130+
131+ render () {
132+ return (
133+ <List>
134+ <ListView
135+ renderRow={this.renderRow}
136+ dataSource={this.state.dataSource}
137+ />
138+ </List>
139+ )
140+ }
141+
100142<List>
101143 {
102- list2 .map((l, i) => (
144+ list .map((l, i) => (
103145 <ListItem
104146 roundAvatar
105147 avatar={l.avatar_url}
Original file line number Diff line number Diff line change 11import React , { Component } from 'react'
2- import { View , StyleSheet , ScrollView } from 'react-native'
2+ import { View , StyleSheet , ScrollView , ListView } from 'react-native'
33import Text from 'HSText'
44import Icon from 'react-native-vector-icons/MaterialIcons'
55import ListItem from 'HSListItem'
@@ -60,6 +60,24 @@ const list2 = [
6060]
6161
6262class More extends Component {
63+ constructor ( ) {
64+ super ( )
65+ const ds = new ListView . DataSource ( { rowHasChanged : ( r1 , r2 ) => r1 !== r2 } )
66+ this . state = {
67+ dataSource : ds . cloneWithRows ( list1 )
68+ }
69+ this . renderRow = this . renderRow . bind ( this )
70+ }
71+ renderRow ( rowData , sectionID ) {
72+ return (
73+ < ListItem
74+ key = { sectionID }
75+ onPress = { log }
76+ title = { rowData . title }
77+ icon = { { name : rowData . icon } }
78+ />
79+ )
80+ }
6381 render ( ) {
6482 return (
6583 < ScrollView style = { styles . mainContainer } >
@@ -68,16 +86,10 @@ class More extends Component {
6886 < Text style = { styles . heading } > List</ Text >
6987 </ View >
7088 < List >
71- {
72- list1 . map ( ( l , i ) => (
73- < ListItem
74- key = { i }
75- onPress = { log }
76- title = { l . title }
77- icon = { { name : l . icon } }
89+ < ListView
90+ renderRow = { this . renderRow }
91+ dataSource = { this . state . dataSource }
7892 />
79- ) )
80- }
8193 </ List >
8294 < List containerStyle = { { marginBottom : 20 } } >
8395 {
You can’t perform that action at this time.
0 commit comments