-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
87 lines (80 loc) · 1.84 KB
/
App.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
import React from 'react';
import Chat from "./Chat";
import {StyleSheet, Text, TextInput, TouchableOpacity, View} from "react-native";
import Fire from "./Fire";
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
user: {
_id: "",
username: "",
},
hasUsername: false,
};
}
componentDidMount() {
const user = Fire.shared.user;
const hasUsername = user.username != null;
this.setState(() => ({
user: {
_id: user.uid,
username: user.username,
},
hasUsername: hasUsername,
}));
console.log('uid = ' + Fire.shared.uid)
console.log(this.state)
}
componentWillUnmount() {
Fire.shared.off();
}
onChangeText = username => this.setState({
user: {username: username}
});
onPress = () => {
Fire.shared.setUser(this.state.user);
this.setState({hasUsername: true});
};
render() {
if (this.state.hasUsername) {
return (
<Chat user={this.state.user}/>
)
} else {
return (
<View>
<Text style={styles.title}>Enter your name:</Text>
<TextInput
style={styles.nameInput}
placeHolder="John Cena"
onChangeText={this.onChangeText}
value={this.state.username}
/>
<TouchableOpacity onPress={this.onPress}>
<Text style={styles.buttonText}>Next</Text>
</TouchableOpacity>
</View>
)
}
}
}
const offset = 24;
const styles = StyleSheet.create({
nameInput: {
height: offset * 2,
margin: offset,
paddingHorizontal: offset,
borderColor: '#111111',
borderWidth: 1,
},
title: {
marginTop: offset,
marginLeft: offset,
fontSize: offset,
},
buttonText: {
marginLeft: offset,
fontSize: offset,
},
});