2019-03-12 16:23:06 +00:00
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
createStackNavigator, createAppContainer, createSwitchNavigator, createDrawerNavigator
|
|
|
|
} from 'react-navigation';
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { useScreens } from 'react-native-screens'; // eslint-disable-line import/no-unresolved
|
2019-01-29 19:52:56 +00:00
|
|
|
import { Linking } from 'react-native';
|
2019-05-28 13:03:08 +00:00
|
|
|
import firebase from 'react-native-firebase';
|
2019-06-10 16:23:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-09-01 19:42:50 +00:00
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
import { appInit } from './actions';
|
2018-07-10 13:40:32 +00:00
|
|
|
import { deepLinkingOpen } from './actions/deepLinking';
|
2019-03-12 16:23:06 +00:00
|
|
|
import OnboardingView from './views/OnboardingView';
|
|
|
|
import NewServerView from './views/NewServerView';
|
|
|
|
import LoginSignupView from './views/LoginSignupView';
|
|
|
|
import AuthLoadingView from './views/AuthLoadingView';
|
|
|
|
import RoomsListView from './views/RoomsListView';
|
|
|
|
import RoomView from './views/RoomView';
|
|
|
|
import NewMessageView from './views/NewMessageView';
|
2019-06-10 16:22:35 +00:00
|
|
|
import DirectoryView from './views/DirectoryView';
|
2019-03-12 16:23:06 +00:00
|
|
|
import LoginView from './views/LoginView';
|
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';
|
|
|
|
import ProfileView from './views/ProfileView';
|
|
|
|
import SettingsView from './views/SettingsView';
|
2019-05-18 19:31:33 +00:00
|
|
|
import AdminPanelView from './views/AdminPanelView';
|
2019-03-12 16:23:06 +00:00
|
|
|
import RoomActionsView from './views/RoomActionsView';
|
|
|
|
import RoomInfoView from './views/RoomInfoView';
|
|
|
|
import RoomInfoEditView from './views/RoomInfoEditView';
|
|
|
|
import RoomMembersView from './views/RoomMembersView';
|
|
|
|
import SearchMessagesView from './views/SearchMessagesView';
|
2019-06-10 18:36:31 +00:00
|
|
|
import ReadReceiptsView from './views/ReadReceiptView';
|
2019-04-17 17:01:03 +00:00
|
|
|
import ThreadMessagesView from './views/ThreadMessagesView';
|
2019-05-10 17:09:07 +00:00
|
|
|
import MessagesView from './views/MessagesView';
|
2019-03-12 16:23:06 +00:00
|
|
|
import SelectedUsersView from './views/SelectedUsersView';
|
|
|
|
import CreateChannelView from './views/CreateChannelView';
|
|
|
|
import LegalView from './views/LegalView';
|
|
|
|
import ForgotPasswordView from './views/ForgotPasswordView';
|
|
|
|
import RegisterView from './views/RegisterView';
|
|
|
|
import OAuthView from './views/OAuthView';
|
|
|
|
import SetUsernameView from './views/SetUsernameView';
|
|
|
|
import { HEADER_BACKGROUND, HEADER_TITLE, HEADER_BACK } from './constants/colors';
|
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';
|
2017-08-21 00:11:46 +00:00
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
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\//, '');
|
|
|
|
const regex = /^(room|auth)\?/;
|
|
|
|
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
|
|
|
const defaultHeader = {
|
|
|
|
headerStyle: {
|
|
|
|
backgroundColor: HEADER_BACKGROUND
|
|
|
|
},
|
|
|
|
headerTitleStyle: {
|
|
|
|
color: HEADER_TITLE
|
|
|
|
},
|
|
|
|
headerBackTitle: null,
|
|
|
|
headerTintColor: HEADER_BACK
|
|
|
|
};
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
// Outside
|
|
|
|
const OutsideStack = createStackNavigator({
|
|
|
|
OnboardingView: {
|
|
|
|
screen: OnboardingView,
|
|
|
|
header: null
|
|
|
|
},
|
|
|
|
NewServerView,
|
|
|
|
LoginSignupView,
|
|
|
|
LoginView,
|
|
|
|
ForgotPasswordView,
|
2019-04-26 20:51:09 +00:00
|
|
|
RegisterView,
|
|
|
|
LegalView
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const OAuthStack = createStackNavigator({
|
|
|
|
OAuthView
|
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const OutsideStackModal = createStackNavigator({
|
|
|
|
OutsideStack,
|
|
|
|
OAuthStack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
|
|
|
headerMode: 'none'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Inside
|
|
|
|
const ChatsStack = createStackNavigator({
|
|
|
|
RoomsListView,
|
|
|
|
RoomView,
|
|
|
|
RoomActionsView,
|
|
|
|
RoomInfoView,
|
|
|
|
RoomInfoEditView,
|
|
|
|
RoomMembersView,
|
|
|
|
SearchMessagesView,
|
2019-04-17 17:01:03 +00:00
|
|
|
SelectedUsersView,
|
2019-05-10 17:09:07 +00:00
|
|
|
ThreadMessagesView,
|
2019-06-10 16:22:35 +00:00
|
|
|
MessagesView,
|
2019-06-10 18:36:31 +00:00
|
|
|
ReadReceiptsView,
|
2019-06-10 16:22:35 +00:00
|
|
|
DirectoryView
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-04-18 13:43:44 +00:00
|
|
|
ChatsStack.navigationOptions = ({ navigation }) => {
|
|
|
|
let drawerLockMode = 'unlocked';
|
|
|
|
if (navigation.state.index > 0) {
|
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const ProfileStack = createStackNavigator({
|
|
|
|
ProfileView
|
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
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({
|
|
|
|
SettingsView
|
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-05-18 19:31:33 +00:00
|
|
|
const AdminPanelStack = createStackNavigator({
|
|
|
|
AdminPanelView
|
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
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
|
|
|
}, {
|
|
|
|
contentComponent: Sidebar
|
|
|
|
});
|
|
|
|
|
|
|
|
const NewMessageStack = createStackNavigator({
|
|
|
|
NewMessageView,
|
|
|
|
SelectedUsersViewCreateChannel: SelectedUsersView,
|
|
|
|
CreateChannelView
|
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const InsideStackModal = createStackNavigator({
|
|
|
|
Main: ChatsDrawer,
|
|
|
|
NewMessageStack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
|
|
|
headerMode: 'none'
|
|
|
|
});
|
|
|
|
|
|
|
|
const SetUsernameStack = createStackNavigator({
|
|
|
|
SetUsernameView
|
|
|
|
});
|
|
|
|
|
2019-06-10 16:23:19 +00:00
|
|
|
class CustomInsideStack extends React.Component {
|
|
|
|
static router = InsideStackModal.router;
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<InsideStackModal navigation={navigation} />
|
|
|
|
<NotificationBadge navigation={navigation} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const App = createAppContainer(createSwitchNavigator(
|
|
|
|
{
|
|
|
|
OutsideStack: OutsideStackModal,
|
2019-06-10 16:23:19 +00:00
|
|
|
InsideStack: CustomInsideStack,
|
2019-03-12 16:23:06 +00:00
|
|
|
AuthLoading: AuthLoadingView,
|
|
|
|
SetUsernameStack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
initialRouteName: 'AuthLoading'
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
));
|
|
|
|
|
2019-05-28 13:03:08 +00:00
|
|
|
// gets the current screen from navigation state
|
|
|
|
const getActiveRouteName = (navigationState) => {
|
|
|
|
if (!navigationState) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const route = navigationState.routes[navigationState.index];
|
|
|
|
// dive into nested navigators
|
|
|
|
if (route.routes) {
|
|
|
|
return getActiveRouteName(route);
|
|
|
|
}
|
|
|
|
return route.routeName;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onNavigationStateChange = (prevState, currentState) => {
|
|
|
|
const currentScreen = getActiveRouteName(currentState);
|
|
|
|
const prevScreen = getActiveRouteName(prevState);
|
|
|
|
|
|
|
|
if (prevScreen !== currentScreen) {
|
|
|
|
firebase.analytics().setCurrentScreen(currentScreen);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
export default class Root extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.listenerTimeout = setTimeout(() => {
|
|
|
|
Linking.addEventListener('url', ({ url }) => {
|
|
|
|
const parsedDeepLinkingURL = parseDeepLinking(url);
|
|
|
|
if (parsedDeepLinkingURL) {
|
|
|
|
store.dispatch(deepLinkingOpen(parsedDeepLinkingURL));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearTimeout(this.listenerTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
init = async() => {
|
|
|
|
const [notification, deepLinking] = await Promise.all([initializePushNotifications(), Linking.getInitialURL()]);
|
|
|
|
const parsedDeepLinkingURL = parseDeepLinking(deepLinking);
|
|
|
|
if (notification) {
|
|
|
|
onNotification(notification);
|
|
|
|
} else if (parsedDeepLinkingURL) {
|
|
|
|
store.dispatch(deepLinkingOpen(parsedDeepLinkingURL));
|
|
|
|
} else {
|
|
|
|
store.dispatch(appInit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
|
|
|
<App
|
|
|
|
ref={(navigatorRef) => {
|
|
|
|
Navigation.setTopLevelNavigator(navigatorRef);
|
|
|
|
}}
|
2019-05-28 13:03:08 +00:00
|
|
|
onNavigationStateChange={onNavigationStateChange}
|
2019-03-18 18:52:38 +00:00
|
|
|
/>
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|