Created
June 8, 2016 16:04
-
-
Save callmephilip/c2c33546c6b2331272954b45110ff4d8 to your computer and use it in GitHub Desktop.
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 { View, Text, TouchableOpacity, Image } from 'react-native'; | |
import React, { Component, PropTypes } from 'react'; | |
import styles from './styles'; | |
import Swipeout from 'react-native-swipeout'; | |
class TodoItem extends Component { | |
render() { | |
const swipeoutBtns = [{ | |
text: 'Delete', | |
backgroundColor: 'red', | |
onPress: () => { | |
this.props.onDelete(this.props.todo.id); | |
} | |
}]; | |
const viewCompletedStyling = this.props.todo.isComplete ? { opacity: 0.5 } : {}; | |
const labelCompletedStyling = this.props.todo.isComplete ? { textDecorationLine: 'line-through' } : {}; | |
return ( | |
<Swipeout right={swipeoutBtns} backgroundColor={'transparent'}> | |
<TouchableOpacity | |
underlayColor="transparent" | |
onPress={ () => this.props.onToggleCompletion(this.props.todo.id) }> | |
<View style={[styles.item, viewCompletedStyling]}> | |
{this._renderCheckbox()} | |
<View style={styles.labelWrapper}> | |
<Text style={[styles.label, labelCompletedStyling]}>{this.props.todo.text}</Text> | |
</View> | |
</View> | |
</TouchableOpacity> | |
</Swipeout> | |
); | |
} | |
_renderCheckbox() { | |
const imageModule = this.props.todo.isComplete ? | |
require('./images/checked.png') : | |
require('./images/unchecked.png'); | |
return ( | |
<Image style={[styles.checkbox]} source={imageModule} /> | |
); | |
} | |
} | |
TodoItem.propTypes = { | |
todo: PropTypes.object.isRequired, | |
onToggleCompletion: PropTypes.func.isRequired, | |
onDelete: PropTypes.func.isRequired | |
}; | |
export default TodoItem; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment