Last active
September 12, 2016 06:46
-
-
Save Chris-Petty/afe23abda4103431a3b0a285046500d6 to your computer and use it in GitHub Desktop.
Showing refs in renderRow.
This file contains hidden or 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
var React = require('react-native'); | |
var { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
ListView, | |
TouchableOpacity | |
} = React; | |
// This example itself probably wont run, but the idea is there. Not actually doing anything with the ref though... | |
export class ReffyListView extends React.Component { | |
constructor(props){ | |
super(props) | |
var data = {{'row 1', 'row 2', 'row 3'}} | |
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) | |
this.state = { | |
dataSource: ds.cloneWithRows(data), | |
} | |
this.refsMap = {}; // { rowId: reference, rowId: reference, ...} | |
} | |
renderRow(rowData, sectionId, rowId) { | |
<TouchableOpacity | |
ref={(reference) => { this.refsMap[rowId] = reference; }} | |
onPress={() => {}} // Some function that actually does something with the refs would be fun. | |
> | |
<Text>{rowData}</Text> | |
</TouchableOpacity> | |
} | |
render() { | |
return ( | |
<ListView | |
dataSource={this.state.dataSource} | |
renderRow={ this.renderRow } | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment