-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
78 lines (72 loc) · 2.57 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
import React from "react";
import { StyleSheet, Alert, View } from "react-native";
import firebase from "react-native-firebase";
import { Provider } from "react-redux";
import stripe from "tipsi-stripe";
import AppNavigator from "./app/router";
import store from "./app/store";
import NavigationService from "./app/utils/NavigationService";
import { StripeApiKey } from "./app/config";
export default class App extends React.Component {
state = {
user: null,
};
componentDidMount = () => {
stripe.setOptions({
publishableKey: StripeApiKey,
// merchantId: AppleMerachantKey // Optional
// androidPayMode: 'test', // Android only
});
this.createNotificationListeners();
};
componentWillUnmount() {
this.notificationListener();
this.notificationOpenedListener();
this.messageListener();
}
// receives notification when the app is in background or foreground and tells what to do notification is clicked
createNotificationListeners = async () => {
// Triggered when a particular notification has been received in foreground
this.notificationListener = firebase
.notifications()
.onNotification((notification) => {
const { title, body } = notification;
console.log(title);
});
// If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
this.notificationOpenedListener = firebase
.notifications()
.onNotificationOpened((notificationOpen) => {
console.log(notificationOpen.notification);
const { title, body } = notificationOpen.notification;
// NavigationService.navigate('Bookings');
});
// If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
const notificationOpen = await firebase
.notifications()
.getInitialNotification();
if (notificationOpen) {
console.log(notificationOpen.notification);
const { title, body, data } = notificationOpen.notification;
console.log(data);
// NavigationService.navigate("Bookings");
}
// Triggered for data only payload in foreground
this.messageListener = firebase.messaging().onMessage((message) => {
//process data message
console.log(JSON.stringify(message));
});
};
render() {
console.disableYellowBox = true;
return (
<Provider store={store}>
<AppNavigator
ref={(navigatorRef) => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
</Provider>
);
}
}