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';
|
|
|
|
|
2016-05-16 20:21:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import {
|
2016-02-15 23:03:16 +00:00
|
|
|
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
|
|
|
}
|