2018-08-10 17:26:36 +00:00
|
|
|
import React from 'react';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2020-02-28 14:13:36 +00:00
|
|
|
View, Text, Image, TouchableOpacity, BackHandler, Linking
|
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';
|
2020-03-26 18:20:26 +00:00
|
|
|
import { SafeAreaView, ScrollView } from 'react-navigation';
|
2019-03-12 16:23:06 +00:00
|
|
|
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';
|
2020-03-26 16:00:39 +00:00
|
|
|
import Button from '../../containers/Button';
|
2018-08-10 17:26:36 +00:00
|
|
|
import styles from './styles';
|
2019-11-25 20:01:17 +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';
|
2020-03-26 18:20:26 +00:00
|
|
|
import AppVersion from '../../containers/AppVersion';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
2019-11-25 20:01:17 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2020-03-26 18:20:26 +00:00
|
|
|
import FormContainer from '../../containers/FormContainer';
|
2018-08-10 17:26:36 +00:00
|
|
|
|
2019-08-07 13:51:34 +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-04 16:39:53 +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-11-25 20:01:17 +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-04 16:39:53 +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
|
|
|
}
|
|
|
|
|
2020-02-28 14:13:36 +00:00
|
|
|
createWorkspace = async() => {
|
|
|
|
try {
|
|
|
|
await Linking.openURL('https://cloud.rocket.chat/trial');
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
2018-08-10 17:26:36 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 14:18:32 +00:00
|
|
|
renderClose = () => {
|
2019-12-04 16:39:53 +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-04 16:39:53 +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-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2018-08-10 17:26:36 +00:00
|
|
|
return (
|
2020-03-26 18:20:26 +00:00
|
|
|
<FormContainer theme={theme}>
|
|
|
|
<View style={[sharedStyles.container, isTablet && sharedStyles.tabletScreenContent]}>
|
2020-03-26 16:00:39 +00:00
|
|
|
<Image style={styles.onboarding} source={{ uri: 'logo' }} fadeDuration={0} />
|
|
|
|
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('Onboarding_title')}</Text>
|
|
|
|
<Text style={[styles.subtitle, { color: themes[theme].controlText }]}>{I18n.t('Onboarding_subtitle')}</Text>
|
|
|
|
<Text style={[styles.description, { color: themes[theme].auxiliaryText }]}>{I18n.t('Onboarding_description')}</Text>
|
|
|
|
<View style={[styles.buttonsContainer]}>
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Onboarding_join_workspace')}
|
|
|
|
type='primary'
|
|
|
|
onPress={this.connectServer}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Create_a_new_workspace')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={themes[theme].chatComponentBackground}
|
|
|
|
onPress={this.createWorkspace}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
</View>
|
2018-08-10 17:26:36 +00:00
|
|
|
</View>
|
2020-03-26 18:20:26 +00:00
|
|
|
{/* {this.renderClose()} */}
|
|
|
|
</FormContainer>
|
2018-08-10 17:26:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +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-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(OnboardingView));
|