This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.tsx
114 lines (107 loc) · 2.48 KB
/
App.tsx
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
import React, { useState, useEffect } from 'react';
import * as Notifications from 'expo-notifications';
import { Text, View, Button, Clipboard } from 'react-native';
import { debug, getDebugValue } from './src/debug';
import { getToken } from './src/get-token';
Notifications.setNotificationHandler({
async handleNotification(...args) {
debug('A', args);
return {
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
};
},
handleSuccess(...args) {
debug('B', args);
},
handleError(...args) {
debug('C', args);
},
});
export default function App() {
const [pushToken, setPushToken] = useState<string | undefined>(undefined);
const [debugValue, setDebugValue] = useState('[Nothing debugged yet]');
useEffect(() => {
debug('D');
void Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}, []);
useEffect(() => {
debug('E');
const subscription = Notifications.addNotificationReceivedListener((notification) => {
debug('F', notification);
});
return () => {
debug('G');
subscription.remove();
};
}, []);
useEffect(() => {
debug('H');
const subscription = Notifications.addNotificationsDroppedListener(() => {
debug('I');
});
return () => {
debug('J');
subscription.remove();
};
}, []);
useEffect(() => {
debug('K');
const subscription = Notifications.addNotificationResponseReceivedListener((arg) => {
debug('L', arg);
});
return () => {
debug('M');
subscription.remove();
};
}, []);
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'space-around',
}}
>
<Text>Your push token: {pushToken}</Text>
<Text>Debug: {debugValue}</Text>
<View>
<Button
title="Press to copy token to clipboard"
onPress={async () => {
Clipboard.setString(pushToken ? 'Token: ' + pushToken : 'Token not found');
}}
/>
<Button
title="Press to get token"
onPress={async () => {
try {
setPushToken(await getToken());
} catch (error) {
debug('N', error);
}
}}
/>
<Button
title="Press to debug hello"
onPress={async () => {
debug('hello');
setDebugValue(getDebugValue());
}}
/>
<Button
title="Press to refresh debug"
onPress={async () => {
setDebugValue(getDebugValue());
}}
/>
</View>
</View>
);
}