Created
June 4, 2017 19:14
-
-
Save hgale/5fbf1ad9da85906c784a461b9af516ed 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 { | |
| View, | |
| Text, | |
| ListView, | |
| TouchableHighlight, | |
| } from 'react-native' | |
| import Exercise from '../exercise' | |
| import Exercises from './exercises' | |
| import style from './style' | |
| const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) | |
| export default class Workout extends Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| dataSource: ds.cloneWithRows(Exercises), | |
| selectedExercise: null, | |
| } | |
| } | |
| onPressRow(rowData) { | |
| console.log('This exercise was selected ', rowData.title); | |
| this.setState({selectedExercise: rowData}) | |
| } | |
| renderRow(rowData, sectionID, rowID) { | |
| return ( | |
| <TouchableHighlight onPress={this.onPressRow.bind(this, rowData)}> | |
| <View style={style.listItemContainer}> | |
| <Text style={style.listItem}>{rowData.title}</Text> | |
| </View> | |
| </TouchableHighlight> | |
| ) | |
| } | |
| render() { | |
| const { selectedExercise } = this.state | |
| return ( | |
| <View style={style.container}> | |
| { selectedExercise ? | |
| <Exercise | |
| title={selectedExercise.title} | |
| close={ () => {this.setState({selectedExercise: null})} }/> | |
| : null | |
| } | |
| <ListView | |
| style={style.list} | |
| initialListSize={1} | |
| removeClippedSubviews={false} | |
| enableEmptySections={true} | |
| dataSource={this.state.dataSource} | |
| renderRow={this.renderRow.bind(this)} | |
| /> | |
| </View> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment