2018-07-10 13:40:32 +00:00
|
|
|
import { Component } from 'react';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { Linking } from 'react-native';
|
2017-09-01 19:42:50 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
import { appInit } from './actions';
|
|
|
|
import { deepLinkingOpen } from './actions/deepLinking';
|
2019-02-07 16:04:41 +00:00
|
|
|
import store from './lib/createStore';
|
|
|
|
import Icons from './lib/Icons';
|
|
|
|
import Navigation from './lib/Navigation';
|
2018-07-10 13:40:32 +00:00
|
|
|
import parseQuery from './lib/methods/helpers/parseQuery';
|
|
|
|
import { initializePushNotifications } from './push';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { DEFAULT_HEADER } from './constants/headerOptions';
|
2017-08-21 00:11:46 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
const startLogged = () => {
|
2019-01-31 16:08:38 +00:00
|
|
|
Navigation.loadView('ProfileView');
|
|
|
|
Navigation.loadView('RoomsListHeaderView');
|
|
|
|
Navigation.loadView('RoomsListView');
|
|
|
|
Navigation.loadView('RoomView');
|
|
|
|
Navigation.loadView('RoomHeaderView');
|
|
|
|
Navigation.loadView('SettingsView');
|
|
|
|
Navigation.loadView('SidebarView');
|
2018-10-23 21:39:48 +00:00
|
|
|
Navigation.setRoot({
|
|
|
|
root: {
|
|
|
|
sideMenu: {
|
|
|
|
left: {
|
|
|
|
component: {
|
2019-01-31 16:08:38 +00:00
|
|
|
id: 'SidebarView',
|
|
|
|
name: 'SidebarView'
|
2018-10-23 21:39:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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 = () => {
|
2019-01-31 16:08:38 +00:00
|
|
|
Navigation.loadView('OnboardingView');
|
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-11-14 21:42:03 +00:00
|
|
|
const startSetUsername = () => {
|
2019-01-31 16:08:38 +00:00
|
|
|
Navigation.loadView('SetUsernameView');
|
2018-11-14 21:42:03 +00:00
|
|
|
Navigation.setRoot({
|
|
|
|
root: {
|
|
|
|
stack: {
|
|
|
|
children: [{
|
|
|
|
component: {
|
|
|
|
name: 'SetUsernameView'
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
options: {
|
|
|
|
layout: {
|
|
|
|
orientation: ['portrait']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-07 16:04:41 +00:00
|
|
|
Icons.configure();
|
2018-07-10 13:40:32 +00:00
|
|
|
|
|
|
|
export default class App extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
initializePushNotifications();
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
Navigation.events().registerAppLaunchedListener(() => {
|
|
|
|
Navigation.setDefaultOptions({
|
2019-01-29 19:52:56 +00:00
|
|
|
...DEFAULT_HEADER,
|
2018-10-23 21:39:48 +00:00
|
|
|
sideMenu: {
|
|
|
|
left: {
|
|
|
|
enabled: false
|
2018-10-25 19:27:11 +00:00
|
|
|
},
|
|
|
|
right: {
|
|
|
|
enabled: false
|
2018-10-23 21:39:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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();
|
2018-11-14 21:42:03 +00:00
|
|
|
} else if (root === 'setUsername') {
|
|
|
|
startSetUsername();
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setDeviceToken(deviceToken) {
|
|
|
|
this.deviceToken = deviceToken;
|
|
|
|
}
|
|
|
|
}
|