BlueWallet/hooks/usePrivacy.ios.tsx

36 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-04-18 03:05:48 +02:00
import { useEffect, useCallback } from 'react';
// @ts-ignore: react-native-obscure is not in the type definition
import { enabled } from 'react-native-privacy-snapshot';
2024-04-18 03:05:48 +02:00
import { useSettings } from '../components/Context/SettingsContext';
export const usePrivacy = () => {
2024-04-18 03:05:48 +02:00
const { isPrivacyBlurEnabled } = useSettings();
const enableBlur = useCallback(() => {
if (!isPrivacyBlurEnabled) return;
enabled(true);
}, [isPrivacyBlurEnabled]);
const disableBlur = useCallback(() => {
enabled(false);
}, []); // 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;