Skip to content

Instantly share code, notes, and snippets.

@Chris-Petty
Last active September 12, 2016 06:46
Show Gist options
  • Save Chris-Petty/afe23abda4103431a3b0a285046500d6 to your computer and use it in GitHub Desktop.
Save Chris-Petty/afe23abda4103431a3b0a285046500d6 to your computer and use it in GitHub Desktop.
Showing refs in renderRow.
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