2018-08-10 17:26:36 +00:00
|
|
|
import React from 'react';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2018-11-27 19:40:53 +00:00
|
|
|
View, Text, Image, TouchableOpacity, BackHandler
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2018-08-10 17:26:36 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { SafeAreaView } from 'react-navigation';
|
|
|
|
import Orientation from 'react-native-orientation-locker';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
import { selectServerRequest, serverInitAdd, serverFinishAdd } from '../../actions/server';
|
2018-11-27 19:40:53 +00:00
|
|
|
import { appStart as appStartAction } from '../../actions';
|
2018-08-10 17:26:36 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import openLink from '../../utils/openLink';
|
|
|
|
import Button from './Button';
|
|
|
|
import styles from './styles';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { isIOS, isNotch, isTablet } from '../../utils/deviceInfo';
|
2018-10-23 21:39:48 +00:00
|
|
|
import EventEmitter from '../../utils/events';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import sharedStyles from '../Styles';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2019-08-20 19:24:22 +00:00
|
|
|
class OnboardingView extends React.Component {
|
2019-03-12 16:23:06 +00:00
|
|
|
static navigationOptions = () => ({
|
|
|
|
header: null
|
|
|
|
})
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
static propTypes = {
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2018-09-19 14:18:32 +00:00
|
|
|
adding: PropTypes.bool,
|
|
|
|
selectServer: PropTypes.func.isRequired,
|
|
|
|
currentServer: PropTypes.string,
|
|
|
|
initAdd: PropTypes.func,
|
2018-11-27 19:40:53 +00:00
|
|
|
finishAdd: PropTypes.func,
|
2019-12-11 23:01:12 +00:00
|
|
|
appStart: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2018-11-27 19:40:53 +00:00
|
|
|
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
|
2019-03-12 16:23:06 +00:00
|
|
|
this.previousServer = props.navigation.getParam('previousServer');
|
2019-12-11 23:01:12 +00:00
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.lockToPortrait();
|
|
|
|
}
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
componentDidMount() {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { initAdd } = this.props;
|
|
|
|
if (this.previousServer) {
|
2018-09-19 14:18:32 +00:00
|
|
|
initAdd();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
EventEmitter.addEventListener('NewServer', this.handleNewServerEvent);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
const { theme } = this.props;
|
|
|
|
if (theme !== nextProps.theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
const {
|
2019-03-12 16:23:06 +00:00
|
|
|
selectServer, currentServer, adding, finishAdd
|
2018-09-19 14:18:32 +00:00
|
|
|
} = this.props;
|
|
|
|
if (adding) {
|
2019-03-12 16:23:06 +00:00
|
|
|
if (this.previousServer !== currentServer) {
|
|
|
|
selectServer(this.previousServer);
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
finishAdd();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
EventEmitter.removeListener('NewServer', this.handleNewServerEvent);
|
2018-11-27 19:40:53 +00:00
|
|
|
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackPress = () => {
|
|
|
|
const { appStart } = this.props;
|
|
|
|
appStart('background');
|
|
|
|
return false;
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close = () => {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { appStart } = this.props;
|
|
|
|
appStart('inside');
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
newServer = (server) => {
|
2019-03-12 16:23:06 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('NewServerView', { server });
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
handleNewServerEvent = (event) => {
|
|
|
|
const { server } = event;
|
|
|
|
this.newServer(server);
|
|
|
|
}
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
connectServer = () => {
|
|
|
|
this.newServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
joinCommunity = () => {
|
|
|
|
this.newServer('https://open.rocket.chat');
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createWorkspace = () => {
|
2019-12-11 23:01:12 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
openLink('https://cloud.rocket.chat/trial', theme);
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
renderClose = () => {
|
2019-12-11 23:01:12 +00:00
|
|
|
const { theme } = this.props;
|
2019-03-12 16:23:06 +00:00
|
|
|
if (this.previousServer) {
|
2018-09-19 14:18:32 +00:00
|
|
|
let top = 15;
|
2019-01-29 19:52:56 +00:00
|
|
|
if (isIOS) {
|
|
|
|
top = isNotch ? 45 : 30;
|
2018-09-19 14:18:32 +00:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
style={[styles.closeModal, { top }]}
|
|
|
|
onPress={this.close}
|
2018-09-25 19:28:42 +00:00
|
|
|
testID='onboarding-close'
|
2018-09-19 14:18:32 +00:00
|
|
|
>
|
2019-03-01 16:49:11 +00:00
|
|
|
<CustomIcon
|
|
|
|
name='cross'
|
2018-09-19 14:18:32 +00:00
|
|
|
size={30}
|
2019-12-11 23:01:12 +00:00
|
|
|
color={themes[theme].actionTintColor}
|
2018-09-19 14:18:32 +00:00
|
|
|
/>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:26:36 +00:00
|
|
|
render() {
|
2019-12-11 23:01:12 +00:00
|
|
|
const { theme } = this.props;
|
2018-08-10 17:26:36 +00:00
|
|
|
return (
|
2019-12-11 23:01:12 +00:00
|
|
|
<SafeAreaView
|
|
|
|
style={[
|
|
|
|
styles.container,
|
|
|
|
{ backgroundColor: themes[theme].backgroundColor }
|
|
|
|
]}
|
|
|
|
testID='onboarding-view'
|
|
|
|
>
|
|
|
|
<StatusBar theme={theme} />
|
2018-11-14 21:42:03 +00:00
|
|
|
<Image style={styles.onboarding} source={{ uri: 'onboarding' }} fadeDuration={0} />
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('Welcome_to_RocketChat')}</Text>
|
|
|
|
<Text style={[styles.subtitle, { color: themes[theme].auxiliaryText }]}>{I18n.t('Open_Source_Communication')}</Text>
|
|
|
|
<View style={[styles.buttonsContainer, isTablet && sharedStyles.tabletScreenContent]}>
|
2018-08-10 17:26:36 +00:00
|
|
|
<Button
|
|
|
|
type='secondary'
|
|
|
|
title={I18n.t('Connect_to_a_server')}
|
2019-12-11 23:01:12 +00:00
|
|
|
icon={<CustomIcon name='permalink' size={30} color={themes[theme].actionTintColor} />}
|
2018-08-10 17:26:36 +00:00
|
|
|
onPress={this.connectServer}
|
|
|
|
testID='connect-server-button'
|
2019-12-11 23:01:12 +00:00
|
|
|
theme={theme}
|
2018-08-10 17:26:36 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type='secondary'
|
|
|
|
title={I18n.t('Join_the_community')}
|
|
|
|
subtitle='open.rocket.chat'
|
2018-11-14 21:42:03 +00:00
|
|
|
icon={<Image source={{ uri: 'logo_onboarding' }} style={{ width: 32, height: 27 }} fadeDuration={0} />}
|
2018-08-10 17:26:36 +00:00
|
|
|
onPress={this.joinCommunity}
|
|
|
|
testID='join-community-button'
|
2019-12-11 23:01:12 +00:00
|
|
|
theme={theme}
|
2018-08-10 17:26:36 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type='primary'
|
|
|
|
title={I18n.t('Create_a_new_workspace')}
|
2019-12-11 23:01:12 +00:00
|
|
|
icon={<CustomIcon name='plus' size={30} color={themes[theme].buttonText} />}
|
2018-08-10 17:26:36 +00:00
|
|
|
onPress={this.createWorkspace}
|
|
|
|
testID='create-workspace-button'
|
2019-12-11 23:01:12 +00:00
|
|
|
theme={theme}
|
2018-08-10 17:26:36 +00:00
|
|
|
/>
|
|
|
|
</View>
|
2018-09-19 14:18:32 +00:00
|
|
|
{this.renderClose()}
|
2018-08-10 17:26:36 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-20 19:24:22 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
currentServer: state.server.server,
|
|
|
|
adding: state.server.adding
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
initAdd: () => dispatch(serverInitAdd()),
|
|
|
|
finishAdd: () => dispatch(serverFinishAdd()),
|
|
|
|
selectServer: server => dispatch(selectServerRequest(server)),
|
|
|
|
appStart: root => dispatch(appStartAction(root))
|
|
|
|
});
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(OnboardingView));
|