-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
159 lines (152 loc) · 4.32 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
import React, {Component} from 'react';
import {AsyncStorage} from 'react-native';
import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {createBottomTabNavigator} from 'react-navigation-tabs';
import LoginScreen from './src/screens/LoginScreen';
import HomeScreen from './src/screens/HomeScreen';
import AuthLoadingScreen from './src/screens/AuthLoadingScreen';
import ChatScreen from './src/screens/ChatScreen';
import SplashScreen from './src/screens/SplashScreen';
import SignUpScreen from './src/screens/SignUpScreen';
import ProfileScreen from './src/screens/ProfileScreen';
import ListChatScreen from './src/screens/ListChatsScreen';
import FriendScreen from './src/screens/FriendProfile';
import OneSignal from 'react-native-onesignal';
import {Icon} from 'native-base';
import audio from 'react-native-sound';
import DeviceId from './src/Publics/store/deviceId';
const AppStack = createStackNavigator({
Home: HomeScreen,
Chat: ChatScreen,
});
const ChatStack = createStackNavigator({
ListChat: ListChatScreen,
Chat: ChatScreen,
Friend: FriendScreen,
});
const HomeBottom = createBottomTabNavigator(
{
Home: {
screen: AppStack,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({tintColor}) => (
<Icon
type="MaterialCommunityIcons"
name="google-maps"
style={{fontSize: 20, color: tintColor}}
/>
),
},
},
ListChat: {
screen: ChatStack,
navigationOptions: {
tabBarLabel: 'Chat',
tabBarIcon: ({tintColor}) => (
<Icon
type="FontAwesome"
name="wechat"
style={{fontSize: 20, color: tintColor}}
/>
),
},
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
tabBarLabel: 'Profile',
tabBarIcon: ({tintColor}) => (
<Icon
type="EvilIcons"
name="user"
style={{fontSize: 20, color: tintColor}}
/>
),
},
},
},
{
tabBarOptions: {
activeTintColor: '#5ba4e5',
inactiveTintColor: 'grey',
style: {
backgroundColor: 'white',
borderTopWidth: 0,
shadowOffset: {width: 5, height: 3},
shadowColor: 'black',
shadowOpacity: 0.5,
elevation: 5,
},
},
},
);
const AuthStack = createStackNavigator({
SignIn: {
screen: LoginScreen,
navigationOptions: ({navigation}) => ({header: null}),
},
Register: {
screen: SignUpScreen,
navigationOptions: ({navigation}) => ({header: null}),
},
Home: {
screen: HomeBottom,
},
});
const AppRoot = createAppContainer(
createSwitchNavigator(
{
SplashScreen: SplashScreen,
AuthLoading: AuthLoadingScreen,
App: HomeBottom,
Auth: AuthStack,
},
{
initialRouteName: 'SplashScreen',
headerMode: 'none',
},
),
);
export default class App extends Component {
constructor(properties) {
super(properties);
OneSignal.init('d78bd285-678f-429b-9b7e-1a8588d4a279');
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
OneSignal.enableSound(false);
OneSignal.inFocusDisplaying(2);
OneSignal.enableVibrate(true);
}
componentWillUnmount() {
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('opened', this.onOpened);
OneSignal.removeEventListener('ids', this.onIds);
}
onReceived(notification) {
console.log('Notification received: ', notification);
const notif = new audio('onichan.mp3', audio.MAIN_BUNDLE, err => {
if (err) {
return;
}
notif.play();
});
}
onOpened(openResult) {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult);
}
onIds(device) {
console.log('Device info: ', device);
DeviceId.IDPonsel = device.userId;
AsyncStorage.setItem('idponsel', device.userId);
console.warn(DeviceId.IDPonsel);
}
render() {
return <AppRoot />;
}
}