New 0.0.5-rc.0

This commit is contained in:
Recep Kocur 2023-01-01 23:56:23 +03:00
parent cee1367c81
commit aeddf37703
8 changed files with 129 additions and 223 deletions

View File

@ -1,10 +1,8 @@
# react-native-screen-capture
> Please do not install. It is under construction.
**`react-native-screen-capture`** allows you to protect screens in your app from being captured or recorded, as well as be notified if a screenshot is taken while your app is foregrounded.
**Keep Awake** provides a React hook that prevents the screen from sleeping and a pair of functions to enable this behavior imperatively.
**Keep Awake**, keep the screen from going to sleep. iOS and Android
## Installation
@ -15,31 +13,35 @@ npm i react-native-screen-capture
## Usage
```js
import ScreenCapture from 'react-native-screen-capture';
import { disallowScreenshot, keepAwake } from 'react-native-screen-capture';
// disable screenshots
ScreenCapture.disallowScreenshot(true);
disallowScreenshot(true);
// enable screenshots
ScreenCapture.disallowScreenshot(false);
disallowScreenshot(false);
// Keep awake true
ScreenCapture.keepAwake(true);
keepAwake(true);
// Keep awake false
ScreenCapture.keepAwake(false);
keepAwake(false);
```
## Roadmap
| Status | Platform | Goal |
| :--------: | :------: | :--------------------- |
| ✅ | Android | Screenshot disable |
| 🚧 | iOS | Screenshot disable |
| ✅ | Android | Keep awake on or off |
| ✅ | iOS | Keep awake on or off |
| 🚧 | Android | Record capture disable |
| 🚧 | iOS | Record capture disable |
| Status | Platform | Goal |
| :--------: | :------: | :---------------------- |
| ✅ | Android | Screenshot disable |
| ✅ | iOS | Screenshot disable |
| ✅ | Android | Keep awake on or off |
| ✅ | iOS | Keep awake on or off |
| 🚧 | Android | Record capture disable |
| 🚧 | iOS | Record capture disable |
| 🚧 | Android | Screenshot callback |
| 🚧 | iOS | Screenshot callback |
| 🚧 | Android | Record capture callback |
| 🚧 | iOS | Record capture callback |
## Contributing

1
TODO
View File

@ -1,4 +1,3 @@
- create-react-native-module ScreenCapture --native-package-id com.recepkocur.screencapture --generate-example --author-email recepkocur@gmail.com --author-name "Recep Kocur" --github-account recepkocur --platforms "ios,android" --example-react-native-template react-native@0.67.5
- https://www.locklizard.com/stop-screenshots-grabbers/
- https://aboutreact.com/react-native-block-disable-screenshots/
- https://github.com/gijoehosaphat/react-native-keep-screen-on

View File

@ -1,148 +0,0 @@
// android/build.gradle
// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
// previous location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
// previous location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
// These defaults should reflect the SDK versions used by
// the minimum React Native version supported.
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
if (project == rootProject) {
repositories {
google()
}
dependencies {
// This should reflect the Gradle plugin version used by
// the minimum React Native version supported.
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
}
android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
// ref: https://www.baeldung.com/maven-local-repository
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
}
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}
def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.recepkocur.screencapture"
description packageJson.description
url packageJson.repository.baseUrl
licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}
developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}
afterEvaluate { project ->
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}
android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
def javaCompileTask = variant.javaCompileProvider.get()
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}
artifacts {
archives androidSourcesJar
archives androidJavadocJar
}
task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
}
}
}

View File

@ -1,32 +1,26 @@
/**
* Sample React Native App
*
* adapted from App.js generated by the following command:
*
* react-native init example
*
* https://github.com/facebook/react-native
*/
import React, { PureComponent } from 'react';
import { Platform, StyleSheet, Text, View, TouchableOpacity, } from 'react-native';
import ScreenCapture from 'react-native-screen-capture';
import { StyleSheet, Text, View, TouchableOpacity, } from 'react-native';
import { disallowScreenshot, keepAwake } from 'react-native-screen-capture';
// import { disallowScreenshot, keepAwake, userDidTakeScreenshot } from 'react-native-screen-capture';
export default class App extends PureComponent {
state = {
disallowScreenshot: true,
keepAwake: true,
disallowScreenshot: true,
// screenCaptureListener: null,
};
componentDidMount() {
ScreenCapture.disallowScreenshot(this.state.disallowScreenshot)
ScreenCapture.keepAwake(this.state.keepAwake)
// ScreenCapture.sampleMethod('Testing', 123, (message) => {
// this.setState({
// status: 'native callback received',
// message
// });
keepAwake(this.state.keepAwake)
disallowScreenshot(this.state.disallowScreenshot)
// this.setState({
// screenCaptureListener: userDidTakeScreenshot(() => {
// console.log('userDidTakeScreenshot')
// })
// });
}
componentWillUnmount() {
// this.state.screenCaptureListener.remove()
}
render() {
return (
<View style={styles.container}>
@ -34,7 +28,7 @@ export default class App extends PureComponent {
this.setState({
disallowScreenshot: !this.state.disallowScreenshot
}, () => {
ScreenCapture.disallowScreenshot(this.state.disallowScreenshot)
disallowScreenshot(this.state.disallowScreenshot)
})
}} style={{ padding: 15, backgroundColor: this.state.disallowScreenshot ? '#5BE55B' : '#FF6666', margin: 15 }}>
<Text>Disallow screenshot {!this.state.disallowScreenshot ? 'OFF' : 'ON'}</Text>
@ -43,11 +37,28 @@ export default class App extends PureComponent {
this.setState({
keepAwake: !this.state.keepAwake
}, () => {
ScreenCapture.keepAwake(this.state.keepAwake)
keepAwake(this.state.keepAwake)
})
}} style={{ padding: 15, backgroundColor: this.state.keepAwake ? '#5BE55B' : '#FF6666', margin: 15 }}>
<Text>Keep screen {!this.state.keepAwake ? 'OFF' : 'ON'}</Text>
</TouchableOpacity>
{/*<TouchableOpacity onPress={() => {
if (!this.state.screenCaptureListener) {
this.setState({
screenCaptureListener: userDidTakeScreenshot(() => {
console.log('JavaScript', 'userDidTakeScreenshot')
})
})
} else {
this.state.screenCaptureListener?.remove?.()
this.setState({
screenCaptureListener: null
})
}
}} style={{ padding: 15, backgroundColor: this.state.screenCaptureListener ? '#5BE55B' : '#FF6666', margin: 15 }}>
<Text>userDidTakeScreenshot {!this.state.screenCaptureListener ? 'OFF' : 'ON'}</Text>
</TouchableOpacity>*/}
</View>
);
}

View File

@ -1,53 +1,64 @@
/**
* Sample React Native App
*
* adapted from App.js generated by the following command:
*
* react-native init example
*
* https://github.com/facebook/react-native
*/
import React, { PureComponent } from 'react';
import { StyleSheet, Text, View, TouchableOpacity, } from 'react-native';
import ScreenCapture from 'react-native-screen-capture';
import { disallowScreenshot, keepAwake } from 'react-native-screen-capture';
// import { disallowScreenshot, keepAwake, userDidTakeScreenshot } from 'react-native-screen-capture';
export default class App extends PureComponent {
state = {
disallowScreenshot: true,
keepAwake: true,
disallowScreenshot: true,
// screenCaptureListener: null,
};
componentDidMount() {
// ScreenCapture.disallowScreenshot(this.state.disallowScreenshot)
ScreenCapture.keepAwake(this.state.keepAwake)
// ScreenCapture.sampleMethod('Testing', 123, (message) => {
// this.setState({
// status: 'native callback received',
// message
// });
keepAwake(this.state.keepAwake)
disallowScreenshot(this.state.disallowScreenshot)
// this.setState({
// screenCaptureListener: userDidTakeScreenshot(() => {
// console.log('userDidTakeScreenshot')
// })
// });
}
componentWillUnmount() {
// this.state.screenCaptureListener.remove()
}
render() {
return (
<View style={styles.container}>
{/*<TouchableOpacity onPress={() => {
<TouchableOpacity onPress={() => {
this.setState({
disallowScreenshot: !this.state.disallowScreenshot
}, () => {
ScreenCapture.disallowScreenshot(this.state.disallowScreenshot)
disallowScreenshot(this.state.disallowScreenshot)
})
}} style={{ padding: 15, backgroundColor: this.state.disallowScreenshot ? '#5BE55B' : '#FF6666', margin: 15 }}>
<Text>Disallow screenshot {!this.state.disallowScreenshot ? 'OFF' : 'ON'}</Text>
</TouchableOpacity>*/}
</TouchableOpacity>
<TouchableOpacity onPress={() => {
this.setState({
keepAwake: !this.state.keepAwake
}, () => {
ScreenCapture.keepAwake(this.state.keepAwake)
keepAwake(this.state.keepAwake)
})
}} style={{ padding: 15, backgroundColor: this.state.keepAwake ? '#5BE55B' : '#FF6666', margin: 15 }}>
<Text>Keep screen {!this.state.keepAwake ? 'OFF' : 'ON'}</Text>
</TouchableOpacity>
{/*<TouchableOpacity onPress={() => {
if (!this.state.screenCaptureListener) {
this.setState({
screenCaptureListener: userDidTakeScreenshot(() => {
console.log('JavaScript', 'userDidTakeScreenshot')
})
})
} else {
this.state.screenCaptureListener?.remove?.()
this.setState({
screenCaptureListener: null
})
}
}} style={{ padding: 15, backgroundColor: this.state.screenCaptureListener ? '#5BE55B' : '#FF6666', margin: 15 }}>
<Text>userDidTakeScreenshot {!this.state.screenCaptureListener ? 'OFF' : 'ON'}</Text>
</TouchableOpacity>*/}
</View>
);
}

View File

@ -1,7 +1,8 @@
// main index.js
import { NativeModules } from 'react-native';
import { NativeModules, NativeEventEmitter, } from 'react-native';
const { ScreenCapture } = NativeModules;
export const { ScreenCapture } = NativeModules;
export default ScreenCapture;
export const disallowScreenshot = ScreenCapture.disallowScreenshot
export const keepAwake = ScreenCapture.keepAwake

View File

@ -2,22 +2,52 @@
#import "ScreenCapture.h"
@implementation ScreenCapture
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback)
{
// TODO: Implement some actually useful functionality
callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]);
@implementation ScreenCapture {
BOOL dev;
UITextField *secureTextField;
}
- (dispatch_queue_t)methodQueue {
dev = NO;
if (dev) NSLog(@"[SC] methodQueue");
return dispatch_get_main_queue();
}
+ (BOOL)requiresMainQueueSetup {
return YES;
}
#pragma mark - dealloc -
- (void)dealloc {
if (dev) NSLog(@"[SC] dealloc");
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - reactnative -
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(keepAwake:(BOOL)status)
{
if (dev) NSLog(@"[SC] keepAwake with %@", status ? @"YES" : @"NO");
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setIdleTimerDisabled:status];
});
}
RCT_EXPORT_METHOD(disallowScreenshot:(BOOL)status)
{
if (dev) NSLog(@"[SC] disallowScreenshot with %@", status ? @"YES" : @"NO");
if (self->secureTextField == nil) {
self->secureTextField = [[UITextField alloc] init];
self->secureTextField.userInteractionEnabled = false;
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
[window addSubview:self->secureTextField];
[window.layer.superlayer addSublayer:self->secureTextField.layer];
[self->secureTextField.layer.sublayers.firstObject addSublayer:window.layer];
}
[self->secureTextField setSecureTextEntry:status];
}
@end

View File

@ -1,7 +1,7 @@
{
"name": "react-native-screen-capture",
"title": "React Native Screen Capture",
"version": "0.0.4",
"version": "0.0.5-rc.0",
"description": "react-native-screen-capture allows you to protect screens in your app from being captured or recorded, as well as be notified if a screenshot is taken while your app is foregrounded.",
"main": "index.js",
"files": [