mattermost-mobile/app/components/root/root.js
Miguel Alatzar 5eee2b7652
[MM-16139] [MM-16140] [MM-16141] Update the remaining screens/components (#2920)
* Update screens

* Update login tests

* Remove done

* Fix failing tests

* Update screens and components

* Check styles fix

* Update tests

* Prevent setState call after component unmounts

* Add empty setButtons func to dummy navigator

* Remove platform check

* Remove Platform import

* Update react-native-navigation version

* Add separate showModalOverCurrentContext function

* check-style fixes

* Remove overriding of AppDelegate's window

* Fix modal over current context animation

* Add showSearchModal navigation action

* Check-style fix

* Address review comments

* Update SettingsSidebar and children

* Update EditProfile screen

* Update SettingsSidebar

* Keep track of latest componentId to appear

* Track componentId in state to use in navigation actions

* Update FlaggedPosts and children

* Update RecentMentions

* Update Settings

* Store componentIds in ephemeral store

* Update AttachmentButton

* Remove unnecessary dismissModal

* Fix typo

* Upate NotificationSettings

* Update NotificationSettingsAutoResponder

* Update NotificationSettingsMentions

* Update NotificationSettingsMobile

* Update CreateChannel and children

* Update MoreChannels

* Update ChannelPeek and children

* Update ChannelNavBar and children

* Update ChannelPostList and children

* Update ChannelInfo and children

* Update ChannelAddMembers

* Update ChannelMembers

* Update EditChannel

* Fix setting of top bar buttons

* Update Channel screen and children

* Update PinnedPosts

* Update LongPost

* Update PostOptions

* Update PostTextboxBase

* Update EditPost

* Check-styles fix

* Update DisplaySettings

* Update Timezone

* Update SelectTimezone

* Update IntlWrapper and Notification

* Update InteractiveDialog and children

* Update ExpandedAnnouncementBanner

* Update ClientUpgradeListener

* Update MoreDirectMessages

* Update SelectorScreen

* Update UserProfile

* Update Thread

* Update About

* Update ImagePreview

* Update TextPreview

* Update AddReaction

* Update ReactionList and children

* Update Code

* Update TermsOfService

* Update Permalink

* Update Permalink

* Update ErrorTeamsList

* Update Search

* Remove navigator prop

* Fix setButtons calls

* Remove navigationComponentId

* Fix test

* Handle in-app notifs in global event handler

* Fix in-app notification handling

* Fix typo

* Fix tests

* Auto dismiss in-app notif after 5 seconds

* Fix typo

* Update overlay dismissal

* Animate in-app notif dismissal and allow gesture dismissal
2019-07-08 10:03:31 -07:00

112 lines
3.5 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {IntlProvider} from 'react-intl';
import {Platform} from 'react-native';
import {Client4} from 'mattermost-redux/client';
import EventEmitter from 'mattermost-redux/utils/event_emitter';
import {NavigationTypes} from 'app/constants';
import {getTranslations} from 'app/i18n';
export default class Root extends PureComponent {
static propTypes = {
actions: PropTypes.shape({
resetToTeams: PropTypes.func.isRequired,
}).isRequired,
children: PropTypes.node,
excludeEvents: PropTypes.bool,
currentUrl: PropTypes.string,
locale: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
};
componentWillMount() {
Client4.setAcceptLanguage(this.props.locale);
if (!this.props.excludeEvents) {
EventEmitter.on(NavigationTypes.NAVIGATION_NO_TEAMS, this.handleNoTeams);
EventEmitter.on(NavigationTypes.NAVIGATION_ERROR_TEAMS, this.errorTeamsList);
}
}
componentDidUpdate(prevProps) {
if (prevProps.locale !== this.props.locale) {
Client4.setAcceptLanguage(this.props.locale);
}
}
componentWillUnmount() {
if (!this.props.excludeEvents) {
EventEmitter.off(NavigationTypes.NAVIGATION_NO_TEAMS, this.handleNoTeams);
EventEmitter.off(NavigationTypes.NAVIGATION_ERROR_TEAMS, this.errorTeamsList);
}
}
handleNoTeams = () => {
if (!this.refs.provider) {
setTimeout(this.handleNoTeams, 200);
return;
}
this.navigateToTeamsPage('SelectTeam');
};
errorTeamsList = () => {
if (!this.refs.provider) {
setTimeout(this.errorTeamsList, 200);
return;
}
this.navigateToTeamsPage('ErrorTeamsList');
}
navigateToTeamsPage = (screen) => {
const {currentUrl, theme, actions} = this.props;
const {intl} = this.refs.provider.getChildContext();
let passProps = {theme};
const options = {topBar: {}};
if (Platform.OS === 'android') {
options.topBar.rightButtons = [{
id: 'logout',
text: intl.formatMessage({id: 'sidebar_right_menu.logout', defaultMessage: 'Logout'}),
color: theme.sidebarHeaderTextColor,
showAsAction: 'always',
}];
} else {
options.topBar.leftButtons = [{
id: 'logout',
text: intl.formatMessage({id: 'sidebar_right_menu.logout', defaultMessage: 'Logout'}),
color: theme.sidebarHeaderTextColor,
}];
}
if (screen === 'SelectTeam') {
passProps = {
...passProps,
currentUrl,
userWithoutTeams: true,
};
}
const title = intl.formatMessage({id: 'mobile.routes.selectTeam', defaultMessage: 'Select Team'});
actions.resetToTeams(screen, title, passProps, options);
}
render() {
const locale = this.props.locale;
return (
<IntlProvider
ref='provider'
locale={locale}
messages={getTranslations(locale)}
>
{this.props.children}
</IntlProvider>
);
}
}