react-native-screenshot-notifier
React-Native module for getting notified of screenshots on Android. (Not for iOS)
Installation
yarn add react-native-screenshot-notifierreact-native link react-native-screenshot-notifier
Best API: Hooks!
useScreenshotNotifier()
Returns array of id
, fileName
and path
of captured screenshot
Usage
const id fileName path = ;
Sample App
;;; { const id path fileName = ; return <View style=stylescontainer> <Text style=styleswelcome>Welcome to React Native!</Text> id ? <Text>`Screenshot Taken! : /`</Text> : <Text>NO screenshot taken... yet!</Text> </View> ;};const styles = StyleSheet;
useDisableScreenshots(disableScreenshots = true)
Disables screenshots (or turns them back on if disableScreenshots
is false
)
Usage
; // That's it.
Sample App
;;; { ; return <View style=stylescontainer> <Text style=styleswelcome>I dare you to screenshot me</Text> </View> ;};const styles = StyleSheet;
Low-Level API
async disableScreenshots()
Yes, it disables screenshots.
async enableScreenshots()
And it enables screenshots. Documentation FTW.
async getPermission()
Get permission to use the READ_EXTERNAL_STORAGE
API as required to detect screenshots.
async start(options)
Start listening for screenshots
async stop
Stop listening for screenshots
async addListener(func)
Add a callback for when a screenshot is returned
async removeListener(func)
Remove that listener by reference
async pause()
Very Low-Level - probably should not use
Pause screenshot listening (normally managed automatically by start
)
async resume()
Very Low-Level - probably should not use
Pause screenshot listening (normally managed automatically by start
)
Credit
This package depends on and embeds the great, terse ShotWatch library code.