Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/a7medev/react-native-prevent-screenshots
Prevent Screenshots in your React Native app when needed. 🦄
https://github.com/a7medev/react-native-prevent-screenshots
react-native
Last synced: 6 days ago
JSON representation
Prevent Screenshots in your React Native app when needed. 🦄
- Host: GitHub
- URL: https://github.com/a7medev/react-native-prevent-screenshots
- Owner: a7medev
- License: mit
- Created: 2021-10-23T11:10:11.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-26T05:38:23.000Z (over 2 years ago)
- Last Synced: 2024-09-20T12:45:41.757Z (about 2 months ago)
- Topics: react-native
- Language: Java
- Homepage:
- Size: 663 KB
- Stars: 72
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# React Native Prevent Screenshots
Prevent Screenshots in your React Native app when needed. 🦄
## Installation
First, you need to install the package using the command above:
```sh
npm install react-native-prevent-screenshots --save
```Or if you're using Yarn:
```sh
yarn add react-native-prevent-screenshots
```### React Native <= 0.59
For React Native <= 0.59, there's no autolinking so you have to link the package using the command below:
```sh
react-native link react-native-prevent-screenshots
```### Expo Managed Workflow Support
In order to use `react-native-prevent-screenshots` with Expo you have to have native `android` folder in your app, fortunately you can do that easily without ejecting just by using this command:
```sh
expo run:android
```which will generate the `android` folder for you and allow you to use custom native code for android while still using Expo managed workflow.
> NOTE: you don't have to do the same for iOS because we use the React Native `AppState` JavaScript API on iOS.
## Usage
For iOS support you have to wrap the App component with the `withPreventScreenshots` call like this:
```js
import { withPreventScreenshots } from 'react-native-prevent-screenshots';function App() {
// ...
}export default withPreventScreenshots(App);
```Now, you can now call `PreventScreenshots.start()` and `PreventScreenshots.stop()` functions anywhere in your app to start/stop preventing screenshots.
```js
import { PreventScreenshots } from 'react-native-prevent-screenshots';// Prevent Screenshots (returns `Promise` of the prevention state)
PreventScreenshots.start();// Allow Screenshots (returns `Promise` of the prevention state)
PreventScreenshots.stop();
```