Show toast when pressing back button on channel screen (#4384)

* MM-24328: Show Press again to exit toast when back button on Channel screeen is pressed.

* Fix feedbacks.

* Handle back press only for the Channel screen.

* MM-24328: Add a back press handler to share activity.

* Update the toast message as Press back again to exit.
This commit is contained in:
sowmiyamuthuraman 2020-07-09 03:31:13 +05:30 committed by GitHub
parent 2bf65491be
commit e754e861a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View file

@ -17,4 +17,9 @@ public class ShareActivity extends ReactActivity {
MainApplication app = (MainApplication) this.getApplication();
app.sharedExtensionIsOpened = true;
}
@Override
public void onBackPressed() {
finish();
}
}

View file

@ -2,7 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
import {StyleSheet, View} from 'react-native';
import {StyleSheet, View, BackHandler, ToastAndroid} from 'react-native';
import {openMainSideMenu, openSettingsSideMenu} from '@actions/navigation';
import LocalConfig from '@assets/config';
@ -12,12 +12,15 @@ import NetworkIndicator from '@components/network_indicator';
import PostDraft from '@components/post_draft';
import {NavigationTypes} from '@constants';
import EventEmitter from '@mm-redux/utils/event_emitter';
import EphemeralStore from '@store/ephemeral_store';
import ChannelNavBar from './channel_nav_bar';
import ChannelPostList from './channel_post_list';
import ChannelBase, {ClientUpgradeListener} from './channel_base';
let backPressedCount = 0;
export default class ChannelAndroid extends ChannelBase {
openMainSidebar = () => {
EventEmitter.emit(NavigationTypes.BLUR_POST_DRAFT);
@ -29,6 +32,33 @@ export default class ChannelAndroid extends ChannelBase {
openSettingsSideMenu();
};
componentDidMount() {
super.componentDidMount();
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}
handleBackPress = () => {
if (!backPressedCount && EphemeralStore.getNavigationTopComponentId() === 'Channel') {
const {formatMessage} = this.context.intl;
backPressedCount++;
ToastAndroid.show(formatMessage({
id: 'mobile.android.back_handler_exit',
defaultMessage: 'Press back again to exit',
}), ToastAndroid.SHORT);
setTimeout(() => {
backPressedCount = 0;
}, 2000);
return true;
}
backPressedCount = 0;
return false;
};
componentWillUnmount() {
super.componentWillUnmount();
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}
render() {
const {theme} = this.props;
let component = this.renderLoadingOrFailedChannel();

View file

@ -140,6 +140,7 @@
"mobile.advanced_settings.timezone": "Timezone",
"mobile.advanced_settings.title": "Advanced Settings",
"mobile.alert_dialog.alertCancel": "Cancel",
"mobile.android.back_handler_exit": "Press back again to exit",
"mobile.android.photos_permission_denied_description": "Upload photos to your Mattermost instance or save them to your device. Open Settings to grant Mattermost Read and Write access to your photo library.",
"mobile.android.photos_permission_denied_title": "{applicationName} would like to access your photos",
"mobile.android.videos_permission_denied_description": "Upload videos to your Mattermost instance or save them to your device. Open Settings to grant Mattermost Read and Write access to your video library.",