expo-screen-capture
allows you to protect screens in your app from being captured or recorded. The two most common reasons you may want to prevent screen capture are:android.media.projection
API allows third-party apps to perform screen capture or screen sharing (even if the app is backgrounded).Currently, taking screenshots on iOS cannot be prevented. This is due to underlying OS limitations.
Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
expo install expo-screen-capture
If you're installing this in a bare React Native app, you should also follow these additional installation instructions.
import { usePreventScreenCapture } from 'expo-screen-capture'; import React from 'react'; import { Text, View } from 'react-native'; export default function ScreenCaptureExample() { usePreventScreenCapture(); return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>As long as this component is mounted, this screen is unrecordable!</Text> </View> ); }
import * as ScreenCapture from 'expo-screen-capture'; import React from 'react'; import { Button, View, Platform } from 'react-native'; export default class ScreenCaptureExample extends React.Component { render() { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'space-around' }}> <Button title="Activate" onPress={this._activate} /> <Button title="Deactivate" onPress={this._deactivate} /> </View> ); } _activate = async () => { await ScreenCapture.preventScreenCaptureAsync(); }; _deactivate = async () => { await ScreenCapture.allowScreenCaptureAsync(); }; }
import { usePreventScreenCapture, preventScreenCaptureAsync, allowScreenCaptureAsync, } from 'expo-screen-capture';
preventScreenCaptureAsync
and allowScreenCaptureAsync
methods from conflicting with each other. This argument is useful if you have multiple active components using the allowScreenCaptureAsync
hook. Defaults to default
.allowScreenCaptureAsync
is called. If you are already preventing screen capture, this method does nothing (unless you pass a new and unique key
).preventScreenCaptureAsync
and allowScreenCaptureAsync
methods (and usePreventScreenCapture
hook) from conflicting with each other. When using multiple keys, you'll have to re-allow each one in order to re-enable screen capturing. Defaults to default
.preventScreenCaptureAsync()
yet, this method does nothingkey
passed to preventScreenCaptureAsync
in order to re-enable screen capturing.