-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
executable file
·99 lines (88 loc) · 3.14 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
import React, { Component } from 'react';
import { Platform, AppState, PushNotificationIOS } from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import { Provider } from 'react-redux';
import SendBird from 'sendbird';
import firebase from 'react-native-firebase';
import store from './src/store';
import Start from './src/screens/Start';
import Login from './src/screens/Login';
import Menu from './src/screens/Menu';
import Profile from './src/screens/Profile';
import OpenChannel from './src/screens/OpenChannel';
import OpenChannelCreate from './src/screens/OpenChannelCreate';
import Chat from './src/screens/Chat';
import Member from './src/screens/Member';
import BlockUser from './src/screens/BlockUser';
import GroupChannel from './src/screens/GroupChannel';
import GroupChannelInvite from './src/screens/GroupChannelInvite';
import appStateChangeHandler from './src/appStateChangeHandler';
import { firebaseConfig } from './src/firebase/fbconfig';
let AppNavigator;
let AppContainer;
export default class App extends Component {
constructor(props) {
super(props);
this.appStateHandler = appStateChangeHandler.getInstance();
AppNavigator = createStackNavigator(
{
Start: { screen: Start },
Login: { screen: Login },
Menu: { screen: Menu },
Profile: { screen: Profile },
OpenChannel: { screen: OpenChannel },
OpenChannelCreate: { screen: OpenChannelCreate },
Chat: { screen: Chat },
Member: { screen: Member },
BlockUser: { screen: BlockUser },
GroupChannel: { screen: GroupChannel },
GroupChannelInvite: { screen: GroupChannelInvite }
},
{
initialRouteName: 'Start',
navigationOptions: ({ navigation }) => ({
headerTitleStyle: { fontWeight: '500' }
})
}
);
AppContainer = createAppContainer(AppNavigator);
}
componentDidMount() {
const channel = new firebase.notifications.Android.Channel(
'com.reactnativewithsendbird.default_channel_id',
'React Native Redux sample',
firebase.notifications.Android.Importance.Max
).setDescription('React Native Redux sample notification channel');
firebase.notifications().android.createChannel(channel);
console.disableYellowBox = true;
console.log('app is launched');
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
console.log('app is killed');
AppState.removeEventListener('change', this._handleAppStateChange);
}
render() {
return (
<Provider store={store}>
<AppContainer />
</Provider>
);
}
_handleAppStateChange = nextAppState => {
const sb = SendBird.getInstance();
if (sb) {
if (nextAppState === 'active') {
if (Platform.OS === 'ios') {
PushNotificationIOS.setApplicationIconBadgeNumber(0);
}
console.log('app is into foreground');
sb.setForegroundState();
this.appStateHandler.notify();
} else if (nextAppState === 'background') {
console.log('app is into background');
sb.setBackgroundState();
}
}
};
}