Web Analytics
Skip to main content

useSGScreenShot NEW ✨

Version

Available from v2.0.0+

A React hook for detecting screenshot events. Replaces registerScreenshotEventListener from v1.x.

Signature

function useSGScreenShot(
listener?: (event: ScreenGuardScreenShotPathDataObject) => void
): {
screenshotData: ScreenGuardScreenShotPathDataObject | null;
activationStatus: ScreenGuardHookData | null;
}

Parameters

NameRequiredTypeDescription
listenerNofunctionOptional callback function triggered on each screenshot event

Return Values

NameTypeDescription
screenshotDataobject | nullData about the last screenshot captured
activationStatusobject | nullCurrent activation status of ScreenGuard

screenshotData Object

interface ScreenGuardScreenShotPathDataObject {
path?: string;
name?: string;
type?: string;
}
FieldTypeDescription
pathstring | undefinedFull file path to the captured screenshot (e.g., /var/mobile/.../screenshot.png). Only available if getScreenshotPath: true in initSettings()
namestring | undefinedFile name of the screenshot (e.g., screenshot_2024.png)
typestring | undefinedFile extension/type (e.g., 'png', 'jpg')

activationStatus Object

interface ScreenGuardHookData {
method: string;
isActivated: boolean;
}
FieldTypeDescription
methodstringThe activation method currently active. Possible values: 'blur', 'image', 'color', '' (empty when not activated)
isActivatedbooleantrue if screenguard is currently activated, false otherwise

Example code

Basic usage with state:

import React from 'react';
import { View, Text } from 'react-native';
import ScreenGuardModule, { useSGScreenShot } from 'react-native-screenguard';

function App() {
const { screenshotData, activationStatus } = useSGScreenShot();

React.useEffect(() => {
// Initialize ScreenGuard
ScreenGuardModule.initSettings({
getScreenshotPath: true,
});
}, []);

return (
<View>
<Text>Activated: {activationStatus?.isActivated ? 'Yes' : 'No'}</Text>
{screenshotData && (
<Text>Last screenshot: {screenshotData.name}</Text>
)}
</View>
);
}

With callback listener:

import React from 'react';
import { Alert } from 'react-native';
import ScreenGuardModule, { useSGScreenShot } from 'react-native-screenguard';

function App() {
const { screenshotData } = useSGScreenShot((event) => {
// This callback fires on every screenshot
Alert.alert('Screenshot detected!', `File: ${event.name}`);
});

// ... rest of component
}

Notes

  • The hook automatically handles subscription cleanup when the component unmounts.
  • Use limitCaptureEvtCount in initSettings() to limit the number of screenshot events triggered:
    • null or 0: Trigger every time (default)
    • > 0: Only trigger for the first N screenshots
Android Limitation

Screenshot events may not be received while screenguard protection is active (FLAG_SECURE blocks standard screenshot attempts). However, events may still be received from third-party screenshot apps.

Demo