realm-js/examples/ReactExample/components/todo-item.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

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');
const TodoListItem = require('./todo-list-item');
2015-10-07 23:20:05 +00:00
const realm = require('./realm');
const styles = require('./styles');
const { Text, TouchableWithoutFeedback, View } = React;
2015-10-07 23:20:05 +00:00
class TodoItem extends TodoListItem {
2015-10-07 23:20:05 +00:00
constructor(props) {
super(props);
this._onPressCheckbox = this._onPressCheckbox.bind(this);
2015-10-07 23:20:05 +00:00
}
get done() {
return this.props.item.done;
2015-10-07 23:20:05 +00:00
}
set done(done) {
this.props.item.done = done;
2015-10-07 23:20:05 +00:00
}
get text() {
return this.props.item.text;
}
set text(text) {
this.props.item.text = text;
}
2015-10-07 23:20:05 +00:00
renderLeftSide() {
2015-10-07 23:20:05 +00:00
return (
<TouchableWithoutFeedback onPress={this._onPressCheckbox}>
<View style={styles.listItemLeftSide}>
<View style={styles.listItemCheckbox}>
<Text style={styles.listItemCheckboxText}>
{this.done ? '✓' : ''}
</Text>
</View>
</View>
</TouchableWithoutFeedback>
2015-10-07 23:20:05 +00:00
);
}
_onPressCheckbox() {
realm.write(() => {
this.done = !this.done;
});
this.forceUpdate();
}
2015-10-07 23:20:05 +00:00
}
module.exports = TodoItem;