Coder Social home page Coder Social logo

azizak / react-native-detector Goto Github PK

View Code? Open in Web Editor NEW
202.0 4.0 34.0 1.63 MB

a screenshot detector for react native

License: MIT License

Kotlin 16.57% JavaScript 5.18% Java 21.82% TypeScript 27.02% C 0.36% Objective-C 13.86% Swift 0.21% Ruby 14.98%
react-native ios screenshot detector android

react-native-detector's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-detector's Issues

Undefined symbols _RCTRegisterModule issue

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-detector/android/.project b/node_modules/react-native-detector/android/.project
index 0e0a1ba..042e8b5 100644
--- a/node_modules/react-native-detector/android/.project
+++ b/node_modules/react-native-detector/android/.project
@@ -5,6 +5,11 @@
 	<projects>
 	</projects>
 	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 		<buildCommand>
 			<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
 			<arguments>
@@ -12,6 +17,7 @@
 		</buildCommand>
 	</buildSpec>
 	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
 		<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
 	</natures>
 </projectDescription>
diff --git a/node_modules/react-native-detector/android/.settings/org.eclipse.buildship.core.prefs b/node_modules/react-native-detector/android/.settings/org.eclipse.buildship.core.prefs
index 8c253d6..509edf4 100644
--- a/node_modules/react-native-detector/android/.settings/org.eclipse.buildship.core.prefs
+++ b/node_modules/react-native-detector/android/.settings/org.eclipse.buildship.core.prefs
@@ -2,7 +2,7 @@ arguments=
 auto.sync=false
 build.scans.enabled=false
 connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0))
-connection.project.dir=
+connection.project.dir=../../../android
 eclipse.preferences.version=1
 gradle.user.home=
 java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
diff --git a/node_modules/react-native-detector/react-native-detector.podspec b/node_modules/react-native-detector/react-native-detector.podspec
index 0986fc8..460ab7d 100644
--- a/node_modules/react-native-detector/react-native-detector.podspec
+++ b/node_modules/react-native-detector/react-native-detector.podspec
@@ -17,5 +17,5 @@ Pod::Spec.new do |s|
   s.source_files = "ios/**/*.{h,m,mm}"
   
 
-  s.dependency "React"
+  s.dependency "React-Core"
 end

This issue body was partially generated by patch-package.

Task :react-native-detector:compileDebugKotlin FAILED

When I try to run my android app after installing the react-native-detector, I have this kind of error:

Task :react-native-detector:compileDebugKotlin FAILED

Task :invertase_react-native-apple-authentication:compileDebugKotlin
w: /Users/marquicas2/Documents/rodeo/node_modules/@invertase/react-native-apple-authentication/android/src/main/java/com/RNAppleAuthentication/webview/SignInWebViewClient.kt: (15, 21): 'constructor Handler()' is deprecated. Deprecated in Java
w: /Users/marquicas2/Documents/rodeo/node_modules/@invertase/react-native-apple-authentication/android/src/main/java/com/RNAppleAuthentication/webview/SignInWebViewDialogFragment.kt: (42, 40): 'getParcelable(String?): T?' is deprecated. Deprecated in Java
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

Any thought? Probably related to the library needs an upgrade of version?

Does this only work on device (not simulator?)

Hitting the "Save Screen" button on the iOS simulator doesn't seem to trigger the screenshot event.

I am only able to get it to work on an actual device.

Is this the expected behavior?

Happy to submit a PR adding this to the README.

Do we need to have Android Permission

Hi,
Nice lib,
Quick question:
Do we need to ask for permission if we don't need to get the path of the screenshot?
If we just wanna know if a screenshot is done by the user or not?
Since we don't get the path on the react-native side
Thanks,
Regards

How do we prevent the app from detecting screenshot when app is in background

How can we stop the package from detecting/recording screenshot events when the app goes in the background without using appstate of react-native to find the state.

Also,
I have stack navigation using react-natvigation with the Home,Listing and Detail page. The package is used in the detail page. But if i take screenshot in the home page or listing page, its still detecting that.

Here is my code for Detail Page


export default class Detail extends React.Component {
  screenCaptureListner;
  componentDidMount() {
     Platform.OS === 'ios' ? this.screenShot() : this.handleAndroidPermission();
  }
 
 componentWillUnmount() {
   removeScreenshotListener(this.screenCaptureListner);
 }

  handleAndroidPermission = async () => {
        try {
            const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
            if (granted === PermissionsAndroid.RESULTS.GRANTED) {
                this.screenShot()
            }
        } catch (err) {
            console.warn(err);
        }
    };
    screenShot = () => {
        this.screenCaptureListner = addScreenshotListener(this.screenCaptured);
    }

 screenCaptured = () => {
  <!--- Here is some code --->
  }
}

[0.2.2] Android still have duplicated screenshot events

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

I was having screenshot duplicated issues on Android and noticed that you had a new version 0.2.2 that was tackling this issue. But I found that there was still an edge case where it was having duplicated events. On a Pixel 2 XL on Android 11 when a screenshot is done it generates the following files:

/storage/emulated/0/Pictures/Screenshots/.pending-1654277201-Screenshot_20220527-132641.png
/storage/emulated/0/Pictures/Screenshots/Screenshot_20220527-132641.png

As you can see, your current fix implementation does not work in this case since one of the filename starts with .pending-xxx-. So, I fixed it on my end by checking instead if the previous path was containing the same filename excluding was comes before Screenshot_20220527-132641.png.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-detector/android/src/main/java/com/.DS_Store b/node_modules/react-native-detector/android/src/main/java/com/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/react-native-detector/android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt b/node_modules/react-native-detector/android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt
index b8964d3..325d802 100644
--- a/node_modules/react-native-detector/android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt
+++ b/node_modules/react-native-detector/android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt
@@ -28,7 +28,8 @@ class ScreenshotDetectionDelegate(val context: Context, val listener: Screenshot
                 if (isReadExternalStoragePermissionGranted() && uri != null) {
                     val path = getFilePathFromContentResolver(context, uri)
                     if (path != null && isScreenshotPath(path)) {
-                        previousPath = path
+                        previousPath = path.toLowerCase().substring(path.toLowerCase().lastIndexOf("screenshot"))
                         onScreenCaptured(path!!)
                     }
                 } else {
@@ -57,7 +58,7 @@ class ScreenshotDetectionDelegate(val context: Context, val listener: Screenshot
     }
 
     private fun isScreenshotPath(path: String?): Boolean {
-        return path != null && path.toLowerCase().contains("screenshots") && previousPath != path
+        return path != null && path.toLowerCase().contains("screenshots") && (previousPath == "" || !path.toLowerCase().contains(previousPath))
     }
 
     private fun getFilePathFromContentResolver(context: Context, uri: Uri): String? {

This issue body was partially generated by patch-package.

Not logging

const Test = () => {
const requestPermission = async () => {
await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: 'Get Read External Storage Access',
message: 'get read external storage access for detecting screenshots',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
};

React.useEffect(() => {
requestPermission();
const userDidScreenshot = () => {
console.log('User took screenshot');
};
const listener = addScreenshotListener(userDidScreenshot);
return () => {
removeScreenshotListener(listener);
};
}, []);
return Test;
};
export default Test;

This is my code, but response system not logging can u help me?

iOS app crashing after 0.2.2 Upgrade

Apologies in advance - this is a less-helpful issue report than I would like to make.

After upgrading react-native-detector to v0.2.2, our iOS app is crashing on launch with the error Invariant Violation: Native module cannot be null.

After downgrading back to v0.2.1, the issue was immediately resolved.

It's not pressing for us to get this fixed, and I don't expect help without me providing more information. I just want to open this issue as a central place for others to report on it if they have the same problem.

RN New Architecture

Hi, I was wondering if there were any plans/scope to migrate this project to the new architecture? Many thanks

Cannot build on [email protected], ScreenshotDetectionDelegate.kt: (25, 13): 'onChange' overrides nothing

How reproduce:

npx react-native init Test
cd Test
yarn add react-native-detector
npx react-native run-android


# you will next error: 
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
e: /home/i/open-source/DetectScreenshot/node_modules/react-native-detector/android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt: (25, 13): 'onChange' overrides nothing

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-detector:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

    at makeError (/home/i/open-source/DetectScreenshot/node_modules/execa/index.js:174:9)
    at /home/i/open-source/DetectScreenshot/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async runOnAllDevices (/home/i/open-source/DetectScreenshot/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:106:5)
    at async Command.handleAction (/home/i/open-source/DetectScreenshot/node_modules/@react-native-community/cli/build/index.js:186:9)

Multiple screenshot events on single screenshot

As mentioned in the header I am getting 3 screenshot calls when I take a single screenshot...

I checked that it only registers the listener once...any ideas?

import {
  addScreenshotListener,
  removeScreenshotListener,
} from 'react-native-detector';

async componentDidMount() {
    this.screenshot = this.screenshot || addScreenshotListener(() => {
      console.log('screenshot');

      toast.show('screenshot');
    });

async componentWillUnmount() {
    removeScreenshotListener(this.screenshot);
}

Task :react-native-detector:lintDebug FAILED

Task :react-native-detector:lintDebug FAILED
Caching disabled for task ':react-native-detector:lintDebug' because:
Build cache is disabled
Task ':react-native-detector:lintDebug' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Lint found 1 errors, 1 warnings. First failure:

D:\chat\node_modules\react-native-detector\android\src\main\java\com\reactnativedetector\ScreenshotDetectionDelegate.kt:68: Error: Value must be โ‰ฅ 0 but getColumnIndex can be -1 [Range]
val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Explanation for issues of type "Range":
Some parameters are required to in a particular numerical range; this check
makes sure that arguments passed fall within the range. For arrays, Strings
and collections this refers to the size or length.

The full lint text report is located at:
D:\chat\node_modules\react-native-detector\android\build\intermediates\lint_intermediate_text_report\debug\lint-results-debug.txt
:react-native-detector:lintDebug (Thread[Execution worker,5,main]) completed. Took 0.003 secs.

./gradlew build --refresh-dependencies
react native 0.71.8
buildToolsVersion = "33.0.0"
minSdkVersion = 24
compileSdkVersion = 33
targetSdkVersion = 33

// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
ndkVersion = "23.1.7779620"

supportLibVersion = "28.0.0"
androidXAnnotation = "1.1.0"
androidXBrowser = "1.0.0"
kotlinVersion = "1.6.0"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.