react-native-screen-blocker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/README.md +105 -0
- package/android/build.gradle +36 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/screenblocker/ScreenBlockerModule.java +40 -0
- package/android/src/main/java/com/screenblocker/ScreenBlockerPackage.java +24 -0
- package/index.js +19 -0
- package/ios/ScreenBlockerModule.h +4 -0
- package/ios/ScreenBlockerModule.m +30 -0
- package/ios/react-native-screen-blocker.podspec +16 -0
- package/package.json +40 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.pbxproj -text
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# react-native-screen-blocker
|
|
2
|
+
|
|
3
|
+
React Native module to **block screenshots and screen recordings** on Android and iOS devices by leveraging native platform capabilities.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Features](#features)
|
|
10
|
+
- [Supported Platforms](#supported-platforms)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Usage](#usage)
|
|
13
|
+
- [API](#api)
|
|
14
|
+
- [Example](#example)
|
|
15
|
+
- [Contact](#contact)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Prevent screenshots and screen recordings at the OS level.
|
|
22
|
+
- Simple API to enable and disable protection dynamically.
|
|
23
|
+
- Supports React Native 0.60+ with automatic linking.
|
|
24
|
+
- Uses `FLAG_SECURE` on Android.
|
|
25
|
+
- Uses iOS 13+ `setSecure:` API with fallback options.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Supported Platforms
|
|
30
|
+
|
|
31
|
+
| Platform | Minimum Version | Notes |
|
|
32
|
+
| -------- | --------------- | -------------------------------- |
|
|
33
|
+
| Android | API 16+ | Uses `WindowManager.LayoutParams.FLAG_SECURE` |
|
|
34
|
+
| iOS | 11.0+ | iOS 13+ uses `setSecure:`; earlier iOS uses overlays and observers |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
1. Install via npm or yarn:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install react-native-screen-blocker
|
|
44
|
+
# or
|
|
45
|
+
yarn add react-native-screen-blocker
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. For iOS, install CocoaPods dependencies:
|
|
49
|
+
```bash
|
|
50
|
+
cd ios && pod install && cd ..
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. For React Native < 0.60, link manually:
|
|
54
|
+
```bash
|
|
55
|
+
react-native link react-native-screen-blocker
|
|
56
|
+
```
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
### Import the module
|
|
61
|
+
```bash
|
|
62
|
+
import { enableScreenBlock, disableScreenBlock } from 'react-native-screen-blocker';
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Enable SSL pinning
|
|
66
|
+
Call early in the app lifecycle.
|
|
67
|
+
```bash
|
|
68
|
+
enableScreenBlock();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Disable SSL pinning
|
|
72
|
+
```bash
|
|
73
|
+
disableScreenBlock();
|
|
74
|
+
```
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
| Method | Description | Returns |
|
|
80
|
+
|-----------|-----------------------------------------------------|---------------|
|
|
81
|
+
| `enableScreenBlock()` | Enables screenshot and screen recording protection | `Promise<void>` |
|
|
82
|
+
| `disableScreenBlock()` | Disables protection and allows screenshots/recordings | `Promise<void>` |
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Example
|
|
87
|
+
```bash
|
|
88
|
+
import React, { useEffect } from 'react';
|
|
89
|
+
import { enableScreenBlock, disableScreenBlock } from 'react-native-screen-blocker';
|
|
90
|
+
|
|
91
|
+
export default function App() {
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
enableScreenBlock();
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
// App JSX
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Contact
|
|
104
|
+
|
|
105
|
+
For questions or support, reach me at: [anweshan.mukherjee@pwc.com](mailto:anweshan.mukherjee@pwc.com)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
buildscript {
|
|
3
|
+
repositories {
|
|
4
|
+
jcenter()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath 'com.android.tools.build:gradle:1.3.1'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
apply plugin: 'com.android.library'
|
|
13
|
+
|
|
14
|
+
android {
|
|
15
|
+
compileSdkVersion 23
|
|
16
|
+
buildToolsVersion "23.0.1"
|
|
17
|
+
|
|
18
|
+
defaultConfig {
|
|
19
|
+
minSdkVersion 16
|
|
20
|
+
targetSdkVersion 22
|
|
21
|
+
versionCode 1
|
|
22
|
+
versionName "1.0"
|
|
23
|
+
}
|
|
24
|
+
lintOptions {
|
|
25
|
+
abortOnError false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
repositories {
|
|
30
|
+
mavenCentral()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
compile 'com.facebook.react:react-native:+'
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package com.screenblocker;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.view.Window;
|
|
5
|
+
import android.view.WindowManager;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
+
|
|
11
|
+
public class ScreenBlockerModule extends ReactContextBaseJavaModule {
|
|
12
|
+
|
|
13
|
+
public ScreenBlockerModule(ReactApplicationContext reactContext) {
|
|
14
|
+
super(reactContext);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
public String getName() {
|
|
19
|
+
return "ScreenBlockerModule";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@ReactMethod
|
|
23
|
+
public void enable() {
|
|
24
|
+
Activity activity = getCurrentActivity();
|
|
25
|
+
if (activity != null) {
|
|
26
|
+
Window window = activity.getWindow();
|
|
27
|
+
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE,
|
|
28
|
+
WindowManager.LayoutParams.FLAG_SECURE);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@ReactMethod
|
|
33
|
+
public void disable() {
|
|
34
|
+
Activity activity = getCurrentActivity();
|
|
35
|
+
if (activity != null) {
|
|
36
|
+
Window window = activity.getWindow();
|
|
37
|
+
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.screenblocker;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage;
|
|
4
|
+
import com.facebook.react.bridge.NativeModule;
|
|
5
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import java.util.ArrayList;
|
|
8
|
+
import java.util.Collections;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
public class ScreenBlockerPackage implements ReactPackage {
|
|
12
|
+
|
|
13
|
+
@Override
|
|
14
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
15
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
16
|
+
modules.add(new ScreenBlockerModule(reactContext));
|
|
17
|
+
return modules;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Override
|
|
21
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
22
|
+
return Collections.emptyList();
|
|
23
|
+
}
|
|
24
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const { ScreenBlockerModule } = NativeModules;
|
|
4
|
+
|
|
5
|
+
export function enableScreenBlock() {
|
|
6
|
+
if (!ScreenBlockerModule) return Promise.resolve();
|
|
7
|
+
if (Platform.OS === 'android' || Platform.OS === 'ios') {
|
|
8
|
+
return ScreenBlockerModule.enable();
|
|
9
|
+
}
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function disableScreenBlock() {
|
|
14
|
+
if (!ScreenBlockerModule) return Promise.resolve();
|
|
15
|
+
if (Platform.OS === 'android' || Platform.OS === 'ios') {
|
|
16
|
+
return ScreenBlockerModule.disable();
|
|
17
|
+
}
|
|
18
|
+
return Promise.resolve();
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#import "ScreenBlockerModule.h"
|
|
2
|
+
#import <UIKit/UIKit.h>
|
|
3
|
+
|
|
4
|
+
@implementation ScreenBlockerModule
|
|
5
|
+
|
|
6
|
+
RCT_EXPORT_MODULE();
|
|
7
|
+
|
|
8
|
+
RCT_EXPORT_METHOD(enable)
|
|
9
|
+
{
|
|
10
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
11
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
|
|
12
|
+
if (@available(iOS 13.0, *)) {
|
|
13
|
+
[keyWindow setSecure:true]; // Obscures the screen content on screenshots & recordings
|
|
14
|
+
} else {
|
|
15
|
+
// For older systems, optionally implement an overlay or similar protection here
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
RCT_EXPORT_METHOD(disable)
|
|
21
|
+
{
|
|
22
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
23
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
|
|
24
|
+
if (@available(iOS 13.0, *)) {
|
|
25
|
+
[keyWindow setSecure:false];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Pod::Spec.new do |s|
|
|
2
|
+
s.name = "react-native-screen-blocker"
|
|
3
|
+
s.version = "1.0.0"
|
|
4
|
+
s.summary = "React Native module to block screenshots and screen recording"
|
|
5
|
+
s.description = <<-DESC
|
|
6
|
+
Adds native protection to prevent screenshots and screen recordings on Android and iOS.
|
|
7
|
+
DESC
|
|
8
|
+
s.homepage = "http://ipznjozqaslv001.pwcglb.com/anweshan_mukherjee/react-native-screen-blocker"
|
|
9
|
+
s.license = { :type => "MIT" }
|
|
10
|
+
s.author = { "Your Name" => "you@example.com" }
|
|
11
|
+
s.platform = :ios, "10.0"
|
|
12
|
+
s.source = { :git => "http://ipznjozqaslv001.pwcglb.com/anweshan_mukherjee/react-native-screen-blocker.git", :tag => s.version }
|
|
13
|
+
s.source_files = "ios/**/*.{h,m}"
|
|
14
|
+
s.requires_arc = true
|
|
15
|
+
s.dependency "React"
|
|
16
|
+
end
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-screen-blocker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React Native module to block screenshots and screen recording on Android and iOS",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"react-native",
|
|
11
|
+
"screenshots",
|
|
12
|
+
"screen-recording",
|
|
13
|
+
"security",
|
|
14
|
+
"screen-blocker",
|
|
15
|
+
"android",
|
|
16
|
+
"ios"
|
|
17
|
+
],
|
|
18
|
+
"author": "Anweshan Mukherjee",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react-native": ">=0.60"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "http://ipznjozqaslv001.pwcglb.com/anweshan_mukherjee/react-native-screen-blocker"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "http://ipznjozqaslv001.pwcglb.com/anweshan_mukherjee/react-native-screen-blocker/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "http://ipznjozqaslv001.pwcglb.com/anweshan_mukherjee/react-native-screen-blocker#readme",
|
|
31
|
+
"react-native": {
|
|
32
|
+
"android": {
|
|
33
|
+
"packageImportPath": "import com.screenblocker.ScreenBlockerPackage;",
|
|
34
|
+
"packageInstance": "new ScreenBlockerPackage()"
|
|
35
|
+
},
|
|
36
|
+
"ios": {
|
|
37
|
+
"podspecPath": "ios/react-native-screen-blocker.podspec"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|