/** * Created by huyanh on 2017. 2. 9.. */ import React, {Component} from 'react'; import {View, Text, StyleSheet, TouchableOpacity, TextInput} from 'react-native'; type Props = { onToggleEdit: (boolean) => void, title: string, onUpdate: () => void, amount: number, onRemove: () => void, } class Row extends Component { props: Props; render() { // this.props.text comes from spread operator in renderRow const textTitleComponent = ( this.props.onToggleEdit(true)}> {this.props.title} ); const editingTitleComponent = ( ); const textAmountComponent = ( this.props.onToggleEdit(true)}> {this.props.amount} ); const editingAmountComponent = ( ); const doneButton = ( this.props.onToggleEdit(false)}> Save ); const removeButton = ( X ); return ( {this.props.editing ? editingTitleComponent : textTitleComponent} {this.props.editing ? editingAmountComponent : textAmountComponent} {this.props.editing ? doneButton : removeButton } ); } } const styles = StyleSheet.create({ container: { padding: 10, flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'space-between', }, input: { height: 100, flex: 1, fontSize: 24, padding: 0, color: '#4d4d4d', }, textWrap: { flex: 1, marginHorizontal: 10, }, done: { borderRadius: 5, borderWidth: 1, borderColor: '#7be290', padding: 7, }, doneText: { color: '#4d4d4d', fontSize: 20, }, text: { flex: 1, fontSize: 24, color: '#141414', }, destroy: { fontSize: 20, color: '#cc9a9a', }, }); export default Row;