-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
45 lines (35 loc) · 1.2 KB
/
App.js
File metadata and controls
45 lines (35 loc) · 1.2 KB
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
import React from 'react';
import { StyleSheet, Text, View, AsyncStorage } from 'react-native';
import EnterNickname from "./src/components/EnterNickname/EnterNickname";
import ChatContainer from "./src/components/Chat/ChatContainer";
const LOGIN_SCREEN = 1;
const CHAT_SCREEN = 2;
//import Coder from './src/utils/Coder';
export default class App extends React.Component {
state = {
screen: LOGIN_SCREEN,
nickname: ''
};
async componentWillMount(){
const nickname = await AsyncStorage.getItem('nickname');
if(nickname) this.login(nickname);
}
login = nickname => {
this.setState({screen: CHAT_SCREEN, nickname});
AsyncStorage.setItem('nickname', nickname);
};
logout = () => {
this.setState({screen: LOGIN_SCREEN, nickname: ''});
AsyncStorage.removeItem('nickname');
AsyncStorage.removeItem('messages');
};
render() {
const {screen} = this.state;
if(screen === LOGIN_SCREEN) return (
<EnterNickname onSubmit={this.login} />
);
if(screen === CHAT_SCREEN) return (
<ChatContainer logout={this.logout} nickname={this.state.nickname}/>
);
}
}