mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { useEffect, useCallback } from 'react';
|
|
// @ts-ignore: react-native-obscure is not in the type definition
|
|
import Obscure from 'react-native-obscure';
|
|
import { useSettings } from './context/useSettings';
|
|
|
|
export const usePrivacy = () => {
|
|
const { isPrivacyBlurEnabled } = useSettings();
|
|
|
|
const enableBlur = useCallback(() => {
|
|
if (!isPrivacyBlurEnabled) return;
|
|
Obscure.activateObscure();
|
|
}, [isPrivacyBlurEnabled]);
|
|
|
|
const disableBlur = useCallback(() => {
|
|
Obscure.deactivateObscure();
|
|
}, []); // This doesn't depend on the isPrivacyBlurEnabled value
|
|
|
|
useEffect(() => {
|
|
// Automatically activate or deactivate on mount and when isPrivacyBlurEnabled changes
|
|
if (isPrivacyBlurEnabled) {
|
|
enableBlur();
|
|
} else {
|
|
disableBlur();
|
|
}
|
|
|
|
// Cleanup function to deactivate obscure when the component unmounts
|
|
return () => {
|
|
disableBlur();
|
|
};
|
|
}, [isPrivacyBlurEnabled, enableBlur, disableBlur]);
|
|
|
|
return { enableBlur, disableBlur };
|
|
};
|
|
|
|
export default usePrivacy;
|