verdnatura-chat/app/index.js

83 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-08-22 01:24:41 +00:00
import PropTypes from 'prop-types';
2017-08-21 00:11:46 +00:00
import React from 'react';
import { View, Image } from 'react-native';
2017-08-21 00:11:46 +00:00
import { connect } from 'react-redux';
import * as Animatable from 'react-native-animatable';
2017-08-21 00:11:46 +00:00
import setNavigator from './actions/navigator';
import { appInit } from './actions';
2017-08-21 00:11:46 +00:00
import LoginView from './views/login';
import ListServerView from './views/serverList';
import styles from './views/Styles';
2017-08-21 00:11:46 +00:00
import store from './lib/createStore';
export const authenticated = WrappedComponent => class _p extends React.PureComponent {
constructor() {
super();
this.login = store.getState().login;
if (!this.login.token || this.login.failure) {
return store.getState().navigator.resetTo({
screen: 'Login',
animated: false
2017-08-21 00:11:46 +00:00
});
}
}
render() {
// Wraps the input component in a container, without mutating it. Good!
return ((this.login.isAuthenticated || this.login.user) && <WrappedComponent {...this.props} />);
2017-08-21 00:11:46 +00:00
}
};
//
export class PublicScreen extends React.PureComponent {
render() {
return ((this.login.isAuthenticated || this.login.user) && <ListServerView {...this.props} />);
2017-08-21 00:11:46 +00:00
}
}
@connect(null, dispatch => ({
setNavigator: navigator => dispatch(setNavigator(navigator))
}))
export class PrivateScreen extends React.PureComponent {
render() {
return (<LoginView {...this.props} />);
}
}
2017-08-22 01:24:41 +00:00
@connect(() => ({
2017-08-21 00:11:46 +00:00
// logged: state.login.isAuthenticated
}), dispatch => ({
setNavigator: navigator => dispatch(setNavigator(navigator)),
appInit: () => dispatch(appInit())
2017-08-21 00:11:46 +00:00
}))
export const HomeScreen = class extends React.PureComponent {
2017-08-22 01:24:41 +00:00
static propTypes = {
appInit: PropTypes.func.isRequired,
setNavigator: PropTypes.func.isRequired,
2017-08-22 01:24:41 +00:00
navigator: PropTypes.object.isRequired
}
static navigatorStyle = {
navBarHidden: true,
2017-08-22 01:24:41 +00:00
rightButtons: [{
id: 'close',
title: 'Cancel'
}]
};
2017-08-21 00:11:46 +00:00
componentWillMount() {
this.props.setNavigator(this.props.navigator);
this.props.appInit();
//
// this.props.navigator.setDrawerEnabled({
// side: 'left', // the side of the drawer since you can have two, 'left' / 'right'
// enabled: false // should the drawer be enabled or disabled (locked closed)
// });
2017-08-21 00:11:46 +00:00
}
render() {
return (<View style={styles.logoContainer}><Animatable.Text animation='pulse' easing='ease-out' iterationCount='infinite' style={{ textAlign: 'center' }}>
<Image style={styles.logo} source={require('./images/logo.png')} />
</Animatable.Text></View>);
2017-08-21 00:11:46 +00:00
}
};