Created
June 12, 2016 00:39
-
-
Save talkol/d9372caaad8a951106dadb4f9d108524 to your computer and use it in GitHub Desktop.
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
| import React, { Component } from 'react'; | |
| import { requireNativeComponent, View } from 'react-native'; | |
| import ReboundRenderer from './ReboundRenderer'; | |
| const RNTableViewChildren = requireNativeComponent('RNTableViewChildren', null); | |
| const ROWS_FOR_RECYCLING = 20; | |
| export default class RecyclingListView extends Component { | |
| constructor(props) { | |
| super(props); | |
| const binding = []; | |
| for (let i=0; i<ROWS_FOR_RECYCLING; i++) binding.push(-1); | |
| this.state = { | |
| binding: binding // childIndex -> rowID | |
| }; | |
| } | |
| render() { | |
| const bodyComponents = []; | |
| for (let i=0; i<ROWS_FOR_RECYCLING; i++) { | |
| bodyComponents.push( | |
| <ReboundRenderer | |
| key={'r_' + i} | |
| boundTo={this.state.binding[i]} | |
| render={this.props.renderRow} | |
| /> | |
| ); | |
| } | |
| return ( | |
| <View style={{flex: 1}}> | |
| <RNTableView | |
| style={{flex: 1}} | |
| onChange={this.onBind.bind(this)} | |
| rowHeight={this.props.rowHeight} | |
| numRows={this.props.numRows} | |
| > | |
| {bodyComponents} | |
| </RNTableView> | |
| </View> | |
| ); | |
| } | |
| onBind(event) { | |
| const {target, childIndex, rowID, sectionID} = event.nativeEvent; | |
| this.state.binding[childIndex] = rowID; | |
| this.setState({ | |
| binding: this.state.binding | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment