* Renamed layouts/root_layout to components/root * Added KeyboardLayout to automatically use a KeyboardAvoidingView when necessary
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import React from 'react';
|
|
import {AppState} from 'react-native';
|
|
import {getTranslations} from 'service/i18n';
|
|
import {IntlProvider} from 'react-intl';
|
|
|
|
export default class Root extends React.Component {
|
|
static propTypes = {
|
|
children: React.PropTypes.node,
|
|
locale: React.PropTypes.string.isRequired,
|
|
actions: React.PropTypes.shape({
|
|
setAppState: React.PropTypes.func
|
|
}).isRequired
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.handleAppStateChange = this.handleAppStateChange.bind(this);
|
|
|
|
this.props.actions.setAppState(AppState.currentState === 'active');
|
|
}
|
|
|
|
componentDidMount() {
|
|
AppState.addEventListener('change', this.handleAppStateChange);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
AppState.removeEventListener('change', this.handleAppStateChange);
|
|
}
|
|
|
|
handleAppStateChange(appState) {
|
|
this.props.actions.setAppState(appState === 'active');
|
|
}
|
|
|
|
render() {
|
|
const locale = this.props.locale;
|
|
|
|
return (
|
|
<IntlProvider
|
|
locale={locale}
|
|
messages={getTranslations(locale)}
|
|
>
|
|
{this.props.children}
|
|
</IntlProvider>
|
|
);
|
|
}
|
|
}
|