[READ-ONLY] Mirror of https://github.com/andrioid/expo-android-splash-bug. temporary repo
1.6 kB
67 lines
1import React from 'react';
2import { StyleSheet, Text, View } from 'react-native';
3import { AppLoading, Permissions, Notifications } from 'expo'
4
5const registerForPush = async () => {
6 const { status: existingStatus } = await Permissions.getAsync(
7 Permissions.NOTIFICATIONS
8 )
9 let finalStatus = existingStatus
10
11 if (existingStatus !== 'granted') {
12 const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS)
13 finalStatus = status
14 }
15
16 if (finalStatus !== 'granted') {
17 return // We can't continue without permission
18 }
19
20 Notifications.addListener(notification => {
21 dispatch(receivePushNotification(notification))
22 console.log('received push notification', notification)
23 })
24 try {
25 const token = await Notifications.getExpoPushTokenAsync()
26 return token
27 } catch (err) {
28 console.error(err)
29 }
30 return
31}
32
33
34export default class App extends React.Component {
35 componentDidMount() {
36 registerForPush()
37 .then((token) => {
38 this.setState({ ready: true, token })
39 })
40 .catch((err) => {
41 console.error(err)
42 })
43 }
44
45 state = { ready: false, token: '' }
46 render() {
47 if (!this.state.ready) {
48 return <AppLoading />
49 }
50 return (
51 <View style={styles.container}>
52 <Text>Main screen turn-on!</Text>
53 <Text>All your base are belong to us!</Text>
54 <Text>{this.state.token}</Text>
55 </View>
56 );
57 }
58}
59
60const styles = StyleSheet.create({
61 container: {
62 flex: 1,
63 backgroundColor: '#fff',
64 alignItems: 'center',
65 justifyContent: 'center',
66 },
67});