-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp1.js
156 lines (142 loc) · 3.61 KB
/
App1.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
147
148
149
150
151
152
153
154
155
156
import React from 'react';
import { ActivityIndicator, StyleSheet, Text, View, Image } from 'react-native';
import * as firebase from 'firebase';
import { Input } from './components/Input';
import { Button } from './components/Button';
import { HomeScreen } from './screens/HomeScreen'
const remoteBg = 'https://chaos-dev.yuelaobank.com/src/img_banner/p_sign.png';
const remoteBgIndex = 'https://chaos-dev.yuelaobank.com/src/img_banner/background.jpg'
export default class App extends React.Component {
state = {
email: '',
password: '',
authenticating: false,
user: null,
error: '',
}
componentWillMount() {
const firebaseConfig = {
apiKey: 'AIzaSyDluZRqZwmKvqtlKkcwBdhUwzMFFNo5lkE',
authDomain: 'react-native-project-5d00f.firebaseapp.com',
}
firebase.initializeApp(firebaseConfig);
}
onPressSignIn() {
this.setState({
authenticating: true,
});
const { email, password } = this.state;
firebase.auth().signInWithEmailAndPassword(email, password)
.then(user => this.setState({
authenticating: false,
user,
error: '',
}))
.catch(() => {
// Login was not successful
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(user => this.setState({
authenticating: false,
user,
error: '',
}))
.catch(() => this.setState({
authenticating: false,
user: null,
error: 'Authentication Failure',
}))
})
}
onPressLogOut() {
firebase.auth().signOut()
.then(() => {
this.setState({
email: '',
password: '',
authenticating: false,
user: null,
})
}, error => {
console.error('Sign Out Error', error);
});
}
renderCurrentState() {
if (this.state.authenticating) {
return (
<View style={styles.form}>
<ActivityIndicator size='large' />
</View>
)
}
if (this.state.user !== null) {
return (
<View style={styles.form}>
<Text>Logged In</Text>
<Button onPress={() => this.onPressLogOut()}>Log Out</Button>
<HomeScreen></HomeScreen>
</View>
)
}
return (
<Image
style={styles.bgimg}
source={{ uri: remoteBg }}
>
<View style={styles.form}>
<Input
placeholder='Enter your email...'
label='Email'
onChangeText={email => this.setState({ email })}
value={this.state.email}
/>
<Input
placeholder='Enter your password...'
label='Password'
secureTextEntry
onChangeText={password => this.setState({ password })}
value={this.state.password}
/>
<Button onPress={() => this.onPressSignIn()}>開始幸福</Button>
<Text>{this.state.error}</Text>
</View>
</Image>
)
}
render() {
return (
<Image
style={styles.bgindex}
source={{ uri: remoteBgIndex }}
>
<View style={styles.container}>
{this.renderCurrentState()}
</View>
</Image>
);
}
}
const styles = StyleSheet.create({
bgindex: {
flex: 1,
},
bgimg: {
flex: 1,
width: null,
height: null,
paddingTop: 110,
resizeMode: 'cover',
justifyContent: 'center',
resizeMode: 'contain'
},
container: {
flex: 1,
padding: 0,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row'
},
form: {
flex: 1,
padding: 50
}
});