-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
169 lines (153 loc) · 5.46 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
import React from "react";
import { View, StatusBar, Platform, YellowBox } from "react-native";
import {
createBottomTabNavigator,
createAppContainer,
createSwitchNavigator
} from "react-navigation";
import { connect } from "react-redux";
import GroupScreenStack from "./src/screens/Main/GroupScreenStack";
// import NotificationsScreen from "./src/screens/Main/NotificationsScreen";
import SettingsScreen from "./src/screens/Main/SettingsScreen";
import CalendarStack from "./src/screens/Main/CalendarStack";
import Auth from "./src/screens/Auth/Auth";
import UserDetails from "./src/screens/Auth/UserDetails";
import MyIcon from "./src/components/MyIcon";
import firebase from "react-native-firebase";
import storage from "redux-persist/lib/storage";
import TabBarComponent from "./src/components/TabBarComponent";
YellowBox.ignoreWarnings(["Possible Unhandled Promise Rejection"]);
const AppNavigator = createBottomTabNavigator(
{
Groups: GroupScreenStack,
Calendar: CalendarStack,
// Notifications: NotificationsScreen,
Profile: SettingsScreen
},
{
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
let IconComponent = MyIcon;
let iconName;
let iconType = "material";
if (routeName === "Groups") {
iconName = `chat${focused ? "" : "-bubble-outline"}`;
} else if (routeName === "Calendar") {
iconType = "material-community";
iconName = `calendar${
focused || Platform.OS === "ios" ? "" : "-blank-outline"
}`;
// } else if (routeName === "Notifications") {
// iconName = `notifications${focused ? "-active" : "-none"}`;
} else if (routeName === "Profile") {
iconName = `person${focused ? "" : "-outline"}`;
}
return (
<View style={{ paddingTop: 5 }}>
<IconComponent
name={iconName}
size={28}
color={tintColor}
type={iconType}
/>
</View>
);
},
tabBarComponent: TabBarComponent,
tabBarOptions: {
showLabel: false,
activeTintColor: "black",
inactiveTintColor: "gray"
}
})
}
);
const AuthNavigator = createSwitchNavigator(
{
Auth: Auth,
UserDetails: UserDetails
},
{
initialRouteName: "Auth"
}
);
const InitialNavigator = createSwitchNavigator(
{
App: AppNavigator,
Auth: AuthNavigator
},
{
initialRouteName: "Auth"
}
);
const AppContainer = createAppContainer(InitialNavigator);
class App extends React.Component {
async componentDidMount() {
// when app is closed and notification is tapped
storage.getAllKeys(keys => console.log(keys));
const notificationOpen = await firebase
.notifications()
.getInitialNotification();
if (notificationOpen) {
const action = notificationOpen.action;
const notification = notificationOpen.notification;
}
const channel = new firebase.notifications.Android.Channel(
"test-channel",
"Test Channel",
firebase.notifications.Android.Importance.Max
).setDescription("My apps test channel");
// Create the channel
firebase.notifications().android.createChannel(channel);
// when app is in the background (iOS, when content_available is true)
this.notificationDisplayedListener = firebase
.notifications()
.onNotificationDisplayed(notification => {
// Process your notification as required
// ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
});
// app in the foreground
this.notificationListener = firebase
.notifications()
.onNotification(async notification => {
const localNotification = new firebase.notifications.Notification({
show_in_foreground: true
})
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle || "")
.setBody(notification.body)
.setData(notification.data)
.setSound("default")
.android.setChannelId("test-channel") // e.g. the id you chose above
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(localNotification);
});
// when app is in the background and then notification is tapped
this.notificationOpenedListener = firebase
.notifications()
.onNotificationOpened(notificationOpen => {
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification = notificationOpen.notification;
firebase
.notifications()
.removeDeliveredNotification(notification.notificationId);
});
this.messageListener = firebase.messaging().onMessage(message => {});
}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
this.notificationOpenedListener();
this.messageListener();
}
render() {
if (Platform.OS === "android")
StatusBar.setBackgroundColor(this.props.colors.cliqueBlue);
return <AppContainer color={"black"} />;
}
}
export default connect(state => ({ colors: state.theme.colors }))(App);