-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeScreen.js
146 lines (132 loc) · 3.69 KB
/
HomeScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React from 'react';
import { StyleSheet, ListView, AlertIOS, ListViewDataSource, Navigator } from 'react-native';
import { Container, Button, Text, Header, Left, Right, Icon, Body, Title, Fab, View} from 'native-base';
import { firebaseAPP } from "./App.js";
const StatusBar = require('./components/StatusBar');
const ActionButton = require('./components/ActionButton');
const ListItem = require('./components/ListItem');
const Roboto = require('native-base/Fonts/Roboto.ttf');
const Roboto_medium = require('native-base/Fonts/Roboto_medium.ttf');
var styles = StyleSheet.create()
export default class HomeScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
active: false
};
this.itemsRef = this.getRef().child('items');
console.log("hello")
console.log(this.state.active)
}
getRef() {
return firebaseAPP.database().ref();
}
listenForItems(itemsRef) {
itemsRef.on('value', (snap) => {
// get children as an array
var items = [];
snap.forEach((child) => {
items.push({
title: child.val().title,
_key: child.key
});
});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(items)
});
});
}
componentDidMount() {
this.listenForItems(this.itemsRef);
}
render() {
return (
<Container>
<Header iosBarStyle="dark-content">
<Left>
<Button transparent onPress={() => this.props.navigation.navigate("DrawerOpen")}>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>Balance</Title>
</Body>
<Right/>
</Header>
<View style={{ flex: 1 }}>
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderItem.bind(this)}
enableEmptySections={true}
style={styles.listview}/>
<Fab active={this.state.active}
direction="up"
containerStyle={{ }}
style={{ backgroundColor: '#5067FF' }}
position="bottomRight"
onPress={() => this.setState({ active: !this.state.active })}>
<Icon name="md-add" />
<Button style={ { backgroundColor: '#34A34F' } } onPress={this._addItem.bind(this)}>
<Icon name="md-add-circle" />
</Button>
<Button style={ { backgroundColor: 'red' } } onPress={this._goToInput.bind(this)}>
<Icon name="md-remove-circle" />
</Button>
</Fab>
</View>
</Container>
)
}
_addItem() {
console.log('add')
AlertIOS.prompt(
'Add New Item',
null,
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{
text: 'Add',
onPress: (text) => {
this.itemsRef.push({
title: text,
bla: "bla"
})
}
},
],
'plain-text'
);
}
_renderItem(item) {
const onPress = () => {
AlertIOS.alert(
'Complete',
null,
[
{
text: 'Complete',
onPress: (text) => this.itemsRef.child(item._key).remove()
},
{
text: 'Cancel',
onPress: (text) => console.log('Cancelled')
}
]
);
};
return (
<ListItem item={ item } onPress={ onPress } />
);
}
// Go to the input page
_goToInput() {
this.props.navigation.navigate("Input")
}
}