mattermost-mobile/app/scenes/root/root.js
Chris Duarte 396bac389f Plt 5944 portait view (#393)
* PLT-5499 RN: Only allow portrait view

* Added library

* Lock to portait

* Fixed upload preview hiding under text input

* Fixed create channel input borders

* Fixed color separators in channel list

* Fixing orientation for android
2017-03-24 13:41:20 -03:00

87 lines
2.8 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React, {PropTypes, PureComponent} from 'react';
import {AsyncStorage} from 'react-native';
import Orientation from 'react-native-orientation';
import Loading from 'app/components/loading';
import {RequestStatus} from 'mattermost-redux/constants';
export default class Root extends PureComponent {
static propTypes = {
credentials: PropTypes.object,
logoutRequest: PropTypes.object,
loginRequest: PropTypes.object,
actions: PropTypes.shape({
goToLoadTeam: PropTypes.func,
goToSelectServer: PropTypes.func,
handleServerUrlChanged: PropTypes.func.isRequired,
loadStorage: PropTypes.func,
removeStorage: PropTypes.func,
setStoreFromLocalData: PropTypes.func
}).isRequired
};
static navigationProps = {
hideNavBar: true
};
componentDidMount() {
Orientation.lockToPortrait();
// Any initialization logic for navigation, setting up the client, etc should go here
this.init();
}
componentWillReceiveProps(nextProps) {
if (this.props.logoutRequest.status === RequestStatus.STARTED &&
nextProps.logoutRequest.status === RequestStatus.SUCCESS) {
this.props.actions.removeStorage();
} else if (this.props.logoutRequest.status === RequestStatus.SUCCESS &&
nextProps.logoutRequest.status === RequestStatus.NOT_STARTED) {
this.init();
}
}
init = () => {
if (this.props.logoutRequest.status === RequestStatus.SUCCESS) {
this.props.actions.removeStorage().then(() => {
setTimeout(this.loadStoreAndScene, 1000);
});
} else {
this.loadStoreAndScene();
}
};
loadStoreAndScene = () => {
this.props.actions.loadStorage().then(() => {
if (this.props.credentials.token && this.props.credentials.url) {
this.props.actions.setStoreFromLocalData(this.props.credentials).then(() => {
if (this.props.loginRequest.status === RequestStatus.SUCCESS) {
this.props.actions.goToLoadTeam();
} else {
this.selectServer();
}
});
} else {
this.selectServer();
}
});
};
selectServer = async () => {
const storage = await AsyncStorage.getItem('storage');
if (storage) {
const {url} = JSON.parse(await AsyncStorage.getItem('storage'));
if (url) {
await this.props.actions.handleServerUrlChanged(url);
}
}
this.props.actions.goToSelectServer();
};
render() {
return <Loading/>;
}
}