verdnatura-chat/app/views/OnboardingView/index.js

105 lines
2.8 KiB
JavaScript
Raw Normal View History

import React from 'react';
import {
View, Text, Image, BackHandler, Linking
} from 'react-native';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
2019-03-12 16:23:06 +00:00
import Orientation from 'react-native-orientation-locker';
import { appStart as appStartAction } from '../../actions';
import I18n from '../../i18n';
import Button from '../../containers/Button';
import styles from './styles';
import { isTablet } from '../../utils/deviceInfo';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
import { withTheme } from '../../theme';
import FormContainer, { FormContainerInner } from '../../containers/FormContainer';
class OnboardingView extends React.Component {
2019-03-12 16:23:06 +00:00
static navigationOptions = () => ({
header: null
})
static propTypes = {
2019-03-12 16:23:06 +00:00
navigation: PropTypes.object,
2019-12-04 16:39:53 +00:00
appStart: PropTypes.func,
theme: PropTypes.string
}
constructor(props) {
super(props);
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
2019-11-25 20:01:17 +00:00
if (!isTablet) {
Orientation.lockToPortrait();
}
}
2019-12-04 16:39:53 +00:00
shouldComponentUpdate(nextProps) {
const { theme } = this.props;
if (theme !== nextProps.theme) {
return true;
}
return false;
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress = () => {
const { appStart } = this.props;
appStart('background');
return false;
}
connectServer = () => {
const { navigation } = this.props;
navigation.navigate('NewServerView');
}
createWorkspace = async() => {
try {
await Linking.openURL('https://cloud.rocket.chat/trial');
} catch {
// do nothing
}
}
render() {
2019-12-04 16:39:53 +00:00
const { theme } = this.props;
return (
<FormContainer theme={theme} testID='onboarding-view'>
<FormContainerInner>
<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}
testID='join-workspace'
/>
<Button
title={I18n.t('Create_a_new_workspace')}
type='secondary'
backgroundColor={themes[theme].chatComponentBackground}
onPress={this.createWorkspace}
theme={theme}
testID='create-workspace-button'
/>
</View>
</FormContainerInner>
</FormContainer>
);
}
}
const mapDispatchToProps = dispatch => ({
appStart: root => dispatch(appStartAction(root))
});
export default connect(null, mapDispatchToProps)(withTheme(OnboardingView));