initSettings NEW ✨
Available from v2.0.0+
Initialize ScreenGuard with your desired settings. This function must be called before using any other ScreenGuard API.
Parameters
Accepted a JS object with following parameters:
| Name | Required | Type | Default |
|---|---|---|---|
| enableCapture | No | boolean | false |
| enableRecord | No | boolean | false |
| enableContentMultitask | No | boolean | false |
| displayScreenGuardOverlay | No | boolean | false |
| displayScreenguardOverlayAndroid | No | boolean | true |
| timeAfterResume | No | number | 1000 |
| getScreenshotPath | No | boolean | false |
| limitCaptureEvtCount | No | number | null |
| trackingLog | No | boolean | false |
enableCapture
| Type | boolean |
| Default | false |
| Platform | iOS, Android |
Enable to allow screenshot or disable it. Default is false (disabled).
enableRecord
| Type | boolean |
| Default | false |
| Platform | iOS 13+, Android 15+ (API 35+) |
Enable to allow screen recording or disable it. Default is false (disabled).
Screen recording detection on Android is only available on API 35+ (Android 15+). On older versions, this setting is ignored.
enableContentMultitask
| Type | boolean |
| Default | false |
| Platform | iOS only |
When set to true, your app content will remain visible in the App Switcher (multitasking view), and hidden/blurred based on the register type (color, blur, or image) when false.
displayScreenGuardOverlay
| Type | boolean |
| Default | false |
| Platform | iOS only |
When set to true, displays an overlay when user screenshot or screen record (show until user stop recording) and disapears after a duration of timeAfterResume. The overlay uses the same style as your registered (color, blur, or image).
Note: Use if is not affecting your app's functionality, and use at your own risk!
displayScreenguardOverlayAndroid
| Type | boolean |
| Default | true |
| Platform | Android only |
When set to true, displays an overlay when user returns to the app from background. Default is true (enabled).
timeAfterResume
| Type | number (milliseconds) |
| Default | 1000 |
| Platform | iOS, Android |
Duration in milliseconds to display the overlay after capture (iOS) or after returning from background (Android). Required displayScreenGuardOverlay or displayScreenguardOverlayAndroid to be true.
Example: Set to 2000 for a 2-second overlay display.
getScreenshotPath
| Type | boolean |
| Default | false |
| Platform | iOS, Android |
When set to true, the screenshot event data will include the file path to the captured screenshot.
Related: useSGScreenShot hook's screenshotData.path property.
limitCaptureEvtCount
| Type | number | null |
| Default | null |
| Platform | iOS, Android* |
Limit the number of screenshot capture events triggered.
nullor0: Trigger every time (unlimited)> 0: Only trigger for the first N screenshots
On Android, screenshot detection may not work while screenguard is active (FLAG_SECURE blocks standard screenshot attempts).
Related: Works with useSGScreenShot hook.
trackingLog
| Type | boolean |
| Default | false |
| Platform | iOS, Android |
Enable activity logging for debugging purposes. When enabled, ScreenGuard will record all events (activate, deactivate, screenshot detected, etc.).
Related: Use getScreenGuardLogs to retrieve recorded logs.
Example code
Basic initialization:
import ScreenGuardModule from 'react-native-screenguard';
// Initialize with default settings
await ScreenGuardModule.initSettings();
With custom settings:
import ScreenGuardModule from 'react-native-screenguard';
await ScreenGuardModule.initSettings({
displayScreenGuardOverlay: true,
timeAfterResume: 2000,
getScreenshotPath: true,
trackingLog: true,
});
- You must call
initSettings()before calling anyregister*function, otherwise an error will be thrown. - Always call this function at the app entry point (e.g.,
App.tsxorindex.js).