BlueWallet/hooks/usePrivacy.android.tsx
Marcos Rodriguez Velez 5a08b4ef63
Revert "wip"
This reverts commit fff04479a9.
2024-02-21 22:08:20 -04:00

36 lines
1.1 KiB
TypeScript

import { useContext, useEffect, useCallback } from 'react';
// @ts-ignore: react-native-obscure is not in the type definition
import Obscure from 'react-native-obscure';
import { BlueStorageContext } from '../blue_modules/storage-context';
export const usePrivacy = () => {
const { isPrivacyBlurEnabled } = useContext(BlueStorageContext);
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;