mattermost-mobile/app/hooks/navigation_button_pressed.ts
Pablo Vélez 8b9779d4b3
MM-56899 - prevent app block when setting custom status if no internet (#8283)
* MM-56899 - prevent app block when setting custom status if no internet

* remove alert and use build in error message

* remove unused translations

* implement pr feedback

* keep function in local file

* remove unnecessary change

* fix placeholder position

* block the done button while the server replies

* add close button to the modal
2024-12-05 15:53:54 -05:00

24 lines
852 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {type DependencyList, type EffectCallback, useEffect} from 'react';
import {Navigation} from 'react-native-navigation';
type Callback = EffectCallback | (() => Promise<void>);
const useNavButtonPressed = (navButtonId: string, componentId: string, callback: Callback, deps?: DependencyList) => {
useEffect(() => {
const unsubscribe = Navigation.events().registerComponentListener({
navigationButtonPressed: ({buttonId}: { buttonId: string }) => {
if (buttonId === navButtonId) {
callback();
}
},
}, componentId);
return () => {
unsubscribe.remove();
};
}, deps);
};
export default useNavButtonPressed;