2019-03-12 16:23:06 +00:00
|
|
|
import React from 'react';
|
2020-02-17 16:42:34 +00:00
|
|
|
import {
|
|
|
|
View, Linking, BackHandler, ScrollView
|
|
|
|
} from 'react-native';
|
2019-09-17 19:24:47 +00:00
|
|
|
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
|
|
|
|
import { createStackNavigator } from 'react-navigation-stack';
|
|
|
|
import { createDrawerNavigator } from 'react-navigation-drawer';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { AppearanceProvider } from 'react-native-appearance';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { Provider } from 'react-redux';
|
2019-06-10 16:23:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-04 16:39:53 +00:00
|
|
|
import RNUserDefaults from 'rn-user-defaults';
|
2019-11-25 20:01:17 +00:00
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import KeyCommands, { KeyCommandsEmitter } from 'react-native-keycommands';
|
2017-09-01 19:42:50 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import {
|
|
|
|
defaultTheme,
|
|
|
|
newThemeState,
|
|
|
|
subscribeTheme,
|
|
|
|
unsubscribeTheme
|
|
|
|
} from './utils/theme';
|
2019-11-25 20:01:17 +00:00
|
|
|
import EventEmitter from './utils/events';
|
2019-12-04 16:50:22 +00:00
|
|
|
import { appInit, appInitLocalSettings } from './actions';
|
2018-07-10 13:40:32 +00:00
|
|
|
import { deepLinkingOpen } from './actions/deepLinking';
|
2019-02-07 16:04:41 +00:00
|
|
|
import Navigation from './lib/Navigation';
|
2019-03-12 16:23:06 +00:00
|
|
|
import Sidebar from './views/SidebarView';
|
2018-07-10 13:40:32 +00:00
|
|
|
import parseQuery from './lib/methods/helpers/parseQuery';
|
2019-06-10 16:23:19 +00:00
|
|
|
import { initializePushNotifications, onNotification } from './notifications/push';
|
2019-03-12 16:23:06 +00:00
|
|
|
import store from './lib/createStore';
|
2019-06-10 16:23:19 +00:00
|
|
|
import NotificationBadge from './notifications/inApp';
|
2019-12-18 21:13:11 +00:00
|
|
|
import {
|
|
|
|
defaultHeader, onNavigationStateChange, cardStyle, getActiveRouteName
|
|
|
|
} from './utils/navigation';
|
2019-08-23 13:18:47 +00:00
|
|
|
import { loggerConfig, analytics } from './utils/log';
|
2019-07-23 14:02:57 +00:00
|
|
|
import Toast from './containers/Toast';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { ThemeContext } from './theme';
|
|
|
|
import RocketChat, { THEME_PREFERENCES_KEY } from './lib/rocketchat';
|
2019-11-25 20:01:17 +00:00
|
|
|
import { MIN_WIDTH_SPLIT_LAYOUT } from './constants/tablet';
|
|
|
|
import {
|
2020-02-17 16:42:34 +00:00
|
|
|
isTablet, isSplited, isIOS, setWidth, supportSystemTheme, isAndroid
|
2019-11-25 20:01:17 +00:00
|
|
|
} from './utils/deviceInfo';
|
|
|
|
import { KEY_COMMAND } from './commands';
|
|
|
|
import Tablet, { initTabletNav } from './tablet';
|
|
|
|
import sharedStyles from './views/Styles';
|
|
|
|
import { SplitContext } from './split';
|
2017-08-21 00:11:46 +00:00
|
|
|
|
2020-02-17 19:06:18 +00:00
|
|
|
import RoomsListView from './views/RoomsListView';
|
|
|
|
import RoomView from './views/RoomView';
|
|
|
|
|
2019-11-04 15:19:27 +00:00
|
|
|
if (isIOS) {
|
|
|
|
const RNScreens = require('react-native-screens');
|
|
|
|
RNScreens.useScreens();
|
|
|
|
}
|
2018-11-14 21:42:03 +00:00
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
const parseDeepLinking = (url) => {
|
2018-07-10 13:40:32 +00:00
|
|
|
if (url) {
|
|
|
|
url = url.replace(/rocketchat:\/\/|https:\/\/go.rocket.chat\//, '');
|
2020-01-28 13:22:35 +00:00
|
|
|
const regex = /^(room|auth|invite)\?/;
|
2018-07-10 13:40:32 +00:00
|
|
|
if (url.match(regex)) {
|
2019-03-18 18:52:38 +00:00
|
|
|
url = url.replace(regex, '').trim();
|
|
|
|
if (url) {
|
|
|
|
return parseQuery(url);
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-18 18:52:38 +00:00
|
|
|
return null;
|
2018-07-10 13:40:32 +00:00
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
// Outside
|
|
|
|
const OutsideStack = createStackNavigator({
|
|
|
|
OnboardingView: {
|
2019-07-17 13:37:20 +00:00
|
|
|
getScreen: () => require('./views/OnboardingView').default,
|
2019-03-12 16:23:06 +00:00
|
|
|
header: null
|
|
|
|
},
|
2019-07-17 13:37:20 +00:00
|
|
|
NewServerView: {
|
|
|
|
getScreen: () => require('./views/NewServerView').default
|
|
|
|
},
|
2020-03-30 19:20:50 +00:00
|
|
|
WorkspaceView: {
|
|
|
|
getScreen: () => require('./views/WorkspaceView').default
|
2019-07-17 13:37:20 +00:00
|
|
|
},
|
|
|
|
LoginView: {
|
|
|
|
getScreen: () => require('./views/LoginView').default
|
|
|
|
},
|
|
|
|
ForgotPasswordView: {
|
|
|
|
getScreen: () => require('./views/ForgotPasswordView').default
|
|
|
|
},
|
|
|
|
RegisterView: {
|
|
|
|
getScreen: () => require('./views/RegisterView').default
|
|
|
|
},
|
|
|
|
LegalView: {
|
|
|
|
getScreen: () => require('./views/LegalView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-08-09 17:28:46 +00:00
|
|
|
const AuthenticationWebViewStack = createStackNavigator({
|
|
|
|
AuthenticationWebView: {
|
|
|
|
getScreen: () => require('./views/AuthenticationWebView').default
|
2019-07-17 13:37:20 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const OutsideStackModal = createStackNavigator({
|
|
|
|
OutsideStack,
|
2019-08-09 17:28:46 +00:00
|
|
|
AuthenticationWebViewStack
|
2019-03-12 16:23:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
2019-12-04 16:39:53 +00:00
|
|
|
headerMode: 'none',
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const RoomRoutes = {
|
2020-02-17 19:06:18 +00:00
|
|
|
RoomView,
|
2019-11-25 20:01:17 +00:00
|
|
|
ThreadMessagesView: {
|
|
|
|
getScreen: () => require('./views/ThreadMessagesView').default
|
|
|
|
},
|
|
|
|
MarkdownTableView: {
|
|
|
|
getScreen: () => require('./views/MarkdownTableView').default
|
|
|
|
},
|
|
|
|
ReadReceiptsView: {
|
|
|
|
getScreen: () => require('./views/ReadReceiptView').default
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
// Inside
|
|
|
|
const ChatsStack = createStackNavigator({
|
2020-02-17 19:06:18 +00:00
|
|
|
RoomsListView,
|
2019-07-17 13:37:20 +00:00
|
|
|
RoomActionsView: {
|
|
|
|
getScreen: () => require('./views/RoomActionsView').default
|
|
|
|
},
|
|
|
|
RoomInfoView: {
|
|
|
|
getScreen: () => require('./views/RoomInfoView').default
|
|
|
|
},
|
|
|
|
RoomInfoEditView: {
|
|
|
|
getScreen: () => require('./views/RoomInfoEditView').default
|
|
|
|
},
|
|
|
|
RoomMembersView: {
|
|
|
|
getScreen: () => require('./views/RoomMembersView').default
|
|
|
|
},
|
|
|
|
SearchMessagesView: {
|
|
|
|
getScreen: () => require('./views/SearchMessagesView').default
|
|
|
|
},
|
|
|
|
SelectedUsersView: {
|
|
|
|
getScreen: () => require('./views/SelectedUsersView').default
|
|
|
|
},
|
2020-01-28 13:22:35 +00:00
|
|
|
InviteUsersView: {
|
|
|
|
getScreen: () => require('./views/InviteUsersView').default
|
|
|
|
},
|
|
|
|
InviteUsersEditView: {
|
|
|
|
getScreen: () => require('./views/InviteUsersEditView').default
|
|
|
|
},
|
2019-07-17 13:37:20 +00:00
|
|
|
MessagesView: {
|
|
|
|
getScreen: () => require('./views/MessagesView').default
|
|
|
|
},
|
|
|
|
AutoTranslateView: {
|
|
|
|
getScreen: () => require('./views/AutoTranslateView').default
|
|
|
|
},
|
|
|
|
DirectoryView: {
|
|
|
|
getScreen: () => require('./views/DirectoryView').default
|
2019-08-23 16:24:15 +00:00
|
|
|
},
|
|
|
|
NotificationPrefView: {
|
|
|
|
getScreen: () => require('./views/NotificationPreferencesView').default
|
2019-11-25 20:01:17 +00:00
|
|
|
},
|
|
|
|
...RoomRoutes
|
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Inside
|
|
|
|
const RoomStack = createStackNavigator({
|
|
|
|
...RoomRoutes
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-04-18 13:43:44 +00:00
|
|
|
ChatsStack.navigationOptions = ({ navigation }) => {
|
|
|
|
let drawerLockMode = 'unlocked';
|
2019-11-25 20:01:17 +00:00
|
|
|
if (navigation.state.index > 0 || isSplited()) {
|
2019-04-18 13:43:44 +00:00
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const ProfileStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
ProfileView: {
|
|
|
|
getScreen: () => require('./views/ProfileView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-04-24 18:36:29 +00:00
|
|
|
ProfileStack.navigationOptions = ({ navigation }) => {
|
2019-04-18 13:43:44 +00:00
|
|
|
let drawerLockMode = 'unlocked';
|
|
|
|
if (navigation.state.index > 0) {
|
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const SettingsStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
SettingsView: {
|
|
|
|
getScreen: () => require('./views/SettingsView').default
|
|
|
|
},
|
|
|
|
LanguageView: {
|
|
|
|
getScreen: () => require('./views/LanguageView').default
|
2019-12-04 16:39:53 +00:00
|
|
|
},
|
|
|
|
ThemeView: {
|
|
|
|
getScreen: () => require('./views/ThemeView').default
|
2020-02-19 20:52:05 +00:00
|
|
|
},
|
|
|
|
DefaultBrowserView: {
|
|
|
|
getScreen: () => require('./views/DefaultBrowserView').default
|
2019-07-17 13:37:20 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-05-18 19:31:33 +00:00
|
|
|
const AdminPanelStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
AdminPanelView: {
|
|
|
|
getScreen: () => require('./views/AdminPanelView').default
|
|
|
|
}
|
2019-05-18 19:31:33 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-05-18 19:31:33 +00:00
|
|
|
});
|
|
|
|
|
2019-04-18 13:43:44 +00:00
|
|
|
SettingsStack.navigationOptions = ({ navigation }) => {
|
|
|
|
let drawerLockMode = 'unlocked';
|
|
|
|
if (navigation.state.index > 0) {
|
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const ChatsDrawer = createDrawerNavigator({
|
|
|
|
ChatsStack,
|
|
|
|
ProfileStack,
|
2019-05-18 19:31:33 +00:00
|
|
|
SettingsStack,
|
|
|
|
AdminPanelStack
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-09-24 17:37:13 +00:00
|
|
|
contentComponent: Sidebar,
|
|
|
|
overlayColor: '#00000090'
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const NewMessageStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
NewMessageView: {
|
|
|
|
getScreen: () => require('./views/NewMessageView').default
|
|
|
|
},
|
|
|
|
SelectedUsersViewCreateChannel: {
|
|
|
|
getScreen: () => require('./views/SelectedUsersView').default
|
|
|
|
},
|
|
|
|
CreateChannelView: {
|
|
|
|
getScreen: () => require('./views/CreateChannelView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-12-18 21:13:11 +00:00
|
|
|
const AttachmentStack = createStackNavigator({
|
|
|
|
AttachmentView: {
|
|
|
|
getScreen: () => require('./views/AttachmentView').default
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
|
|
|
});
|
|
|
|
|
2020-02-11 14:01:35 +00:00
|
|
|
const ModalBlockStack = createStackNavigator({
|
|
|
|
ModalBlockView: {
|
|
|
|
getScreen: () => require('./views/ModalBlockView').default
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
mode: 'modal',
|
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
|
|
|
});
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const InsideStackModal = createStackNavigator({
|
|
|
|
Main: ChatsDrawer,
|
2019-09-25 22:13:39 +00:00
|
|
|
NewMessageStack,
|
2019-12-18 21:13:11 +00:00
|
|
|
AttachmentStack,
|
2020-02-11 14:01:35 +00:00
|
|
|
ModalBlockStack,
|
2019-09-25 22:13:39 +00:00
|
|
|
JitsiMeetView: {
|
|
|
|
getScreen: () => require('./views/JitsiMeetView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
2019-12-04 16:39:53 +00:00
|
|
|
headerMode: 'none',
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const SetUsernameStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
SetUsernameView: {
|
|
|
|
getScreen: () => require('./views/SetUsernameView').default
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
cardStyle
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-06-10 16:23:19 +00:00
|
|
|
class CustomInsideStack extends React.Component {
|
|
|
|
static router = InsideStackModal.router;
|
|
|
|
|
|
|
|
static propTypes = {
|
2019-11-25 20:01:17 +00:00
|
|
|
navigation: PropTypes.object,
|
|
|
|
screenProps: PropTypes.object
|
2019-06-10 16:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { navigation, screenProps } = this.props;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<InsideStackModal navigation={navigation} screenProps={screenProps} />
|
|
|
|
{ !isTablet ? <NotificationBadge navigation={navigation} /> : null }
|
|
|
|
{ !isTablet ? <Toast /> : null }
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomRoomStack extends React.Component {
|
|
|
|
static router = RoomStack.router;
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
screenProps: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { navigation, screenProps } = this.props;
|
2019-06-10 16:23:19 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-11-25 20:01:17 +00:00
|
|
|
<RoomStack navigation={navigation} screenProps={screenProps} />
|
2019-07-23 14:02:57 +00:00
|
|
|
<Toast />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-06-10 16:23:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const MessagesStack = createStackNavigator({
|
|
|
|
NewMessageView: {
|
|
|
|
getScreen: () => require('./views/NewMessageView').default
|
|
|
|
},
|
|
|
|
SelectedUsersViewCreateChannel: {
|
|
|
|
getScreen: () => require('./views/SelectedUsersView').default
|
|
|
|
},
|
|
|
|
CreateChannelView: {
|
|
|
|
getScreen: () => require('./views/CreateChannelView').default
|
|
|
|
}
|
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const DirectoryStack = createStackNavigator({
|
|
|
|
DirectoryView: {
|
|
|
|
getScreen: () => require('./views/DirectoryView').default
|
|
|
|
}
|
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const SidebarStack = createStackNavigator({
|
|
|
|
SettingsView: {
|
|
|
|
getScreen: () => require('./views/SettingsView').default
|
|
|
|
},
|
|
|
|
ProfileView: {
|
|
|
|
getScreen: () => require('./views/ProfileView').default
|
|
|
|
},
|
|
|
|
AdminPanelView: {
|
|
|
|
getScreen: () => require('./views/AdminPanelView').default
|
|
|
|
}
|
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const RoomActionsStack = createStackNavigator({
|
|
|
|
RoomActionsView: {
|
|
|
|
getScreen: () => require('./views/RoomActionsView').default
|
|
|
|
},
|
|
|
|
RoomInfoView: {
|
|
|
|
getScreen: () => require('./views/RoomInfoView').default
|
|
|
|
},
|
|
|
|
RoomInfoEditView: {
|
|
|
|
getScreen: () => require('./views/RoomInfoEditView').default
|
|
|
|
},
|
|
|
|
RoomMembersView: {
|
|
|
|
getScreen: () => require('./views/RoomMembersView').default
|
|
|
|
},
|
|
|
|
SearchMessagesView: {
|
|
|
|
getScreen: () => require('./views/SearchMessagesView').default
|
|
|
|
},
|
|
|
|
SelectedUsersView: {
|
|
|
|
getScreen: () => require('./views/SelectedUsersView').default
|
|
|
|
},
|
|
|
|
MessagesView: {
|
|
|
|
getScreen: () => require('./views/MessagesView').default
|
|
|
|
},
|
|
|
|
AutoTranslateView: {
|
|
|
|
getScreen: () => require('./views/AutoTranslateView').default
|
|
|
|
},
|
|
|
|
ReadReceiptsView: {
|
|
|
|
getScreen: () => require('./views/ReadReceiptView').default
|
|
|
|
},
|
|
|
|
NotificationPrefView: {
|
|
|
|
getScreen: () => require('./views/NotificationPreferencesView').default
|
2019-12-18 21:13:11 +00:00
|
|
|
},
|
|
|
|
AttachmentView: {
|
|
|
|
getScreen: () => require('./views/AttachmentView').default
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
}, {
|
2019-12-04 16:39:53 +00:00
|
|
|
defaultNavigationOptions: defaultHeader,
|
|
|
|
cardStyle
|
2019-11-25 20:01:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const ModalSwitch = createSwitchNavigator({
|
|
|
|
MessagesStack,
|
|
|
|
DirectoryStack,
|
|
|
|
SidebarStack,
|
|
|
|
RoomActionsStack,
|
|
|
|
SettingsStack,
|
2020-02-11 14:01:35 +00:00
|
|
|
ModalBlockStack,
|
2019-11-25 20:01:17 +00:00
|
|
|
AuthLoading: () => null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
initialRouteName: 'AuthLoading'
|
|
|
|
});
|
|
|
|
|
|
|
|
class CustomModalStack extends React.Component {
|
|
|
|
static router = ModalSwitch.router;
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
showModal: PropTypes.bool,
|
|
|
|
closeModal: PropTypes.func,
|
|
|
|
screenProps: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.closeModal);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.backHandler.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
closeModal = () => {
|
|
|
|
const { closeModal, navigation } = this.props;
|
|
|
|
const { state } = navigation;
|
|
|
|
if (state && state.routes[state.index] && state.routes[state.index].index === 0) {
|
|
|
|
closeModal();
|
|
|
|
return true;
|
|
|
|
}
|
2020-02-28 17:26:31 +00:00
|
|
|
if (state && state.routes[state.index] && state.routes[state.index].routes && state.routes[state.index].routes.length > 1) {
|
2020-02-11 14:01:35 +00:00
|
|
|
navigation.goBack();
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
navigation, showModal, closeModal, screenProps
|
|
|
|
} = this.props;
|
2019-12-18 21:13:11 +00:00
|
|
|
|
|
|
|
const pageSheetViews = ['AttachmentView'];
|
|
|
|
const pageSheet = pageSheetViews.includes(getActiveRouteName(navigation.state));
|
|
|
|
|
2020-02-17 16:42:34 +00:00
|
|
|
const androidProps = isAndroid && {
|
|
|
|
style: { marginBottom: 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
let content = (
|
|
|
|
<View style={[sharedStyles.modal, pageSheet ? sharedStyles.modalPageSheet : sharedStyles.modalFormSheet]}>
|
|
|
|
<ModalSwitch navigation={navigation} screenProps={{ ...screenProps, closeModal: this.closeModal }} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isAndroid) {
|
|
|
|
content = (
|
|
|
|
<ScrollView overScrollMode='never'>
|
|
|
|
{content}
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
useNativeDriver
|
|
|
|
coverScreen={false}
|
|
|
|
isVisible={showModal}
|
|
|
|
onBackdropPress={closeModal}
|
|
|
|
hideModalContentWhileAnimating
|
|
|
|
avoidKeyboard
|
2020-02-17 16:42:34 +00:00
|
|
|
{...androidProps}
|
2019-11-25 20:01:17 +00:00
|
|
|
>
|
2020-02-17 16:42:34 +00:00
|
|
|
{content}
|
2019-11-25 20:01:17 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomNotificationStack extends React.Component {
|
|
|
|
static router = InsideStackModal.router;
|
|
|
|
|
|
|
|
static propTypes = {
|
2019-12-04 16:39:53 +00:00
|
|
|
navigation: PropTypes.object,
|
|
|
|
screenProps: PropTypes.object
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { navigation, screenProps } = this.props;
|
|
|
|
return <NotificationBadge navigation={navigation} screenProps={screenProps} />;
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const App = createAppContainer(createSwitchNavigator(
|
2019-03-12 16:23:06 +00:00
|
|
|
{
|
|
|
|
OutsideStack: OutsideStackModal,
|
2019-06-10 16:23:19 +00:00
|
|
|
InsideStack: CustomInsideStack,
|
2019-07-17 13:37:20 +00:00
|
|
|
AuthLoading: {
|
|
|
|
getScreen: () => require('./views/AuthLoadingView').default
|
|
|
|
},
|
2019-03-12 16:23:06 +00:00
|
|
|
SetUsernameStack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
initialRouteName: 'AuthLoading'
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
));
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
export const RoomContainer = createAppContainer(CustomRoomStack);
|
|
|
|
|
|
|
|
export const ModalContainer = createAppContainer(CustomModalStack);
|
|
|
|
|
|
|
|
export const NotificationContainer = createAppContainer(CustomNotificationStack);
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
export default class Root extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.init();
|
2019-08-23 13:18:47 +00:00
|
|
|
this.initCrashReport();
|
2019-11-25 20:01:17 +00:00
|
|
|
this.state = {
|
|
|
|
split: false,
|
|
|
|
inside: false,
|
2019-12-04 16:39:53 +00:00
|
|
|
showModal: false,
|
|
|
|
theme: defaultTheme(),
|
|
|
|
themePreferences: {
|
|
|
|
currentTheme: supportSystemTheme() ? 'automatic' : 'light',
|
|
|
|
darkLevel: 'dark'
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
};
|
|
|
|
if (isTablet) {
|
|
|
|
this.initTablet();
|
|
|
|
}
|
2019-03-18 18:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.listenerTimeout = setTimeout(() => {
|
|
|
|
Linking.addEventListener('url', ({ url }) => {
|
|
|
|
const parsedDeepLinkingURL = parseDeepLinking(url);
|
|
|
|
if (parsedDeepLinkingURL) {
|
|
|
|
store.dispatch(deepLinkingOpen(parsedDeepLinkingURL));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
componentDidUpdate(_, prevState) {
|
|
|
|
if (isTablet) {
|
|
|
|
const { split, inside } = this.state;
|
|
|
|
if (inside && split !== prevState.split) {
|
|
|
|
// Reset app on split mode changes
|
|
|
|
Navigation.navigate('RoomsListView');
|
|
|
|
this.closeModal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
clearTimeout(this.listenerTimeout);
|
2019-12-04 16:39:53 +00:00
|
|
|
|
|
|
|
unsubscribeTheme();
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (this.onKeyCommands && this.onKeyCommands.remove) {
|
|
|
|
this.onKeyCommands.remove();
|
|
|
|
}
|
2019-03-18 18:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init = async() => {
|
2019-12-04 16:39:53 +00:00
|
|
|
RNUserDefaults.objectForKey(THEME_PREFERENCES_KEY).then(this.setTheme);
|
2019-03-18 18:52:38 +00:00
|
|
|
const [notification, deepLinking] = await Promise.all([initializePushNotifications(), Linking.getInitialURL()]);
|
|
|
|
const parsedDeepLinkingURL = parseDeepLinking(deepLinking);
|
2019-12-04 16:50:22 +00:00
|
|
|
store.dispatch(appInitLocalSettings());
|
2019-03-18 18:52:38 +00:00
|
|
|
if (notification) {
|
|
|
|
onNotification(notification);
|
|
|
|
} else if (parsedDeepLinkingURL) {
|
|
|
|
store.dispatch(deepLinkingOpen(parsedDeepLinkingURL));
|
|
|
|
} else {
|
|
|
|
store.dispatch(appInit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
setTheme = (newTheme = {}) => {
|
|
|
|
// change theme state
|
|
|
|
this.setState(prevState => newThemeState(prevState, newTheme), () => {
|
|
|
|
const { themePreferences } = this.state;
|
|
|
|
// subscribe to Appearance changes
|
|
|
|
subscribeTheme(themePreferences, this.setTheme);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
initTablet = async() => {
|
|
|
|
initTabletNav(args => this.setState(args));
|
|
|
|
await KeyCommands.setKeyCommands([]);
|
|
|
|
this.onKeyCommands = KeyCommandsEmitter.addListener(
|
|
|
|
'onKeyCommand',
|
|
|
|
command => EventEmitter.emit(KEY_COMMAND, { event: command })
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:18:47 +00:00
|
|
|
initCrashReport = () => {
|
|
|
|
RocketChat.getAllowCrashReport()
|
|
|
|
.then((allowCrashReport) => {
|
|
|
|
if (!allowCrashReport) {
|
|
|
|
loggerConfig.autoNotify = false;
|
|
|
|
loggerConfig.registerBeforeSendCallback(() => false);
|
|
|
|
analytics().setAnalyticsCollectionEnabled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
onLayout = ({ nativeEvent: { layout: { width } } }) => (isTablet ? this.setSplit(width) : null);
|
|
|
|
|
|
|
|
setSplit = (width) => {
|
|
|
|
this.setState({ split: width > MIN_WIDTH_SPLIT_LAYOUT });
|
|
|
|
setWidth(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
closeModal = () => this.setState({ showModal: false });
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
render() {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { split, themePreferences, theme } = this.state;
|
2019-11-25 20:01:17 +00:00
|
|
|
|
|
|
|
let content = (
|
|
|
|
<App
|
|
|
|
ref={(navigatorRef) => {
|
|
|
|
Navigation.setTopLevelNavigator(navigatorRef);
|
|
|
|
}}
|
2019-12-04 16:39:53 +00:00
|
|
|
screenProps={{ split, theme }}
|
2019-11-25 20:01:17 +00:00
|
|
|
onNavigationStateChange={onNavigationStateChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isTablet) {
|
|
|
|
const { inside, showModal } = this.state;
|
|
|
|
content = (
|
|
|
|
<SplitContext.Provider value={{ split }}>
|
|
|
|
<Tablet
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-11-25 20:01:17 +00:00
|
|
|
tablet={split}
|
|
|
|
inside={inside}
|
|
|
|
showModal={showModal}
|
|
|
|
closeModal={this.closeModal}
|
|
|
|
onLayout={this.onLayout}
|
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</Tablet>
|
|
|
|
</SplitContext.Provider>
|
|
|
|
);
|
|
|
|
}
|
2019-03-18 18:52:38 +00:00
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<AppearanceProvider>
|
|
|
|
<Provider store={store}>
|
|
|
|
<ThemeContext.Provider
|
|
|
|
value={{
|
|
|
|
theme,
|
|
|
|
themePreferences,
|
|
|
|
setTheme: this.setTheme
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</ThemeContext.Provider>
|
|
|
|
</Provider>
|
|
|
|
</AppearanceProvider>
|
2019-03-18 18:52:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|