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';
|
|
|
|
|
|
|
|
const React = require('react-native');
|
2015-10-27 08:52:26 +00:00
|
|
|
const TodoListItem = require('./todo-list-item');
|
2015-10-07 23:20:05 +00:00
|
|
|
const realm = require('./realm');
|
|
|
|
const styles = require('./styles');
|
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
const { Text, TouchableWithoutFeedback, View } = React;
|
2015-10-07 23:20:05 +00:00
|
|
|
|
2015-10-27 08:52:26 +00:00
|
|
|
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}>
|
2015-10-27 21:23:17 +00:00
|
|
|
<Text style={styles.listItemCheckbox}>
|
|
|
|
{this.done ? '✓' : ''}
|
|
|
|
</Text>
|
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
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = TodoItem;
|