-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
113 lines (104 loc) · 2.52 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
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Fragment, Component} from 'react';
import {
SafeAreaView,
StatusBar,
StyleSheet,
View,
Text,
ActivityIndicator,
} from 'react-native';
import {
LoginButton,
AccessToken,
GraphRequest,
GraphRequestManager,
} from 'react-native-fbsdk';
export default class App extends Component {
state = {
loading: false,
user: null,
};
getUserCallback = (error, result) => {
if (error) {
console.log('getUserError', error);
} else {
this.setState({user: result, loading: false});
}
};
getUserInfo = token => {
const infoRequest = new GraphRequest(
'/me',
{
accessToken: token,
parameters: {
fields: {string: 'email, name'},
},
},
this.getUserCallback,
);
new GraphRequestManager().addRequest(infoRequest).start();
};
render() {
return (
<Fragment>
<StatusBar backgroundColor='#3b5998' barStyle='light-content' />
<SafeAreaView style={styles.container}>
<View style={styles.content}>
{this.state.loading && <ActivityIndicator />}
{this.state.user && (
<Fragment>
<Text style={styles.userName}>{this.state.user.name}</Text>
<Text style={styles.userEmail}>{this.state.user.email}</Text>
</Fragment>
)}
</View>
<LoginButton
permissions={['public_profile', 'email']}
onLoginFinished={async (error, result) => {
if (error) {
console.log('auth error', error);
} else if (result.isCancelled) {
console.log('isCancelled');
} else {
const accessData = await AccessToken.getCurrentAccessToken();
this.setState({loading: true});
this.getUserInfo(accessData.accessToken);
}
}}
onLogoutFinished={() => this.setState({user: null})}
/>
</SafeAreaView>
</Fragment>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#3b5998'
},
content: {
alignItems: 'center',
justifyContent: 'center',
marginBottom: 20,
},
userName: {
fontWeight: 'bold',
color: '#333',
fontSize: 18,
},
userEmail: {
color: '#888',
fontSize: 14,
},
});