forked from Ivasoft/mattermost-mobile
* Add terms of service * Add i18n * Fix test * Address feedback * Address ux feedback * Update texts * Avoid Review to show on top of ToS Co-authored-by: Daniel Espino <danielespino@MacBook-Pro-de-Daniel.local>
27 lines
773 B
TypeScript
27 lines
773 B
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {useEffect} from 'react';
|
|
import {BackHandler} from 'react-native';
|
|
|
|
import NavigationStore from '@store/navigation_store';
|
|
|
|
const useAndroidHardwareBackHandler = (componentId: string, callback: () => void) => {
|
|
useEffect(() => {
|
|
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
if (NavigationStore.getNavigationTopComponentId() === componentId) {
|
|
callback();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
return () => {
|
|
backHandler.remove();
|
|
};
|
|
}, [componentId]);
|
|
};
|
|
|
|
export default useAndroidHardwareBackHandler;
|