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

76 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-02-18 19:59:34 +00:00
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
2015-10-27 23:19:30 +00:00
2015-10-07 23:20:05 +00:00
'use strict';
import React, {
Text,
TouchableWithoutFeedback,
View,
} from 'react-native';
2015-10-07 23:20:05 +00:00
import TodoListItem from './todo-list-item';
import realm from './realm';
import styles from './styles';
2015-10-07 23:20:05 +00:00
export default 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
}