2015-10-27 23:19:30 +00:00
|
|
|
/* Copyright 2015 Realm Inc - All Rights Reserved
|
|
|
|
* Proprietary and Confidential
|
|
|
|
*/
|
|
|
|
|
2015-10-07 23:20:05 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-15 23:03:16 +00:00
|
|
|
import React, {
|
|
|
|
Text,
|
|
|
|
TouchableWithoutFeedback,
|
|
|
|
View,
|
|
|
|
} from 'react-native';
|
2015-10-07 23:20:05 +00:00
|
|
|
|
2016-02-15 23:03:16 +00:00
|
|
|
import TodoListItem from './todo-list-item';
|
|
|
|
import realm from './realm';
|
|
|
|
import styles from './styles';
|
2015-10-07 23:20:05 +00:00
|
|
|
|
2016-02-15 23:03:16 +00:00
|
|
|
export default class TodoItem extends TodoListItem {
|
2015-10-07 23:20:05 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2015-10-26 19:10:40 +00:00
|
|
|
this._onPressCheckbox = this._onPressCheckbox.bind(this);
|
2015-10-07 23:20:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
get done() {
|
|
|
|
return this.props.item.done;
|
2015-10-07 23:20:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
set done(done) {
|
|
|
|
this.props.item.done = done;
|
2015-10-07 23:20:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
get text() {
|
|
|
|
return this.props.item.text;
|
|
|
|
}
|
2015-10-27 00:13:33 +00:00
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
set text(text) {
|
|
|
|
this.props.item.text = text;
|
|
|
|
}
|
2015-10-07 23:20:05 +00:00
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
renderLeftSide() {
|
2015-10-07 23:20:05 +00:00
|
|
|
return (
|
2015-10-27 08:52:26 +00:00
|
|
|
<TouchableWithoutFeedback onPress={this._onPressCheckbox}>
|
|
|
|
<View style={styles.listItemLeftSide}>
|
2016-01-19 23:10:06 +00:00
|
|
|
<View style={styles.listItemCheckbox}>
|
|
|
|
<Text style={styles.listItemCheckboxText}>
|
|
|
|
{this.done ? '✓' : ''}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-10-27 08:52:26 +00:00
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
2015-10-07 23:20:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-26 19:10:40 +00:00
|
|
|
_onPressCheckbox() {
|
|
|
|
realm.write(() => {
|
2015-10-27 08:52:26 +00:00
|
|
|
this.done = !this.done;
|
2015-10-26 19:10:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
2015-10-07 23:20:05 +00:00
|
|
|
}
|