2018-07-10 13:40:32 +00:00
|
|
|
import { Component } from 'react';
|
2018-10-23 21:39:48 +00:00
|
|
|
import { Linking, Platform, Dimensions } from 'react-native';
|
2018-07-10 13:40:32 +00:00
|
|
|
import { Navigation } from 'react-native-navigation';
|
2017-09-01 19:42:50 +00:00
|
|
|
|
2017-08-21 00:11:46 +00:00
|
|
|
import store from './lib/createStore';
|
2018-07-10 13:40:32 +00:00
|
|
|
import { appInit } from './actions';
|
|
|
|
import { iconsLoaded } from './Icons';
|
|
|
|
import { registerScreens } from './views';
|
|
|
|
import { deepLinkingOpen } from './actions/deepLinking';
|
|
|
|
import parseQuery from './lib/methods/helpers/parseQuery';
|
|
|
|
import { initializePushNotifications } from './push';
|
2017-08-21 00:11:46 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
const isAndroid = () => Platform.OS === 'android';
|
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
const startLogged = () => {
|
2018-10-23 21:39:48 +00:00
|
|
|
Navigation.setRoot({
|
|
|
|
root: {
|
|
|
|
sideMenu: {
|
|
|
|
left: {
|
|
|
|
component: {
|
|
|
|
id: 'Sidebar',
|
|
|
|
name: 'Sidebar'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
center: {
|
|
|
|
stack: {
|
|
|
|
id: 'AppRoot',
|
|
|
|
children: [{
|
|
|
|
component: {
|
|
|
|
id: 'RoomsListView',
|
|
|
|
name: 'RoomsListView'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
});
|
|
|
|
};
|
2017-08-21 00:11:46 +00:00
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
const startNotLogged = () => {
|
2018-10-23 21:39:48 +00:00
|
|
|
Navigation.setRoot({
|
|
|
|
root: {
|
|
|
|
stack: {
|
|
|
|
children: [{
|
|
|
|
component: {
|
|
|
|
name: 'OnboardingView'
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
options: {
|
|
|
|
layout: {
|
|
|
|
orientation: ['portrait']
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
});
|
|
|
|
};
|
2017-08-22 01:24:41 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
const handleOpenURL = ({ url }) => {
|
|
|
|
if (url) {
|
|
|
|
url = url.replace(/rocketchat:\/\/|https:\/\/go.rocket.chat\//, '');
|
|
|
|
const regex = /^(room|auth)\?/;
|
|
|
|
if (url.match(regex)) {
|
|
|
|
url = url.replace(regex, '');
|
|
|
|
const params = parseQuery(url);
|
|
|
|
store.dispatch(deepLinkingOpen(params));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
registerScreens(store);
|
|
|
|
iconsLoaded();
|
|
|
|
|
|
|
|
export default class App extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
store.dispatch(appInit());
|
|
|
|
store.subscribe(this.onStoreUpdate.bind(this));
|
|
|
|
initializePushNotifications();
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
Navigation.events().registerAppLaunchedListener(() => {
|
|
|
|
Navigation.setDefaultOptions({
|
|
|
|
topBar: {
|
|
|
|
backButton: {
|
|
|
|
icon: { uri: 'back', scale: Dimensions.get('window').scale }
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
color: isAndroid() ? '#FFF' : undefined
|
|
|
|
},
|
|
|
|
background: {
|
|
|
|
color: isAndroid() ? '#2F343D' : undefined
|
|
|
|
},
|
|
|
|
buttonColor: '#FFF'
|
|
|
|
},
|
|
|
|
sideMenu: {
|
|
|
|
left: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
store.dispatch(appInit());
|
|
|
|
store.subscribe(this.onStoreUpdate.bind(this));
|
|
|
|
});
|
2018-07-10 13:40:32 +00:00
|
|
|
Linking
|
|
|
|
.getInitialURL()
|
|
|
|
.then(url => handleOpenURL({ url }))
|
|
|
|
.catch(e => console.warn(e));
|
|
|
|
Linking.addEventListener('url', handleOpenURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
onStoreUpdate = () => {
|
|
|
|
const { root } = store.getState().app;
|
|
|
|
|
|
|
|
if (this.currentRoot !== root) {
|
|
|
|
this.currentRoot = root;
|
|
|
|
if (root === 'outside') {
|
2018-08-10 17:26:36 +00:00
|
|
|
startNotLogged();
|
2018-07-10 13:40:32 +00:00
|
|
|
} else if (root === 'inside') {
|
|
|
|
startLogged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setDeviceToken(deviceToken) {
|
|
|
|
this.deviceToken = deviceToken;
|
|
|
|
}
|
|
|
|
}
|