Created
December 2, 2016 08:27
-
-
Save hijamoya/9716bd0a16516d6760ae6c666c9ccbd7 to your computer and use it in GitHub Desktop.
Poor rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
Image, | |
Text, | |
ListView, | |
Navigator, | |
View | |
} from 'react-native'; | |
class HomePage extends Component | |
{ | |
// Initialize the hardcoded data | |
constructor(props) { | |
super(props); | |
var data = ['begin']; | |
for (i = 0; i < 1000; i++) { | |
data.push(Math.random().toString(36).substring(7)) | |
} | |
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | |
this.state = { | |
dataSource: ds.cloneWithRows(data) | |
}; | |
} | |
render() { | |
return ( | |
<Navigator | |
renderScene={this.renderScene.bind(this)} | |
navigationBar={ | |
<Navigator.NavigationBar style={{backgroundColor: '#000000', alignItems: 'center'}} | |
routeMapper={NavigationBarRouteMapper} /> | |
} /> | |
); | |
} | |
renderScene(route, navigator) { | |
return ( | |
<View style={{paddingTop: 22,flex:1}}> | |
<ListView | |
dataSource={this.state.dataSource} | |
renderRow={this.renderRow.bind(this)} | |
renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator}/>} | |
/> | |
</View> | |
); | |
} | |
renderRow(rowData, sectionID, rowID, highlightRow: (sectionID: number, rowID: number) => void){ | |
var rowHash = Math.abs(hashCode(rowData)); | |
var imgSource = THUMB_URLS[rowHash % THUMB_URLS.length]; | |
return ( | |
<View> | |
<Image source={imgSource} /> | |
<Text>{rowData}</Text> | |
</View> | |
) | |
} | |
var THUMB_URLS = [ | |
require('./Thumbnails/like.png'), | |
require('./Thumbnails/dislike.png'), | |
require('./Thumbnails/call.png'), | |
require('./Thumbnails/fist.png'), | |
require('./Thumbnails/bandaged.png'), | |
require('./Thumbnails/flowers.png'), | |
require('./Thumbnails/heart.png'), | |
require('./Thumbnails/liking.png'), | |
require('./Thumbnails/party.png'), | |
require('./Thumbnails/poke.png'), | |
require('./Thumbnails/superlike.png'), | |
require('./Thumbnails/victory.png'), | |
]; | |
module.exports = HomePage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment