A simple implementation of FLAG_SECURE in Android and UIApplicationUserDidTakeScreenshotNotification IOS for prevent screenshots
npm install react-native-screenshot-prevention
cd ios && pod install
import { allowScreenCapture, preventScreenCapture, addScreenshotListener } from "react-native-screenshot-prevention";
// Enable screenshot (android only)
allowScreenCapture()
//Disable screenshot (android only)
preventScreenCapture()
useEffect(() => {
// Function to execute when user did a screenshot(ios only)
const onScreenshot = () => {
console.log("Hey, screenshot detected!")
}
// Its important have an "unsubscribe" to remove listener from screen is dismounted
const unsubscribe = addScreenshotListener(onScreenshot);
return () => {
unsubscribe()
}
}, [])
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT