-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.ios.js
232 lines (225 loc) · 8.02 KB
/
index.ios.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/**
* @flow
*/
/* global __DEV__ */
import React, { Component } from 'react';
import {
AppRegistry,
AppState,
Navigator,
StyleSheet,
View,
Text,
} from 'react-native';
import './modules/Bugsnag';
import { Provider } from 'react-redux';
import { isIphoneX } from 'react-native-iphone-x-helper';
import OneSignal from 'react-native-onesignal';
import MainSceneContainer from './containers/mainSceneContainer';
import NetworkAvailability from './components/networkAvailability';
import NotificationContainer from './containers/notificationContainer';
import SocialShareContainer from './containers/socialShareContainer';
import OfflineModeBanner from './components/offlineModeBanner';
import AnalyticsService from './modules/Analytics';
import NavigationStateNotifier from './modules/NavigationStateNotifier';
import SoundcloudPlaylist from './containers/soundcloudPlaylist';
import UploaderProfileContainer from './containers/uploaderProfileContainer'
import { store } from './redux/store/configure';
import { PUSH_NOTIFICATION_OPENED_HIT } from './helpers/constants';
import Config from './helpers/config';
import THEME from './styles/variables';
import AdMobBottomBanner from './components/adMobBottomBanner';
import config from './helpers/config';
//decorate navigator to add a method to push at the bottom of the routeStack
Navigator.prototype.pushToBottom = function (route) {
var activeStack = this.state.routeStack;
var activeAnimationConfigStack = this.state.sceneConfigStack;
var nextStack = activeStack.concat([route]);
var destIndex = nextStack.length - 1;
var nextAnimationConfigStack = activeAnimationConfigStack.concat([
this.props.configureScene(route),
]);
this._emitWillFocus(nextStack[destIndex]);
this.setState({
routeStack: nextStack,
sceneConfigStack: nextAnimationConfigStack,
}, () => {
this._enableScene(destIndex);
this._transitionTo(destIndex);
});
};
AnalyticsService.initialize(Config.GOOG_ANALYTICS_ID, 'SplitcloudApp');
if(!__DEV__){
/* avoid any logging to prevent performance drops in prod mode */
console.log = () => false;
console.info = () => false;
console.warn = () => false;
}
class SplitCloudApp extends Component {
constructor(props){
super(props);
this.configureScene = this.configureScene.bind(this);
this.onSceneDidFocus = this.onSceneDidFocus.bind(this);
this.onSceneWillFocus = this.onSceneWillFocus.bind(this);
this.initialNotification = null;
this.setStylesGlobalOvverides();
this.initPushNotifications();
this.bindNotificationListeners();
}
componentDidMount(){
// register notification handlers after we
// rendered and got a ref to the navigator instance
this.processInitialNotification();
}
processInitialNotification(){
console.log('processing initial notification');
if (this.initialNotification && this.navigator){
this.handlePushNotification(this.initialNotification);
this.initialNotification = null;
}
}
initPushNotifications(){
console.log('setting up PushNotifications OneSignal SDK');
OneSignal.init(config.ONE_SIGNAL_APP_ID,{kOSSettingsKeyAutoPrompt : true});
OneSignal.inFocusDisplaying(0);
OneSignal.setLocationShared(false);
OneSignal.setExternalUserId(AnalyticsService.uniqueClientId);
}
bindNotificationListeners(){
OneSignal.addEventListener('received', (notification) => {
console.log('received notification!', notification);
return false;
});
OneSignal.addEventListener('ids',(device) => {
console.log('received device info: ', device);
});
OneSignal.addEventListener('opened', (opened) => {
console.log('Opened notification', opened);
const notificationData = opened.notification.payload.additionalData;
if( this.navigator ){
this.handlePushNotification(notificationData);
} else {
this.initialNotification = notificationData;
}
});
}
handlePushNotification(notification){
const payload = notification;
let componentSceneData;
if (!payload) return false;
const activeMode = this.getActivePlaybackMode(store);
const activeSide = activeMode !== 'S' ? activeMode : 'L';
AnalyticsService.sendEvent({
category: `side-${activeSide}`,
action: PUSH_NOTIFICATION_OPENED_HIT,
label: payload.componentName,
value: 1,
});
if (payload.componentName === 'SoundcloudPlaylist') {
componentSceneData = {
title : `SoundcloudPlaylist - ${payload.playlistId} - ${activeSide}`,
name : 'SoundcloudPlaylist' + activeSide,
component: SoundcloudPlaylist,
passProps : {
playlist : { id: payload.playlistId },
side : activeSide,
}
};
}
if (payload.componentName === 'UploaderProfileContainer') {
componentSceneData = {
title: `${payload.componentName} - ${payload.scUploaderLink}`,
name: `${payload.componentName} ${activeSide}`,
component: UploaderProfileContainer,
passProps : {
scUploaderLink: payload.scUploaderLink,
side: activeSide
}
}
}
if (payload.componentName) {
this.navigator.push({ ...componentSceneData,
passProps:{
...componentSceneData.passProps,
onClose: () => this.navigator.pop()
}
})
}
}
setStylesGlobalOvverides(){
Text.defaultProps.allowFontScaling = false;
}
configureScene(route, routeStack){
return {
...Navigator.SceneConfigs.PushFromRight,
gestures: {}, // or null
};
}
onSceneDidFocus(route){
console.log('new scene did focus:',route);
NavigationStateNotifier.onSceneDidFocus(route);
}
onSceneWillFocus(route){
console.log('new scene will focus:',route);
let screenName = route.title;
if( this.isMainPlayerScreen(route) ){
screenName += ' | mode: ' + this.getActivePlaybackMode(store);
}
AnalyticsService.sendScreenView( screenName || 'Unknown Screen');
}
isMainPlayerScreen(route){
return route.name == 'MainSceneContainer';
}
getActivePlaybackMode(store){
return store.getState().mode;
}
render() {
return (
<Provider store={store} >
<Navigator
initialRoute={{
title: 'MainSceneContainer',
name:'MainSceneContainer',
index: 0,
component: MainSceneContainer
}}
onDidFocus={this.onSceneDidFocus}
onWillFocus={this.onSceneWillFocus}
ref={(navigator)=> {this.navigator = navigator;}}
renderScene={(route, navigator) => {
let Component = route.component;
return <NetworkAvailability>{
(isOnline,networkType) => {
const fullScreenPlayerScene = route.name == 'MainSceneContainer' ? [styles.fullScreenPlayer] :null;
return <View style={[styles.rootContainerView,fullScreenPlayerScene]}>
<Component title={route.title}
isOnline={isOnline}
networkType={networkType}
routeName={route.name}
navigator={navigator}
{...route.passProps}/>
<NotificationContainer />
<SocialShareContainer navigator={navigator} />
<OfflineModeBanner isOnline={isOnline} />
<AdMobBottomBanner adDisabled={config.AD_DISABLED} />
</View>
}
}</NetworkAvailability>
}}
configureScene={ this.configureScene }
/>
</Provider>
);
}
}
const styles = StyleSheet.create({
rootContainerView:{
flex: 1,
backgroundColor:THEME.mainBgColor,
paddingTop: isIphoneX() ? 40 : 20
},
fullScreenPlayer: {
paddingTop: 0
}
})
AppRegistry.registerComponent('SplitCloudApp', () => SplitCloudApp);