├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── gradle.properties └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── reactnativedetector │ ├── DetectorModule.kt │ ├── DetectorPackage.kt │ └── ScreenshotDetectionDelegate.kt ├── babel.config.js ├── commitlint.config.js ├── example ├── .bundle │ └── config ├── .flowconfig ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── android │ ├── .project │ ├── .settings │ │ └── org.eclipse.buildship.core.prefs │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── DetectorExample │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── DetectorExample │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── drawable │ │ │ └── rn_edit_text_material.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.tsx ├── ios │ ├── DetectorExample-Bridging-Header.h │ ├── DetectorExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── DetectorExample.xcscheme │ ├── DetectorExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── DetectorExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m │ ├── File.swift │ ├── Podfile │ └── Podfile.lock ├── metro.config.js ├── package.json ├── src │ └── App.tsx └── yarn.lock ├── ios ├── Detector.h ├── Detector.m └── Detector.xcodeproj │ └── project.pbxproj ├── package.json ├── react-native-detector.podspec ├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .idea 35 | .gradle 36 | local.properties 37 | android.iml 38 | 39 | # Cocoapods 40 | # 41 | example/ios/Pods 42 | 43 | # node.js 44 | # 45 | node_modules/ 46 | npm-debug.log 47 | yarn-debug.log 48 | yarn-error.log 49 | 50 | # BUCK 51 | buck-out/ 52 | \.buckd/ 53 | android/app/libs 54 | android/keystores/debug.keystore 55 | 56 | # Expo 57 | .expo/* 58 | 59 | # generated by bob 60 | lib/ 61 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn bootstrap` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn bootstrap 11 | ``` 12 | 13 | While developing, you can run the [example app](/example/) to test your changes. 14 | 15 | To start the packager: 16 | 17 | ```sh 18 | yarn example start 19 | ``` 20 | 21 | To run the example app on Android: 22 | 23 | ```sh 24 | yarn example android 25 | ``` 26 | 27 | To run the example app on iOS: 28 | 29 | ```sh 30 | yarn example ios 31 | ``` 32 | 33 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 34 | 35 | ```sh 36 | yarn typescript 37 | yarn lint 38 | ``` 39 | 40 | To fix formatting errors, run the following: 41 | 42 | ```sh 43 | yarn lint --fix 44 | ``` 45 | 46 | Remember to add tests for your change if possible. Run the unit tests by: 47 | 48 | ```sh 49 | yarn test 50 | ``` 51 | 52 | To edit the Objective-C files, open `example/ios/DetectorExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-detector`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativedetector` under `Android`. 55 | 56 | ### Commit message convention 57 | 58 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 59 | 60 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 61 | - `feat`: new features, e.g. add new method to the module. 62 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 63 | - `docs`: changes into documentation, e.g. add usage example for the module.. 64 | - `test`: adding or updating tests, eg add integration tests using detox. 65 | - `chore`: tooling changes, e.g. change CI config. 66 | 67 | Our pre-commit hooks verify that your commit message matches this format when committing. 68 | 69 | ### Linting and tests 70 | 71 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 72 | 73 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 74 | 75 | Our pre-commit hooks verify that the linter and tests pass when committing. 76 | 77 | ### Scripts 78 | 79 | The `package.json` file contains various scripts for common tasks: 80 | 81 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 82 | - `yarn typescript`: type-check files with TypeScript. 83 | - `yarn lint`: lint files with ESLint. 84 | - `yarn test`: run unit tests with Jest. 85 | - `yarn example start`: start the Metro server for the example app. 86 | - `yarn example android`: run the example app on Android. 87 | - `yarn example ios`: run the example app on iOS. 88 | 89 | ### Sending a pull request 90 | 91 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). 92 | 93 | When you're sending a pull request: 94 | 95 | - Prefer small pull requests focused on one change. 96 | - Verify that linters and tests are passing. 97 | - Review the documentation to make sure it looks good. 98 | - Follow the pull request template when opening a pull request. 99 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 100 | 101 | ## Code of Conduct 102 | 103 | ### Our Pledge 104 | 105 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 106 | 107 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 108 | 109 | ### Our Standards 110 | 111 | Examples of behavior that contributes to a positive environment for our community include: 112 | 113 | - Demonstrating empathy and kindness toward other people 114 | - Being respectful of differing opinions, viewpoints, and experiences 115 | - Giving and gracefully accepting constructive feedback 116 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 117 | - Focusing on what is best not just for us as individuals, but for the overall community 118 | 119 | Examples of unacceptable behavior include: 120 | 121 | - The use of sexualized language or imagery, and sexual attention or 122 | advances of any kind 123 | - Trolling, insulting or derogatory comments, and personal or political attacks 124 | - Public or private harassment 125 | - Publishing others' private information, such as a physical or email 126 | address, without their explicit permission 127 | - Other conduct which could reasonably be considered inappropriate in a 128 | professional setting 129 | 130 | ### Enforcement Responsibilities 131 | 132 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 133 | 134 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 135 | 136 | ### Scope 137 | 138 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 139 | 140 | ### Enforcement 141 | 142 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 143 | 144 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 145 | 146 | ### Enforcement Guidelines 147 | 148 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 149 | 150 | #### 1. Correction 151 | 152 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 153 | 154 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 155 | 156 | #### 2. Warning 157 | 158 | **Community Impact**: A violation through a single incident or series of actions. 159 | 160 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 161 | 162 | #### 3. Temporary Ban 163 | 164 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 165 | 166 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 167 | 168 | #### 4. Permanent Ban 169 | 170 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 171 | 172 | **Consequence**: A permanent ban from any sort of public interaction within the community. 173 | 174 | ### Attribution 175 | 176 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 177 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 178 | 179 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 180 | 181 | [homepage]: https://www.contributor-covenant.org 182 | 183 | For answers to common questions about this code of conduct, see the FAQ at 184 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 185 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Abdulaziz Alkharashi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-detector 2 | 3 | a simply and easy to use screenshot detector for react native 4 | 5 | ## Installation 6 | 7 | yarn 8 | 9 | ```sh 10 | yarn add react-native-detector 11 | ``` 12 | 13 | npm 14 | 15 | ```sh 16 | npm install react-native-detector 17 | ``` 18 | 19 | ### iOS 20 | 21 | ```sh 22 | cd ios && pod install 23 | ``` 24 | 25 | ### android 26 | 27 | for Android you need to have access for `READ_EXTERNAL_STORAGE` to detect screenshots by user to do that you just need to add this line in `AndroidManifest.xml` 28 | 29 | ```xml 30 | 31 | ``` 32 | 33 | and get user permission 34 | 35 | ```js 36 | import { PermissionsAndroid } from 'react-native'; 37 | 38 | //... 39 | const requestPermission = async () => { 40 | await PermissionsAndroid.request( 41 | PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, 42 | { 43 | title: 'Get Read External Storage Access', 44 | message: 'get read external storage access for detecting screenshots', 45 | buttonNeutral: 'Ask Me Later', 46 | buttonNegative: 'Cancel', 47 | buttonPositive: 'OK', 48 | } 49 | ); 50 | }; 51 | ``` 52 | 53 | ## Usage 54 | 55 | ```js 56 | import { 57 | addScreenshotListener, 58 | removeScreenshotListener, 59 | } from 'react-native-detector'; 60 | 61 | // ... 62 | React.useEffect(() => { 63 | const userDidScreenshot = () => { 64 | console.log('User took screenshot'); 65 | }; 66 | const unsubscribe = addScreenshotListener(userDidScreenshot); 67 | return () => { 68 | unsubscribe(); 69 | }; 70 | }, []); 71 | ``` 72 | 73 | ## Roadmap 74 | 75 | | Status | Goal | 76 | | :---------------------------------------------------: | :------------------------------------- | 77 | | ✅ | iOS version of screenshot detector | 78 | | ✅ (Thanks to [@mhssn95](https://github.com/mhssn95)) | Android version of screenshot detector | 79 | | 🚧 | Screen recording detecting | 80 | | 🚧 | Calls detector | 81 | 82 | ## Contributing 83 | 84 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 85 | 86 | ## License 87 | 88 | MIT 89 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | android_ 4 | Project android_ created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0)) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault 3 | def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Detector_kotlinVersion'] 4 | 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.2.1' 12 | // noinspection DifferentKotlinGradleVersion 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | } 15 | } 16 | 17 | apply plugin: 'com.android.library' 18 | apply plugin: 'kotlin-android' 19 | 20 | def getExtOrDefault(name) { 21 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Detector_' + name] 22 | } 23 | 24 | def getExtOrIntegerDefault(name) { 25 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Detector_' + name]).toInteger() 26 | } 27 | 28 | android { 29 | compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') 30 | buildToolsVersion getExtOrDefault('buildToolsVersion') 31 | defaultConfig { 32 | minSdkVersion getExtOrIntegerDefault('minSdkVersion') 33 | targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') 34 | versionCode 1 35 | versionName "1.0" 36 | } 37 | 38 | buildTypes { 39 | release { 40 | minifyEnabled false 41 | } 42 | } 43 | lintOptions { 44 | disable 'GradleCompatible' 45 | } 46 | compileOptions { 47 | sourceCompatibility JavaVersion.VERSION_1_8 48 | targetCompatibility JavaVersion.VERSION_1_8 49 | } 50 | } 51 | 52 | repositories { 53 | mavenCentral() 54 | google() 55 | 56 | def found = false 57 | def defaultDir = null 58 | def androidSourcesName = 'React Native sources' 59 | 60 | if (rootProject.ext.has('reactNativeAndroidRoot')) { 61 | defaultDir = rootProject.ext.get('reactNativeAndroidRoot') 62 | } else { 63 | defaultDir = new File( 64 | projectDir, 65 | '/../../../node_modules/react-native/android' 66 | ) 67 | } 68 | 69 | if (defaultDir.exists()) { 70 | maven { 71 | url defaultDir.toString() 72 | name androidSourcesName 73 | } 74 | 75 | logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") 76 | found = true 77 | } else { 78 | def parentDir = rootProject.projectDir 79 | 80 | 1.upto(5, { 81 | if (found) return true 82 | parentDir = parentDir.parentFile 83 | 84 | def androidSourcesDir = new File( 85 | parentDir, 86 | 'node_modules/react-native' 87 | ) 88 | 89 | def androidPrebuiltBinaryDir = new File( 90 | parentDir, 91 | 'node_modules/react-native/android' 92 | ) 93 | 94 | if (androidPrebuiltBinaryDir.exists()) { 95 | maven { 96 | url androidPrebuiltBinaryDir.toString() 97 | name androidSourcesName 98 | } 99 | 100 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") 101 | found = true 102 | } else if (androidSourcesDir.exists()) { 103 | maven { 104 | url androidSourcesDir.toString() 105 | name androidSourcesName 106 | } 107 | 108 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") 109 | found = true 110 | } 111 | }) 112 | } 113 | 114 | if (!found) { 115 | throw new GradleException( 116 | "${project.name}: unable to locate React Native android sources. " + 117 | "Ensure you have you installed React Native as a dependency in your project and try again." 118 | ) 119 | } 120 | } 121 | 122 | def kotlin_version = getExtOrDefault('kotlinVersion') 123 | 124 | dependencies { 125 | // noinspection GradleDynamicVersion 126 | api 'com.facebook.react:react-native:+' 127 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 128 | } 129 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | Detector_kotlinVersion=1.3.50 2 | Detector_compileSdkVersion=28 3 | Detector_buildToolsVersion=28.0.3 4 | Detector_targetSdkVersion=28 5 | Detector_minSdkVersion=16 6 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativedetector/DetectorModule.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativedetector 2 | 3 | import com.facebook.react.bridge.ReactApplicationContext 4 | import com.facebook.react.bridge.ReactContextBaseJavaModule 5 | import com.facebook.react.bridge.ReactMethod 6 | import com.facebook.react.modules.core.DeviceEventManagerModule 7 | 8 | 9 | 10 | class DetectorModule(val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), ScreenshotDetectionListener { 11 | private val screenshotDetectionDelegate = ScreenshotDetectionDelegate(reactContext, this) 12 | override fun getName(): String { 13 | return "Detector" 14 | } 15 | 16 | @ReactMethod 17 | fun startScreenshotDetection() { 18 | screenshotDetectionDelegate.startScreenshotDetection() 19 | } 20 | 21 | @ReactMethod 22 | fun stopScreenshotDetection() { 23 | screenshotDetectionDelegate.stopScreenshotDetection() 24 | } 25 | 26 | override fun onScreenCaptured(path: String) { 27 | reactContext 28 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) 29 | .emit("UIApplicationUserDidTakeScreenshotNotification", null) 30 | } 31 | 32 | override fun onScreenCapturedWithDeniedPermission() { 33 | // Todo: send user notification. 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativedetector/DetectorPackage.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativedetector 2 | 3 | import java.util.Arrays 4 | import com.facebook.react.ReactPackage 5 | import com.facebook.react.bridge.NativeModule 6 | import com.facebook.react.bridge.ReactApplicationContext 7 | import com.facebook.react.uimanager.ViewManager 8 | 9 | class DetectorPackage : ReactPackage { 10 | override fun createNativeModules(reactContext: ReactApplicationContext): List { 11 | return Arrays.asList(DetectorModule(reactContext)) 12 | } 13 | 14 | override fun createViewManagers(reactContext: ReactApplicationContext): List> { 15 | return emptyList>() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativedetector/ScreenshotDetectionDelegate.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativedetector 2 | 3 | import android.Manifest 4 | import android.content.Context 5 | import android.database.ContentObserver 6 | import android.net.Uri 7 | import android.os.Handler 8 | import android.provider.MediaStore 9 | import android.content.pm.PackageManager 10 | import android.Manifest.permission 11 | import android.Manifest.permission.READ_EXTERNAL_STORAGE 12 | import androidx.core.content.ContextCompat 13 | import android.database.Cursor 14 | import android.util.Log 15 | import java.lang.Exception 16 | 17 | 18 | class ScreenshotDetectionDelegate(val context: Context, val listener: ScreenshotDetectionListener) { 19 | lateinit var contentObserver: ContentObserver 20 | 21 | var isListening = false 22 | var previousPath = "" 23 | 24 | fun startScreenshotDetection() { 25 | contentObserver = object : ContentObserver(Handler()) { 26 | override fun onChange(selfChange: Boolean, uri: Uri?) { 27 | super.onChange(selfChange, uri) 28 | if (isReadExternalStoragePermissionGranted() && uri != null) { 29 | val path = getFilePathFromContentResolver(context, uri) 30 | if (path != null && isScreenshotPath(path)) { 31 | previousPath = path 32 | onScreenCaptured(path!!) 33 | } 34 | } else { 35 | onScreenCapturedWithDeniedPermission() 36 | } 37 | } 38 | } 39 | 40 | context.contentResolver.registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 41 | true, 42 | contentObserver) 43 | isListening = true 44 | } 45 | 46 | fun stopScreenshotDetection() { 47 | context.getContentResolver().unregisterContentObserver(contentObserver) 48 | isListening = false 49 | } 50 | 51 | private fun onScreenCaptured(path: String) { 52 | listener.onScreenCaptured(path) 53 | } 54 | 55 | private fun onScreenCapturedWithDeniedPermission() { 56 | listener.onScreenCapturedWithDeniedPermission() 57 | } 58 | 59 | private fun isScreenshotPath(path: String?): Boolean { 60 | return path != null && path.toLowerCase().contains("screenshots") && previousPath != path 61 | } 62 | 63 | private fun getFilePathFromContentResolver(context: Context, uri: Uri): String? { 64 | try { 65 | 66 | val cursor = context.contentResolver.query(uri, arrayOf(MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA), null, null, null) 67 | if (cursor != null && cursor.moveToFirst()) { 68 | val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)) 69 | cursor.close() 70 | return path 71 | } 72 | } catch (e: Exception) { 73 | 74 | } 75 | return null 76 | } 77 | 78 | private fun isReadExternalStoragePermissionGranted(): Boolean { 79 | return ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED 80 | } 81 | } 82 | 83 | interface ScreenshotDetectionListener { 84 | fun onScreenCaptured(path: String) 85 | fun onScreenCapturedWithDeniedPermission() 86 | } -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 -------------------------------------------------------------------------------- /example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore polyfills 9 | node_modules/react-native/Libraries/polyfills/.* 10 | 11 | ; Flow doesn't support platforms 12 | .*/Libraries/Utilities/LoadingView.js 13 | 14 | [untyped] 15 | .*/node_modules/@react-native-community/cli/.*/.* 16 | 17 | [include] 18 | 19 | [libs] 20 | node_modules/react-native/interface.js 21 | node_modules/react-native/flow/ 22 | 23 | [options] 24 | emoji=true 25 | 26 | exact_by_default=true 27 | 28 | format.bracket_spacing=false 29 | 30 | module.file_ext=.js 31 | module.file_ext=.json 32 | module.file_ext=.ios.js 33 | 34 | munge_underscores=true 35 | 36 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 37 | module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' 38 | 39 | suppress_type=$FlowIssue 40 | suppress_type=$FlowFixMe 41 | suppress_type=$FlowFixMeProps 42 | suppress_type=$FlowFixMeState 43 | 44 | [lints] 45 | sketchy-null-number=warn 46 | sketchy-null-mixed=warn 47 | sketchy-number=warn 48 | untyped-type-import=warn 49 | nonstrict-import=warn 50 | deprecated-type=warn 51 | unsafe-getters-setters=warn 52 | unnecessary-invariant=warn 53 | signature-verification-failure=warn 54 | 55 | [strict] 56 | deprecated-type 57 | nonstrict-import 58 | sketchy-null 59 | unclear-type 60 | unsafe-getters-setters 61 | untyped-import 62 | untyped-type-import 63 | 64 | [version] 65 | ^0.162.0 66 | -------------------------------------------------------------------------------- /example/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.4 -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 3 | ruby '2.7.4' 4 | gem 'cocoapods', '~> 1.11', '>= 1.11.2' -------------------------------------------------------------------------------- /example/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (3.0.5) 5 | rexml 6 | activesupport (6.1.4.6) 7 | concurrent-ruby (~> 1.0, >= 1.0.2) 8 | i18n (>= 1.6, < 2) 9 | minitest (>= 5.1) 10 | tzinfo (~> 2.0) 11 | zeitwerk (~> 2.3) 12 | addressable (2.8.0) 13 | public_suffix (>= 2.0.2, < 5.0) 14 | algoliasearch (1.27.5) 15 | httpclient (~> 2.8, >= 2.8.3) 16 | json (>= 1.5.1) 17 | atomos (0.1.3) 18 | claide (1.1.0) 19 | cocoapods (1.11.2) 20 | addressable (~> 2.8) 21 | claide (>= 1.0.2, < 2.0) 22 | cocoapods-core (= 1.11.2) 23 | cocoapods-deintegrate (>= 1.0.3, < 2.0) 24 | cocoapods-downloader (>= 1.4.0, < 2.0) 25 | cocoapods-plugins (>= 1.0.0, < 2.0) 26 | cocoapods-search (>= 1.0.0, < 2.0) 27 | cocoapods-trunk (>= 1.4.0, < 2.0) 28 | cocoapods-try (>= 1.1.0, < 2.0) 29 | colored2 (~> 3.1) 30 | escape (~> 0.0.4) 31 | fourflusher (>= 2.3.0, < 3.0) 32 | gh_inspector (~> 1.0) 33 | molinillo (~> 0.8.0) 34 | nap (~> 1.0) 35 | ruby-macho (>= 1.0, < 3.0) 36 | xcodeproj (>= 1.21.0, < 2.0) 37 | cocoapods-core (1.11.2) 38 | activesupport (>= 5.0, < 7) 39 | addressable (~> 2.8) 40 | algoliasearch (~> 1.0) 41 | concurrent-ruby (~> 1.1) 42 | fuzzy_match (~> 2.0.4) 43 | nap (~> 1.0) 44 | netrc (~> 0.11) 45 | public_suffix (~> 4.0) 46 | typhoeus (~> 1.0) 47 | cocoapods-deintegrate (1.0.5) 48 | cocoapods-downloader (1.5.1) 49 | cocoapods-plugins (1.0.0) 50 | nap 51 | cocoapods-search (1.0.1) 52 | cocoapods-trunk (1.6.0) 53 | nap (>= 0.8, < 2.0) 54 | netrc (~> 0.11) 55 | cocoapods-try (1.2.0) 56 | colored2 (3.1.2) 57 | concurrent-ruby (1.1.9) 58 | escape (0.0.4) 59 | ethon (0.15.0) 60 | ffi (>= 1.15.0) 61 | ffi (1.15.5) 62 | fourflusher (2.3.1) 63 | fuzzy_match (2.0.4) 64 | gh_inspector (1.1.3) 65 | httpclient (2.8.3) 66 | i18n (1.10.0) 67 | concurrent-ruby (~> 1.0) 68 | json (2.6.1) 69 | minitest (5.15.0) 70 | molinillo (0.8.0) 71 | nanaimo (0.3.0) 72 | nap (1.1.0) 73 | netrc (0.11.0) 74 | public_suffix (4.0.6) 75 | rexml (3.2.5) 76 | ruby-macho (2.5.1) 77 | typhoeus (1.4.0) 78 | ethon (>= 0.9.0) 79 | tzinfo (2.0.4) 80 | concurrent-ruby (~> 1.0) 81 | xcodeproj (1.21.0) 82 | CFPropertyList (>= 2.3.3, < 4.0) 83 | atomos (~> 0.1.3) 84 | claide (>= 1.0.2, < 2.0) 85 | colored2 (~> 3.1) 86 | nanaimo (~> 0.3.0) 87 | rexml (~> 3.2.4) 88 | zeitwerk (2.5.4) 89 | PLATFORMS 90 | ruby 91 | DEPENDENCIES 92 | cocoapods (~> 1.11, >= 1.11.2) 93 | RUBY VERSION 94 | ruby 2.7.4p191 95 | BUNDLED WITH 96 | 2.2.27 -------------------------------------------------------------------------------- /example/android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | android 4 | Project android created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/android/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir= 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format 22 | * bundleCommand: "ram-bundle", 23 | * 24 | * // whether to bundle JS and assets in debug mode 25 | * bundleInDebug: false, 26 | * 27 | * // whether to bundle JS and assets in release mode 28 | * bundleInRelease: true, 29 | * 30 | * // whether to bundle JS and assets in another build variant (if configured). 31 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 32 | * // The configuration property can be in the following formats 33 | * // 'bundleIn${productFlavor}${buildType}' 34 | * // 'bundleIn${buildType}' 35 | * // bundleInFreeDebug: true, 36 | * // bundleInPaidRelease: true, 37 | * // bundleInBeta: true, 38 | * 39 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 40 | * // for DetectorExample: to disable dev mode in the staging build type (if configured) 41 | * devDisabledInStaging: true, 42 | * // The configuration property can be in the following formats 43 | * // 'devDisabledIn${productFlavor}${buildType}' 44 | * // 'devDisabledIn${buildType}' 45 | * 46 | * // the root of your project, i.e. where "package.json" lives 47 | * root: "../../", 48 | * 49 | * // where to put the JS bundle asset in debug mode 50 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 51 | * 52 | * // where to put the JS bundle asset in release mode 53 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 54 | * 55 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 56 | * // require('./image.png')), in debug mode 57 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 58 | * 59 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 60 | * // require('./image.png')), in release mode 61 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 62 | * 63 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 64 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 65 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 66 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 67 | * // for DetectorExample, you might want to remove it from here. 68 | * inputExcludes: ["android/**", "ios/**"], 69 | * 70 | * // override which node gets called and with what additional arguments 71 | * nodeExecutableAndArgs: ["node"], 72 | * 73 | * // supply additional arguments to the packager 74 | * extraPackagerArgs: [] 75 | * ] 76 | */ 77 | 78 | project.ext.react = [ 79 | enableHermes: false, // clean and rebuild if changing 80 | ] 81 | 82 | apply from: "../../node_modules/react-native/react.gradle" 83 | 84 | /** 85 | * Set this to true to create two separate APKs instead of one: 86 | * - An APK that only works on ARM devices 87 | * - An APK that only works on x86 devices 88 | * The advantage is the size of the APK is reduced by about 4MB. 89 | * Upload all the APKs to the Play Store and people will download 90 | * the correct one based on the CPU architecture of their device. 91 | */ 92 | def enableSeparateBuildPerCPUArchitecture = false 93 | 94 | /** 95 | * Run Proguard to shrink the Java bytecode in release builds. 96 | */ 97 | def enableProguardInReleaseBuilds = false 98 | 99 | /** 100 | * The preferred build flavor of JavaScriptCore. 101 | * 102 | * For DetectorExample, to use the international variant, you can use: 103 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 104 | * 105 | * The international variant includes ICU i18n library and necessary data 106 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 107 | * give correct results when using with locales other than en-US. Note that 108 | * this variant is about 6MiB larger per architecture than default. 109 | */ 110 | def jscFlavor = 'org.webkit:android-jsc:+' 111 | 112 | /** 113 | * Whether to enable the Hermes VM. 114 | * 115 | * This should be set on project.ext.react and mirrored here. If it is not set 116 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 117 | * and the benefits of using Hermes will therefore be sharply reduced. 118 | */ 119 | def enableHermes = project.ext.react.get("enableHermes", false); 120 | 121 | /** 122 | * Architectures to build native code for in debug. 123 | */ 124 | def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures") 125 | 126 | android { 127 | ndkVersion rootProject.ext.ndkVersion 128 | 129 | compileSdkVersion rootProject.ext.compileSdkVersion 130 | 131 | defaultConfig { 132 | applicationId "com.example.reactnativedetector" 133 | minSdkVersion rootProject.ext.minSdkVersion 134 | targetSdkVersion rootProject.ext.targetSdkVersion 135 | versionCode 1 136 | versionName "1.0" 137 | } 138 | splits { 139 | abi { 140 | reset() 141 | enable enableSeparateBuildPerCPUArchitecture 142 | universalApk false // If true, also generate a universal APK 143 | include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 144 | } 145 | } 146 | signingConfigs { 147 | debug { 148 | storeFile file('debug.keystore') 149 | storePassword 'android' 150 | keyAlias 'androiddebugkey' 151 | keyPassword 'android' 152 | } 153 | } 154 | buildTypes { 155 | debug { 156 | signingConfig signingConfigs.debug 157 | if (nativeArchitectures) { 158 | ndk { 159 | abiFilters nativeArchitectures.split(',') 160 | } 161 | } 162 | } 163 | release { 164 | // Caution! In production, you need to generate your own keystore file. 165 | // see https://facebook.github.io/react-native/docs/signed-apk-android. 166 | signingConfig signingConfigs.debug 167 | minifyEnabled enableProguardInReleaseBuilds 168 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 169 | } 170 | } 171 | // applicationVariants are e.g. debug, release 172 | applicationVariants.all { variant -> 173 | variant.outputs.each { output -> 174 | // For each separate APK per architecture, set a unique version code as described here: 175 | // https://developer.android.com/studio/build/configure-apk-splits.html 176 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 177 | def abi = output.getFilter(OutputFile.ABI) 178 | if (abi != null) { // null for the universal-debug, universal-release variants 179 | output.versionCodeOverride = 180 | defaultConfig.versionCode * 1000 + versionCodes.get(abi) 181 | } 182 | 183 | } 184 | } 185 | } 186 | 187 | dependencies { 188 | implementation fileTree(dir: "libs", include: ["*.jar"]) 189 | //noinspection GradleDynamicVersion 190 | implementation "com.facebook.react:react-native:+" // From node_modules 191 | 192 | 193 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 194 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { 195 | exclude group:'com.facebook.fbjni' 196 | } 197 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 198 | exclude group:'com.facebook.flipper' 199 | exclude group:'com.squareup.okhttp3', module:'okhttp' 200 | } 201 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { 202 | exclude group:'com.facebook.flipper' 203 | } 204 | 205 | if (enableHermes) { 206 | def hermesPath = "../../node_modules/hermes-engine/android/"; 207 | debugImplementation files(hermesPath + "hermes-debug.aar") 208 | releaseImplementation files(hermesPath + "hermes-release.aar") 209 | } else { 210 | implementation jscFlavor 211 | } 212 | 213 | implementation project(':reactnativedetector') 214 | } 215 | 216 | // Run this once to be able to run the application with BUCK 217 | // puts all compile dependencies into folder libs for BUCK to use 218 | task copyDownloadableDepsToLibs(type: Copy) { 219 | from configurations.implementation 220 | into 'libs' 221 | } 222 | 223 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 224 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/DetectorExample/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example.reactnativedetector; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin; 21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | public class ReactNativeFlipper { 28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 29 | if (FlipperUtils.shouldEnableFlipper(context)) { 30 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 31 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 32 | client.addPlugin(new ReactFlipperPlugin()); 33 | client.addPlugin(new DatabasesFlipperPlugin(context)); 34 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 35 | client.addPlugin(CrashReporterPlugin.getInstance()); 36 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 37 | NetworkingModule.setCustomClientBuilder( 38 | new NetworkingModule.CustomClientBuilder() { 39 | @Override 40 | public void apply(OkHttpClient.Builder builder) { 41 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 42 | } 43 | }); 44 | client.addPlugin(networkFlipperPlugin); 45 | client.start(); 46 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 47 | // Hence we run if after all native modules have been initialized 48 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 49 | if (reactContext == null) { 50 | reactInstanceManager.addReactInstanceEventListener( 51 | new ReactInstanceManager.ReactInstanceEventListener() { 52 | @Override 53 | public void onReactContextInitialized(ReactContext reactContext) { 54 | reactInstanceManager.removeReactInstanceEventListener(this); 55 | reactContext.runOnNativeModulesQueueThread( 56 | new Runnable() { 57 | @Override 58 | public void run() { 59 | client.addPlugin(new FrescoFlipperPlugin()); 60 | } 61 | }); 62 | } 63 | }); 64 | } else { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/DetectorExample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.reactnativedetector; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. This is used to schedule 9 | * rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "DetectorExample"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/DetectorExample/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.reactnativedetector; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactApplication; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.ReactInstanceManager; 10 | import com.facebook.soloader.SoLoader; 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.util.List; 13 | 14 | import com.reactnativedetector.DetectorPackage; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = 19 | new ReactNativeHost(this) { 20 | @Override 21 | public boolean getUseDeveloperSupport() { 22 | return BuildConfig.DEBUG; 23 | } 24 | 25 | @Override 26 | protected List getPackages() { 27 | @SuppressWarnings("UnnecessaryLocalVariable") 28 | List packages = new PackageList(this).getPackages(); 29 | // Packages that cannot be autolinked yet can be added manually here, for DetectorExample: 30 | // packages.add(new MyReactNativePackage()); 31 | packages.add(new DetectorPackage()); 32 | 33 | return packages; 34 | } 35 | 36 | @Override 37 | protected String getJSMainModuleName() { 38 | return "index"; 39 | } 40 | }; 41 | 42 | @Override 43 | public ReactNativeHost getReactNativeHost() { 44 | return mReactNativeHost; 45 | } 46 | 47 | @Override 48 | public void onCreate() { 49 | super.onCreate(); 50 | SoLoader.init(this, /* native exopackage */ false); 51 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled 52 | } 53 | 54 | /** 55 | * Loads Flipper in React Native templates. 56 | * 57 | * @param context 58 | */ 59 | private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 60 | if (BuildConfig.DEBUG) { 61 | try { 62 | /* 63 | We use reflection here to pick up the class that initializes Flipper, 64 | since Flipper library is not available in release mode 65 | */ 66 | Class aClass = Class.forName("com.reactnativedetectorExample.ReactNativeFlipper"); 67 | aClass 68 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 69 | .invoke(null, context, reactInstanceManager); 70 | } catch (ClassNotFoundException e) { 71 | e.printStackTrace(); 72 | } catch (NoSuchMethodException e) { 73 | e.printStackTrace(); 74 | } catch (IllegalAccessException e) { 75 | e.printStackTrace(); 76 | } catch (InvocationTargetException e) { 77 | e.printStackTrace(); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 18 | 19 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Detector Example 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "30.0.2" 6 | minSdkVersion = 21 7 | compileSdkVersion = 30 8 | targetSdkVersion = 30 9 | ndkVersion = "21.4.7075529" 10 | } 11 | repositories { 12 | google() 13 | mavenCentral() 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle:4.2.2") 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | maven { 25 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 26 | url("$rootDir/../node_modules/react-native/android") 27 | } 28 | maven { 29 | // Android JSC is installed from npm 30 | url("$rootDir/../node_modules/jsc-android/dist") 31 | } 32 | mavenCentral { 33 | // We don't want to fetch react-native from Maven Central as there are 34 | // older versions over there. 35 | content { 36 | excludeGroup "com.facebook.react" 37 | } 38 | } 39 | google() 40 | maven { url 'https://www.jitpack.io' } 41 | } 42 | } -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx1024m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.99.0 -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AzizAK/react-native-detector/17931004180b5d409a5978d370ff71ea0f4a1527/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'DetectorExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | 5 | include ':reactnativedetector' 6 | project(':reactnativedetector').projectDir = new File(rootProject.projectDir, '../../android') 7 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DetectorExample", 3 | "displayName": "Detector Example" 4 | } 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | alias: { 11 | [pak.name]: path.join(__dirname, '..', pak.source), 12 | }, 13 | }, 14 | ], 15 | ], 16 | }; 17 | -------------------------------------------------------------------------------- /example/index.tsx: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/ios/DetectorExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/DetectorExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0D1336C0461A88D01186E375 /* libPods-DetectorExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BCEA90A70F4BEAD7E9FA28B2 /* libPods-DetectorExample.a */; }; 11 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 12 | 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 14 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 15 | 20F357B024636CDF00C146DC /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20F357AF24636CDF00C146DC /* File.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = ""; }; 20 | 13B07F961A680F5B00A75B9A /* DetectorExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DetectorExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = DetectorExample/AppDelegate.h; sourceTree = ""; }; 22 | 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = DetectorExample/AppDelegate.m; sourceTree = ""; }; 23 | 13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 24 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = DetectorExample/Images.xcassets; sourceTree = ""; }; 25 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = DetectorExample/Info.plist; sourceTree = ""; }; 26 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = DetectorExample/main.m; sourceTree = ""; }; 27 | 20F357AD24636CDE00C146DC /* DetectorExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DetectorExample-Bridging-Header.h"; sourceTree = ""; }; 28 | 20F357AE24636CDF00C146DC /* DetectorExample-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DetectorExample-Bridging-Header.h"; sourceTree = ""; }; 29 | 20F357AF24636CDF00C146DC /* File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = ""; }; 30 | 4D7192F03A36A017E887435B /* Pods-DetectorExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DetectorExample.release.xcconfig"; path = "Target Support Files/Pods-DetectorExample/Pods-DetectorExample.release.xcconfig"; sourceTree = ""; }; 31 | 871719007ECC5EAD276C345C /* Pods-DetectorExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DetectorExample.debug.xcconfig"; path = "Target Support Files/Pods-DetectorExample/Pods-DetectorExample.debug.xcconfig"; sourceTree = ""; }; 32 | BCEA90A70F4BEAD7E9FA28B2 /* libPods-DetectorExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DetectorExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | 0D1336C0461A88D01186E375 /* libPods-DetectorExample.a in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 13B07FAE1A68108700A75B9A /* DetectorExample */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 008F07F21AC5B25A0029DE68 /* main.jsbundle */, 52 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 53 | 13B07FB01A68108700A75B9A /* AppDelegate.m */, 54 | 13B07FB51A68108700A75B9A /* Images.xcassets */, 55 | 13B07FB61A68108700A75B9A /* Info.plist */, 56 | 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, 57 | 13B07FB71A68108700A75B9A /* main.m */, 58 | ); 59 | name = DetectorExample; 60 | sourceTree = ""; 61 | }; 62 | 1CFFDEF7170271C97B8B7E5A /* Pods */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 871719007ECC5EAD276C345C /* Pods-DetectorExample.debug.xcconfig */, 66 | 4D7192F03A36A017E887435B /* Pods-DetectorExample.release.xcconfig */, 67 | ); 68 | path = Pods; 69 | sourceTree = ""; 70 | }; 71 | 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */, 75 | BCEA90A70F4BEAD7E9FA28B2 /* libPods-DetectorExample.a */, 76 | ); 77 | name = Frameworks; 78 | sourceTree = ""; 79 | }; 80 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | ); 84 | name = Libraries; 85 | sourceTree = ""; 86 | }; 87 | 83CBB9F61A601CBA00E9B192 = { 88 | isa = PBXGroup; 89 | children = ( 90 | 20F357AF24636CDF00C146DC /* File.swift */, 91 | 20F357AE24636CDF00C146DC /* DetectorExample-Bridging-Header.h */, 92 | 13B07FAE1A68108700A75B9A /* DetectorExample */, 93 | 832341AE1AAA6A7D00B99B32 /* Libraries */, 94 | 83CBBA001A601CBA00E9B192 /* Products */, 95 | 2D16E6871FA4F8E400B85C8A /* Frameworks */, 96 | 1CFFDEF7170271C97B8B7E5A /* Pods */, 97 | 20F357AD24636CDE00C146DC /* DetectorExample-Bridging-Header.h */, 98 | ); 99 | indentWidth = 2; 100 | sourceTree = ""; 101 | tabWidth = 2; 102 | usesTabs = 0; 103 | }; 104 | 83CBBA001A601CBA00E9B192 /* Products */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 13B07F961A680F5B00A75B9A /* DetectorExample.app */, 108 | ); 109 | name = Products; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 13B07F861A680F5B00A75B9A /* DetectorExample */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "DetectorExample" */; 118 | buildPhases = ( 119 | CCCC07BCAFDEF1FCADC0D0C9 /* [CP] Check Pods Manifest.lock */, 120 | FD10A7F022414F080027D42C /* Start Packager */, 121 | 13B07F871A680F5B00A75B9A /* Sources */, 122 | 13B07F8C1A680F5B00A75B9A /* Frameworks */, 123 | 13B07F8E1A680F5B00A75B9A /* Resources */, 124 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, 125 | ); 126 | buildRules = ( 127 | ); 128 | dependencies = ( 129 | ); 130 | name = DetectorExample; 131 | productName = DetectorExample; 132 | productReference = 13B07F961A680F5B00A75B9A /* DetectorExample.app */; 133 | productType = "com.apple.product-type.application"; 134 | }; 135 | /* End PBXNativeTarget section */ 136 | 137 | /* Begin PBXProject section */ 138 | 83CBB9F71A601CBA00E9B192 /* Project object */ = { 139 | isa = PBXProject; 140 | attributes = { 141 | LastUpgradeCheck = 0940; 142 | ORGANIZATIONNAME = Facebook; 143 | TargetAttributes = { 144 | 13B07F861A680F5B00A75B9A = { 145 | LastSwiftMigration = 1110; 146 | }; 147 | }; 148 | }; 149 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "DetectorExample" */; 150 | compatibilityVersion = "Xcode 3.2"; 151 | developmentRegion = English; 152 | hasScannedForEncodings = 0; 153 | knownRegions = ( 154 | English, 155 | en, 156 | Base, 157 | ); 158 | mainGroup = 83CBB9F61A601CBA00E9B192; 159 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; 160 | projectDirPath = ""; 161 | projectRoot = ""; 162 | targets = ( 163 | 13B07F861A680F5B00A75B9A /* DetectorExample */, 164 | ); 165 | }; 166 | /* End PBXProject section */ 167 | 168 | /* Begin PBXResourcesBuildPhase section */ 169 | 13B07F8E1A680F5B00A75B9A /* Resources */ = { 170 | isa = PBXResourcesBuildPhase; 171 | buildActionMask = 2147483647; 172 | files = ( 173 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 174 | 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | }; 178 | /* End PBXResourcesBuildPhase section */ 179 | 180 | /* Begin PBXShellScriptBuildPhase section */ 181 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { 182 | isa = PBXShellScriptBuildPhase; 183 | buildActionMask = 2147483647; 184 | files = ( 185 | ); 186 | inputPaths = ( 187 | ); 188 | name = "Bundle React Native code and images"; 189 | outputPaths = ( 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | shellPath = /bin/sh; 193 | shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; 194 | }; 195 | CCCC07BCAFDEF1FCADC0D0C9 /* [CP] Check Pods Manifest.lock */ = { 196 | isa = PBXShellScriptBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | ); 200 | inputFileListPaths = ( 201 | ); 202 | inputPaths = ( 203 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 204 | "${PODS_ROOT}/Manifest.lock", 205 | ); 206 | name = "[CP] Check Pods Manifest.lock"; 207 | outputFileListPaths = ( 208 | ); 209 | outputPaths = ( 210 | "$(DERIVED_FILE_DIR)/Pods-DetectorExample-checkManifestLockResult.txt", 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | shellPath = /bin/sh; 214 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 215 | showEnvVarsInLog = 0; 216 | }; 217 | FD10A7F022414F080027D42C /* Start Packager */ = { 218 | isa = PBXShellScriptBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | ); 222 | inputFileListPaths = ( 223 | ); 224 | inputPaths = ( 225 | ); 226 | name = "Start Packager"; 227 | outputFileListPaths = ( 228 | ); 229 | outputPaths = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | shellPath = /bin/sh; 233 | shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n"; 234 | showEnvVarsInLog = 0; 235 | }; 236 | /* End PBXShellScriptBuildPhase section */ 237 | 238 | /* Begin PBXSourcesBuildPhase section */ 239 | 13B07F871A680F5B00A75B9A /* Sources */ = { 240 | isa = PBXSourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, 244 | 20F357B024636CDF00C146DC /* File.swift in Sources */, 245 | 13B07FC11A68108700A75B9A /* main.m in Sources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | /* End PBXSourcesBuildPhase section */ 250 | 251 | /* Begin PBXVariantGroup section */ 252 | 13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = { 253 | isa = PBXVariantGroup; 254 | children = ( 255 | 13B07FB21A68108700A75B9A /* Base */, 256 | ); 257 | name = LaunchScreen.xib; 258 | path = DetectorExample; 259 | sourceTree = ""; 260 | }; 261 | /* End PBXVariantGroup section */ 262 | 263 | /* Begin XCBuildConfiguration section */ 264 | 13B07F941A680F5B00A75B9A /* Debug */ = { 265 | isa = XCBuildConfiguration; 266 | baseConfigurationReference = 871719007ECC5EAD276C345C /* Pods-DetectorExample.debug.xcconfig */; 267 | buildSettings = { 268 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 269 | CLANG_ENABLE_MODULES = YES; 270 | CURRENT_PROJECT_VERSION = 1; 271 | DEAD_CODE_STRIPPING = NO; 272 | INFOPLIST_FILE = DetectorExample/Info.plist; 273 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 274 | OTHER_CFLAGS = ( 275 | "$(inherited)", 276 | "-DFB_SONARKIT_ENABLED=1", 277 | ); 278 | OTHER_LDFLAGS = ( 279 | "$(inherited)", 280 | "-ObjC", 281 | "-lc++", 282 | ); 283 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.DetectorExample.$(PRODUCT_NAME:rfc1034identifier)"; 284 | PRODUCT_NAME = DetectorExample; 285 | SWIFT_OBJC_BRIDGING_HEADER = "DetectorExample-Bridging-Header.h"; 286 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 287 | SWIFT_VERSION = 5.0; 288 | VERSIONING_SYSTEM = "apple-generic"; 289 | }; 290 | name = Debug; 291 | }; 292 | 13B07F951A680F5B00A75B9A /* Release */ = { 293 | isa = XCBuildConfiguration; 294 | baseConfigurationReference = 4D7192F03A36A017E887435B /* Pods-DetectorExample.release.xcconfig */; 295 | buildSettings = { 296 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 297 | CLANG_ENABLE_MODULES = YES; 298 | CURRENT_PROJECT_VERSION = 1; 299 | INFOPLIST_FILE = DetectorExample/Info.plist; 300 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 301 | OTHER_CFLAGS = ( 302 | "$(inherited)", 303 | "-DFB_SONARKIT_ENABLED=1", 304 | ); 305 | OTHER_LDFLAGS = ( 306 | "$(inherited)", 307 | "-ObjC", 308 | "-lc++", 309 | ); 310 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.DetectorExample.$(PRODUCT_NAME:rfc1034identifier)"; 311 | PRODUCT_NAME = DetectorExample; 312 | SWIFT_OBJC_BRIDGING_HEADER = "DetectorExample-Bridging-Header.h"; 313 | SWIFT_VERSION = 5.0; 314 | VERSIONING_SYSTEM = "apple-generic"; 315 | }; 316 | name = Release; 317 | }; 318 | 83CBBA201A601CBA00E9B192 /* Debug */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ALWAYS_SEARCH_USER_PATHS = NO; 322 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 323 | CLANG_CXX_LIBRARY = "libc++"; 324 | CLANG_ENABLE_MODULES = YES; 325 | CLANG_ENABLE_OBJC_ARC = YES; 326 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 327 | CLANG_WARN_BOOL_CONVERSION = YES; 328 | CLANG_WARN_COMMA = YES; 329 | CLANG_WARN_CONSTANT_CONVERSION = YES; 330 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 331 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 332 | CLANG_WARN_EMPTY_BODY = YES; 333 | CLANG_WARN_ENUM_CONVERSION = YES; 334 | CLANG_WARN_INFINITE_RECURSION = YES; 335 | CLANG_WARN_INT_CONVERSION = YES; 336 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 337 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 338 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 341 | CLANG_WARN_STRICT_PROTOTYPES = YES; 342 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 343 | CLANG_WARN_UNREACHABLE_CODE = YES; 344 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 345 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 346 | COPY_PHASE_STRIP = NO; 347 | ENABLE_STRICT_OBJC_MSGSEND = YES; 348 | ENABLE_TESTABILITY = YES; 349 | GCC_C_LANGUAGE_STANDARD = gnu99; 350 | GCC_DYNAMIC_NO_PIC = NO; 351 | GCC_NO_COMMON_BLOCKS = YES; 352 | GCC_OPTIMIZATION_LEVEL = 0; 353 | GCC_PREPROCESSOR_DEFINITIONS = ( 354 | "DEBUG=1", 355 | "$(inherited)", 356 | ); 357 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 358 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 359 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 360 | GCC_WARN_UNDECLARED_SELECTOR = YES; 361 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 362 | GCC_WARN_UNUSED_FUNCTION = YES; 363 | GCC_WARN_UNUSED_VARIABLE = YES; 364 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 365 | MTL_ENABLE_DEBUG_INFO = YES; 366 | ONLY_ACTIVE_ARCH = YES; 367 | SDKROOT = iphoneos; 368 | }; 369 | name = Debug; 370 | }; 371 | 83CBBA211A601CBA00E9B192 /* Release */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ALWAYS_SEARCH_USER_PATHS = NO; 375 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 376 | CLANG_CXX_LIBRARY = "libc++"; 377 | CLANG_ENABLE_MODULES = YES; 378 | CLANG_ENABLE_OBJC_ARC = YES; 379 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 380 | CLANG_WARN_BOOL_CONVERSION = YES; 381 | CLANG_WARN_COMMA = YES; 382 | CLANG_WARN_CONSTANT_CONVERSION = YES; 383 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 384 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 385 | CLANG_WARN_EMPTY_BODY = YES; 386 | CLANG_WARN_ENUM_CONVERSION = YES; 387 | CLANG_WARN_INFINITE_RECURSION = YES; 388 | CLANG_WARN_INT_CONVERSION = YES; 389 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 390 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 391 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 392 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 393 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 394 | CLANG_WARN_STRICT_PROTOTYPES = YES; 395 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 396 | CLANG_WARN_UNREACHABLE_CODE = YES; 397 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 398 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 399 | COPY_PHASE_STRIP = YES; 400 | ENABLE_NS_ASSERTIONS = NO; 401 | ENABLE_STRICT_OBJC_MSGSEND = YES; 402 | GCC_C_LANGUAGE_STANDARD = gnu99; 403 | GCC_NO_COMMON_BLOCKS = YES; 404 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 405 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 406 | GCC_WARN_UNDECLARED_SELECTOR = YES; 407 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 408 | GCC_WARN_UNUSED_FUNCTION = YES; 409 | GCC_WARN_UNUSED_VARIABLE = YES; 410 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 411 | MTL_ENABLE_DEBUG_INFO = NO; 412 | SDKROOT = iphoneos; 413 | VALIDATE_PRODUCT = YES; 414 | }; 415 | name = Release; 416 | }; 417 | /* End XCBuildConfiguration section */ 418 | 419 | /* Begin XCConfigurationList section */ 420 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "DetectorExample" */ = { 421 | isa = XCConfigurationList; 422 | buildConfigurations = ( 423 | 13B07F941A680F5B00A75B9A /* Debug */, 424 | 13B07F951A680F5B00A75B9A /* Release */, 425 | ); 426 | defaultConfigurationIsVisible = 0; 427 | defaultConfigurationName = Release; 428 | }; 429 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "DetectorExample" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | 83CBBA201A601CBA00E9B192 /* Debug */, 433 | 83CBBA211A601CBA00E9B192 /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | defaultConfigurationName = Release; 437 | }; 438 | /* End XCConfigurationList section */ 439 | }; 440 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; 441 | } 442 | -------------------------------------------------------------------------------- /example/ios/DetectorExample.xcodeproj/xcshareddata/xcschemes/DetectorExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 51 | 52 | 53 | 54 | 55 | 56 | 66 | 68 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /example/ios/DetectorExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/DetectorExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/DetectorExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (nonatomic, strong) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /example/ios/DetectorExample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import "AppDelegate.h" 9 | 10 | #import 11 | #import 12 | #import 13 | 14 | #if DEBUG 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | #import 21 | static void InitializeFlipper(UIApplication *application) { 22 | FlipperClient *client = [FlipperClient sharedClient]; 23 | SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; 24 | [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; 25 | [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; 26 | [client addPlugin:[FlipperKitReactPlugin new]]; 27 | [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; 28 | [client start]; 29 | } 30 | #endif 31 | 32 | @implementation AppDelegate 33 | 34 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 35 | { 36 | #if DEBUG 37 | InitializeFlipper(application); 38 | #endif 39 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 40 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 41 | moduleName:@"DetectorExample" 42 | initialProperties:nil]; 43 | 44 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 45 | 46 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 47 | UIViewController *rootViewController = [UIViewController new]; 48 | rootViewController.view = rootView; 49 | self.window.rootViewController = rootViewController; 50 | [self.window makeKeyAndVisible]; 51 | return YES; 52 | } 53 | 54 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 55 | { 56 | #if DEBUG 57 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 58 | #else 59 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 60 | #endif 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /example/ios/DetectorExample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /example/ios/DetectorExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /example/ios/DetectorExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/DetectorExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | Detector Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSAllowsArbitraryLoads 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSLocationWhenInUseUsageDescription 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UIViewControllerBasedStatusBarAppearance 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /example/ios/DetectorExample/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | #import 9 | 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // DetectorExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '9.0' 2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 3 | 4 | def add_flipper_pods! 5 | version = '~> 0.33.1' 6 | pod 'FlipperKit', version, :configuration => 'Debug' 7 | pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug' 8 | pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug' 9 | pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug' 10 | pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug' 11 | end 12 | # Post Install processing for Flipper 13 | def flipper_post_install(installer) 14 | installer.pods_project.targets.each do |target| 15 | if target.name == 'YogaKit' 16 | target.build_configurations.each do |config| 17 | config.build_settings['SWIFT_VERSION'] = '4.1' 18 | end 19 | end 20 | end 21 | end 22 | 23 | target 'DetectorExample' do 24 | # Pods for DetectorExample 25 | pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" 26 | pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" 27 | pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" 28 | pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" 29 | pod 'React', :path => '../node_modules/react-native/' 30 | pod 'React-Core', :path => '../node_modules/react-native/' 31 | pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' 32 | pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' 33 | pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' 34 | pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' 35 | pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' 36 | pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' 37 | pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' 38 | pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' 39 | pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' 40 | pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' 41 | pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' 42 | pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/' 43 | 44 | pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' 45 | pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' 46 | pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' 47 | pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' 48 | pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon" 49 | pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" 50 | pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true 51 | 52 | pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' 53 | pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' 54 | pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' 55 | 56 | pod 'react-native-detector', :path => '../..' 57 | 58 | use_native_modules! 59 | 60 | # Enables Flipper. 61 | # 62 | # Note that if you have use_frameworks! enabled, Flipper will not work and 63 | # you should disable these next few lines. 64 | add_flipper_pods! 65 | post_install do |installer| 66 | flipper_post_install(installer) 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - boost-for-react-native (1.63.0) 3 | - CocoaAsyncSocket (7.6.4) 4 | - CocoaLibEvent (1.0.0) 5 | - DoubleConversion (1.1.6) 6 | - FBLazyVector (0.62.0) 7 | - FBReactNativeSpec (0.62.0): 8 | - Folly (= 2018.10.22.00) 9 | - RCTRequired (= 0.62.0) 10 | - RCTTypeSafety (= 0.62.0) 11 | - React-Core (= 0.62.0) 12 | - React-jsi (= 0.62.0) 13 | - ReactCommon/turbomodule/core (= 0.62.0) 14 | - Flipper (0.33.1): 15 | - Flipper-Folly (~> 2.1) 16 | - Flipper-RSocket (~> 1.0) 17 | - Flipper-DoubleConversion (1.1.7) 18 | - Flipper-Folly (2.2.0): 19 | - boost-for-react-native 20 | - CocoaLibEvent (~> 1.0) 21 | - Flipper-DoubleConversion 22 | - Flipper-Glog 23 | - OpenSSL-Universal (= 1.0.2.19) 24 | - Flipper-Glog (0.3.6) 25 | - Flipper-PeerTalk (0.0.4) 26 | - Flipper-RSocket (1.1.0): 27 | - Flipper-Folly (~> 2.2) 28 | - FlipperKit (0.33.1): 29 | - FlipperKit/Core (= 0.33.1) 30 | - FlipperKit/Core (0.33.1): 31 | - Flipper (~> 0.33.1) 32 | - FlipperKit/CppBridge 33 | - FlipperKit/FBCxxFollyDynamicConvert 34 | - FlipperKit/FBDefines 35 | - FlipperKit/FKPortForwarding 36 | - FlipperKit/CppBridge (0.33.1): 37 | - Flipper (~> 0.33.1) 38 | - FlipperKit/FBCxxFollyDynamicConvert (0.33.1): 39 | - Flipper-Folly (~> 2.1) 40 | - FlipperKit/FBDefines (0.33.1) 41 | - FlipperKit/FKPortForwarding (0.33.1): 42 | - CocoaAsyncSocket (~> 7.6) 43 | - Flipper-PeerTalk (~> 0.0.4) 44 | - FlipperKit/FlipperKitHighlightOverlay (0.33.1) 45 | - FlipperKit/FlipperKitLayoutPlugin (0.33.1): 46 | - FlipperKit/Core 47 | - FlipperKit/FlipperKitHighlightOverlay 48 | - FlipperKit/FlipperKitLayoutTextSearchable 49 | - YogaKit (~> 1.18) 50 | - FlipperKit/FlipperKitLayoutTextSearchable (0.33.1) 51 | - FlipperKit/FlipperKitNetworkPlugin (0.33.1): 52 | - FlipperKit/Core 53 | - FlipperKit/FlipperKitReactPlugin (0.33.1): 54 | - FlipperKit/Core 55 | - FlipperKit/FlipperKitUserDefaultsPlugin (0.33.1): 56 | - FlipperKit/Core 57 | - FlipperKit/SKIOSNetworkPlugin (0.33.1): 58 | - FlipperKit/Core 59 | - FlipperKit/FlipperKitNetworkPlugin 60 | - Folly (2018.10.22.00): 61 | - boost-for-react-native 62 | - DoubleConversion 63 | - Folly/Default (= 2018.10.22.00) 64 | - glog 65 | - Folly/Default (2018.10.22.00): 66 | - boost-for-react-native 67 | - DoubleConversion 68 | - glog 69 | - glog (0.3.5) 70 | - OpenSSL-Universal (1.0.2.19): 71 | - OpenSSL-Universal/Static (= 1.0.2.19) 72 | - OpenSSL-Universal/Static (1.0.2.19) 73 | - RCTRequired (0.62.0) 74 | - RCTTypeSafety (0.62.0): 75 | - FBLazyVector (= 0.62.0) 76 | - Folly (= 2018.10.22.00) 77 | - RCTRequired (= 0.62.0) 78 | - React-Core (= 0.62.0) 79 | - React (0.62.0): 80 | - React-Core (= 0.62.0) 81 | - React-Core/DevSupport (= 0.62.0) 82 | - React-Core/RCTWebSocket (= 0.62.0) 83 | - React-RCTActionSheet (= 0.62.0) 84 | - React-RCTAnimation (= 0.62.0) 85 | - React-RCTBlob (= 0.62.0) 86 | - React-RCTImage (= 0.62.0) 87 | - React-RCTLinking (= 0.62.0) 88 | - React-RCTNetwork (= 0.62.0) 89 | - React-RCTSettings (= 0.62.0) 90 | - React-RCTText (= 0.62.0) 91 | - React-RCTVibration (= 0.62.0) 92 | - React-Core (0.62.0): 93 | - Folly (= 2018.10.22.00) 94 | - glog 95 | - React-Core/Default (= 0.62.0) 96 | - React-cxxreact (= 0.62.0) 97 | - React-jsi (= 0.62.0) 98 | - React-jsiexecutor (= 0.62.0) 99 | - Yoga 100 | - React-Core/CoreModulesHeaders (0.62.0): 101 | - Folly (= 2018.10.22.00) 102 | - glog 103 | - React-Core/Default 104 | - React-cxxreact (= 0.62.0) 105 | - React-jsi (= 0.62.0) 106 | - React-jsiexecutor (= 0.62.0) 107 | - Yoga 108 | - React-Core/Default (0.62.0): 109 | - Folly (= 2018.10.22.00) 110 | - glog 111 | - React-cxxreact (= 0.62.0) 112 | - React-jsi (= 0.62.0) 113 | - React-jsiexecutor (= 0.62.0) 114 | - Yoga 115 | - React-Core/DevSupport (0.62.0): 116 | - Folly (= 2018.10.22.00) 117 | - glog 118 | - React-Core/Default (= 0.62.0) 119 | - React-Core/RCTWebSocket (= 0.62.0) 120 | - React-cxxreact (= 0.62.0) 121 | - React-jsi (= 0.62.0) 122 | - React-jsiexecutor (= 0.62.0) 123 | - React-jsinspector (= 0.62.0) 124 | - Yoga 125 | - React-Core/RCTActionSheetHeaders (0.62.0): 126 | - Folly (= 2018.10.22.00) 127 | - glog 128 | - React-Core/Default 129 | - React-cxxreact (= 0.62.0) 130 | - React-jsi (= 0.62.0) 131 | - React-jsiexecutor (= 0.62.0) 132 | - Yoga 133 | - React-Core/RCTAnimationHeaders (0.62.0): 134 | - Folly (= 2018.10.22.00) 135 | - glog 136 | - React-Core/Default 137 | - React-cxxreact (= 0.62.0) 138 | - React-jsi (= 0.62.0) 139 | - React-jsiexecutor (= 0.62.0) 140 | - Yoga 141 | - React-Core/RCTBlobHeaders (0.62.0): 142 | - Folly (= 2018.10.22.00) 143 | - glog 144 | - React-Core/Default 145 | - React-cxxreact (= 0.62.0) 146 | - React-jsi (= 0.62.0) 147 | - React-jsiexecutor (= 0.62.0) 148 | - Yoga 149 | - React-Core/RCTImageHeaders (0.62.0): 150 | - Folly (= 2018.10.22.00) 151 | - glog 152 | - React-Core/Default 153 | - React-cxxreact (= 0.62.0) 154 | - React-jsi (= 0.62.0) 155 | - React-jsiexecutor (= 0.62.0) 156 | - Yoga 157 | - React-Core/RCTLinkingHeaders (0.62.0): 158 | - Folly (= 2018.10.22.00) 159 | - glog 160 | - React-Core/Default 161 | - React-cxxreact (= 0.62.0) 162 | - React-jsi (= 0.62.0) 163 | - React-jsiexecutor (= 0.62.0) 164 | - Yoga 165 | - React-Core/RCTNetworkHeaders (0.62.0): 166 | - Folly (= 2018.10.22.00) 167 | - glog 168 | - React-Core/Default 169 | - React-cxxreact (= 0.62.0) 170 | - React-jsi (= 0.62.0) 171 | - React-jsiexecutor (= 0.62.0) 172 | - Yoga 173 | - React-Core/RCTSettingsHeaders (0.62.0): 174 | - Folly (= 2018.10.22.00) 175 | - glog 176 | - React-Core/Default 177 | - React-cxxreact (= 0.62.0) 178 | - React-jsi (= 0.62.0) 179 | - React-jsiexecutor (= 0.62.0) 180 | - Yoga 181 | - React-Core/RCTTextHeaders (0.62.0): 182 | - Folly (= 2018.10.22.00) 183 | - glog 184 | - React-Core/Default 185 | - React-cxxreact (= 0.62.0) 186 | - React-jsi (= 0.62.0) 187 | - React-jsiexecutor (= 0.62.0) 188 | - Yoga 189 | - React-Core/RCTVibrationHeaders (0.62.0): 190 | - Folly (= 2018.10.22.00) 191 | - glog 192 | - React-Core/Default 193 | - React-cxxreact (= 0.62.0) 194 | - React-jsi (= 0.62.0) 195 | - React-jsiexecutor (= 0.62.0) 196 | - Yoga 197 | - React-Core/RCTWebSocket (0.62.0): 198 | - Folly (= 2018.10.22.00) 199 | - glog 200 | - React-Core/Default (= 0.62.0) 201 | - React-cxxreact (= 0.62.0) 202 | - React-jsi (= 0.62.0) 203 | - React-jsiexecutor (= 0.62.0) 204 | - Yoga 205 | - React-CoreModules (0.62.0): 206 | - FBReactNativeSpec (= 0.62.0) 207 | - Folly (= 2018.10.22.00) 208 | - RCTTypeSafety (= 0.62.0) 209 | - React-Core/CoreModulesHeaders (= 0.62.0) 210 | - React-RCTImage (= 0.62.0) 211 | - ReactCommon/turbomodule/core (= 0.62.0) 212 | - React-cxxreact (0.62.0): 213 | - boost-for-react-native (= 1.63.0) 214 | - DoubleConversion 215 | - Folly (= 2018.10.22.00) 216 | - glog 217 | - React-jsinspector (= 0.62.0) 218 | - React-jsi (0.62.0): 219 | - boost-for-react-native (= 1.63.0) 220 | - DoubleConversion 221 | - Folly (= 2018.10.22.00) 222 | - glog 223 | - React-jsi/Default (= 0.62.0) 224 | - React-jsi/Default (0.62.0): 225 | - boost-for-react-native (= 1.63.0) 226 | - DoubleConversion 227 | - Folly (= 2018.10.22.00) 228 | - glog 229 | - React-jsiexecutor (0.62.0): 230 | - DoubleConversion 231 | - Folly (= 2018.10.22.00) 232 | - glog 233 | - React-cxxreact (= 0.62.0) 234 | - React-jsi (= 0.62.0) 235 | - React-jsinspector (0.62.0) 236 | - react-native-detector (0.1.0): 237 | - React 238 | - React-RCTActionSheet (0.62.0): 239 | - React-Core/RCTActionSheetHeaders (= 0.62.0) 240 | - React-RCTAnimation (0.62.0): 241 | - FBReactNativeSpec (= 0.62.0) 242 | - Folly (= 2018.10.22.00) 243 | - RCTTypeSafety (= 0.62.0) 244 | - React-Core/RCTAnimationHeaders (= 0.62.0) 245 | - ReactCommon/turbomodule/core (= 0.62.0) 246 | - React-RCTBlob (0.62.0): 247 | - FBReactNativeSpec (= 0.62.0) 248 | - Folly (= 2018.10.22.00) 249 | - React-Core/RCTBlobHeaders (= 0.62.0) 250 | - React-Core/RCTWebSocket (= 0.62.0) 251 | - React-jsi (= 0.62.0) 252 | - React-RCTNetwork (= 0.62.0) 253 | - ReactCommon/turbomodule/core (= 0.62.0) 254 | - React-RCTImage (0.62.0): 255 | - FBReactNativeSpec (= 0.62.0) 256 | - Folly (= 2018.10.22.00) 257 | - RCTTypeSafety (= 0.62.0) 258 | - React-Core/RCTImageHeaders (= 0.62.0) 259 | - React-RCTNetwork (= 0.62.0) 260 | - ReactCommon/turbomodule/core (= 0.62.0) 261 | - React-RCTLinking (0.62.0): 262 | - FBReactNativeSpec (= 0.62.0) 263 | - React-Core/RCTLinkingHeaders (= 0.62.0) 264 | - ReactCommon/turbomodule/core (= 0.62.0) 265 | - React-RCTNetwork (0.62.0): 266 | - FBReactNativeSpec (= 0.62.0) 267 | - Folly (= 2018.10.22.00) 268 | - RCTTypeSafety (= 0.62.0) 269 | - React-Core/RCTNetworkHeaders (= 0.62.0) 270 | - ReactCommon/turbomodule/core (= 0.62.0) 271 | - React-RCTSettings (0.62.0): 272 | - FBReactNativeSpec (= 0.62.0) 273 | - Folly (= 2018.10.22.00) 274 | - RCTTypeSafety (= 0.62.0) 275 | - React-Core/RCTSettingsHeaders (= 0.62.0) 276 | - ReactCommon/turbomodule/core (= 0.62.0) 277 | - React-RCTText (0.62.0): 278 | - React-Core/RCTTextHeaders (= 0.62.0) 279 | - React-RCTVibration (0.62.0): 280 | - FBReactNativeSpec (= 0.62.0) 281 | - Folly (= 2018.10.22.00) 282 | - React-Core/RCTVibrationHeaders (= 0.62.0) 283 | - ReactCommon/turbomodule/core (= 0.62.0) 284 | - ReactCommon/callinvoker (0.62.0): 285 | - DoubleConversion 286 | - Folly (= 2018.10.22.00) 287 | - glog 288 | - React-cxxreact (= 0.62.0) 289 | - ReactCommon/turbomodule/core (0.62.0): 290 | - DoubleConversion 291 | - Folly (= 2018.10.22.00) 292 | - glog 293 | - React-Core (= 0.62.0) 294 | - React-cxxreact (= 0.62.0) 295 | - React-jsi (= 0.62.0) 296 | - ReactCommon/callinvoker (= 0.62.0) 297 | - Yoga (1.14.0) 298 | - YogaKit (1.18.1): 299 | - Yoga (~> 1.14) 300 | 301 | DEPENDENCIES: 302 | - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) 303 | - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) 304 | - FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`) 305 | - FlipperKit (~> 0.33.1) 306 | - FlipperKit/FlipperKitLayoutPlugin (~> 0.33.1) 307 | - FlipperKit/FlipperKitReactPlugin (~> 0.33.1) 308 | - FlipperKit/FlipperKitUserDefaultsPlugin (~> 0.33.1) 309 | - FlipperKit/SKIOSNetworkPlugin (~> 0.33.1) 310 | - Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`) 311 | - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) 312 | - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) 313 | - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) 314 | - React (from `../node_modules/react-native/`) 315 | - React-Core (from `../node_modules/react-native/`) 316 | - React-Core/DevSupport (from `../node_modules/react-native/`) 317 | - React-Core/RCTWebSocket (from `../node_modules/react-native/`) 318 | - React-CoreModules (from `../node_modules/react-native/React/CoreModules`) 319 | - React-cxxreact (from `../node_modules/react-native/ReactCommon/cxxreact`) 320 | - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`) 321 | - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) 322 | - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) 323 | - react-native-detector (from `../..`) 324 | - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) 325 | - React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) 326 | - React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`) 327 | - React-RCTImage (from `../node_modules/react-native/Libraries/Image`) 328 | - React-RCTLinking (from `../node_modules/react-native/Libraries/LinkingIOS`) 329 | - React-RCTNetwork (from `../node_modules/react-native/Libraries/Network`) 330 | - React-RCTSettings (from `../node_modules/react-native/Libraries/Settings`) 331 | - React-RCTText (from `../node_modules/react-native/Libraries/Text`) 332 | - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) 333 | - ReactCommon/callinvoker (from `../node_modules/react-native/ReactCommon`) 334 | - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) 335 | - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) 336 | 337 | SPEC REPOS: 338 | trunk: 339 | - boost-for-react-native 340 | - CocoaAsyncSocket 341 | - CocoaLibEvent 342 | - Flipper 343 | - Flipper-DoubleConversion 344 | - Flipper-Folly 345 | - Flipper-Glog 346 | - Flipper-PeerTalk 347 | - Flipper-RSocket 348 | - FlipperKit 349 | - OpenSSL-Universal 350 | - YogaKit 351 | 352 | EXTERNAL SOURCES: 353 | DoubleConversion: 354 | :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec" 355 | FBLazyVector: 356 | :path: "../node_modules/react-native/Libraries/FBLazyVector" 357 | FBReactNativeSpec: 358 | :path: "../node_modules/react-native/Libraries/FBReactNativeSpec" 359 | Folly: 360 | :podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec" 361 | glog: 362 | :podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec" 363 | RCTRequired: 364 | :path: "../node_modules/react-native/Libraries/RCTRequired" 365 | RCTTypeSafety: 366 | :path: "../node_modules/react-native/Libraries/TypeSafety" 367 | React: 368 | :path: "../node_modules/react-native/" 369 | React-Core: 370 | :path: "../node_modules/react-native/" 371 | React-CoreModules: 372 | :path: "../node_modules/react-native/React/CoreModules" 373 | React-cxxreact: 374 | :path: "../node_modules/react-native/ReactCommon/cxxreact" 375 | React-jsi: 376 | :path: "../node_modules/react-native/ReactCommon/jsi" 377 | React-jsiexecutor: 378 | :path: "../node_modules/react-native/ReactCommon/jsiexecutor" 379 | React-jsinspector: 380 | :path: "../node_modules/react-native/ReactCommon/jsinspector" 381 | react-native-detector: 382 | :path: "../.." 383 | React-RCTActionSheet: 384 | :path: "../node_modules/react-native/Libraries/ActionSheetIOS" 385 | React-RCTAnimation: 386 | :path: "../node_modules/react-native/Libraries/NativeAnimation" 387 | React-RCTBlob: 388 | :path: "../node_modules/react-native/Libraries/Blob" 389 | React-RCTImage: 390 | :path: "../node_modules/react-native/Libraries/Image" 391 | React-RCTLinking: 392 | :path: "../node_modules/react-native/Libraries/LinkingIOS" 393 | React-RCTNetwork: 394 | :path: "../node_modules/react-native/Libraries/Network" 395 | React-RCTSettings: 396 | :path: "../node_modules/react-native/Libraries/Settings" 397 | React-RCTText: 398 | :path: "../node_modules/react-native/Libraries/Text" 399 | React-RCTVibration: 400 | :path: "../node_modules/react-native/Libraries/Vibration" 401 | ReactCommon: 402 | :path: "../node_modules/react-native/ReactCommon" 403 | Yoga: 404 | :path: "../node_modules/react-native/ReactCommon/yoga" 405 | 406 | SPEC CHECKSUMS: 407 | boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c 408 | CocoaAsyncSocket: 694058e7c0ed05a9e217d1b3c7ded962f4180845 409 | CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f 410 | DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2 411 | FBLazyVector: 545eccf4f6ef2de8fd450fd8a1edb3f913c7371a 412 | FBReactNativeSpec: 85c7f8347f4a6e911742228e89e245187afa298e 413 | Flipper: 6c1f484f9a88d30ab3e272800d53688439e50f69 414 | Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41 415 | Flipper-Folly: c12092ea368353b58e992843a990a3225d4533c3 416 | Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6 417 | Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9 418 | Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7 419 | FlipperKit: 6dc9b8f4ef60d9e5ded7f0264db299c91f18832e 420 | Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51 421 | glog: 1f3da668190260b06b429bb211bfbee5cd790c28 422 | OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355 423 | RCTRequired: 0873f5bdb1762d2b9b1ae16a01c4f91d6ee3b6dd 424 | RCTTypeSafety: a605e0cc0e4220f6e65896bd9e675073c2978f35 425 | React: 8abf6bdd2b05538e9445f7bbda800df744068bfe 426 | React-Core: d6daa0d60a4180915e889a5e81f28522cb30359a 427 | React-CoreModules: 9d5343b095a52e830954a1dd7ae1cb9321ceeddc 428 | React-cxxreact: c108ca236585b9c802f1eeab11fed1a023faac3a 429 | React-jsi: bc8166d6833cdcb0848c80710b26ce63fad2c099 430 | React-jsiexecutor: 8bf0b2707f05865113415088c398a7f98c0cf546 431 | React-jsinspector: 8e5913c4c6c54f0d3f9c9fc630c465a89cded65d 432 | react-native-detector: 4d1d3dda0bc24e293511ca557d133cf43a7c81a6 433 | React-RCTActionSheet: 674afbc8b9c76e0a83520e0a51da29a70802c03f 434 | React-RCTAnimation: f5f24330d09ee677fb49e0782f8321868f4df431 435 | React-RCTBlob: b773ce6138ab0d172ebd8a455fd4efd200a92549 436 | React-RCTImage: 8dbaa77916f9d21ff8faa0f3f5f06d4069c28e93 437 | React-RCTLinking: 312a2b3511e2829e68c300c2cdcae4282fefc7ef 438 | React-RCTNetwork: 4b87acf29c38b8819bea67dad3edeca7b9a20718 439 | React-RCTSettings: be798c8b33392a90d9d551644610ffa349a89255 440 | React-RCTText: 91a0d0ae5434aa28fe0c89c03eb9d660ff53bd9b 441 | React-RCTVibration: 0630aeb11e22f87c180ca9c0c3a0a0aba780cc62 442 | ReactCommon: d22162ab8f1358c53dfcd0f9c4d82d38facdbc48 443 | Yoga: 9db9ff2025ad21d1ac0a8b3c85d5ac4e7c29d525 444 | YogaKit: f782866e155069a2cca2517aafea43200b01fd5a 445 | 446 | PODFILE CHECKSUM: 2f3ad1b0fd46d5876756ba863362b12e432e77ce 447 | 448 | COCOAPODS: 1.9.0 449 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/blacklist'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-detector-example", 3 | "description": "Example app for react-native-detector", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "android": "react-native run-android", 8 | "ios": "react-native run-ios", 9 | "start": "react-native start" 10 | }, 11 | "dependencies": { 12 | "react": "17.0.2", 13 | "react-native": "0.67.3" 14 | }, 15 | "devDependencies": { 16 | "@babel/core": "^7.9.6", 17 | "@babel/runtime": "^7.9.6", 18 | "babel-plugin-module-resolver": "^4.0.0", 19 | "metro-react-native-babel-preset": "^0.59.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { 3 | StyleSheet, 4 | View, 5 | Text, 6 | PermissionsAndroid, 7 | Platform, 8 | } from 'react-native'; 9 | import { addScreenshotListener } from 'react-native-detector'; 10 | 11 | export default function App() { 12 | const [screenshotCounter, setScreenshotCounter] = React.useState(0); 13 | 14 | React.useEffect(() => { 15 | const requestPermission = async () => { 16 | try { 17 | const granted = await PermissionsAndroid.request( 18 | PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, 19 | { 20 | title: 'Get Read External Storage Access', 21 | message: 22 | 'get read external storage access for detecting screenshots', 23 | buttonNeutral: 'Ask Me Later', 24 | buttonNegative: 'Cancel', 25 | buttonPositive: 'OK', 26 | } 27 | ); 28 | if (granted === PermissionsAndroid.RESULTS.GRANTED) { 29 | console.log('You can use the READ_EXTERNAL_STORAGE'); 30 | } else { 31 | console.log('READ_EXTERNAL_STORAGE permission denied'); 32 | } 33 | } catch (err) { 34 | console.warn(err); 35 | } 36 | }; 37 | if (Platform.OS === 'android') { 38 | requestPermission(); 39 | } 40 | const userDidScreenshot = () => { 41 | setScreenshotCounter((screenshotCounter) => screenshotCounter + 1); 42 | }; 43 | const unsubscribe = addScreenshotListener(userDidScreenshot); 44 | return () => { 45 | unsubscribe(); 46 | }; 47 | }, []); 48 | 49 | return ( 50 | 51 | User took {screenshotCounter} screenshot 52 | 53 | ); 54 | } 55 | 56 | const styles = StyleSheet.create({ 57 | container: { 58 | flex: 1, 59 | alignItems: 'center', 60 | justifyContent: 'center', 61 | }, 62 | }); 63 | -------------------------------------------------------------------------------- /ios/Detector.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface Detector : RCTEventEmitter 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /ios/Detector.m: -------------------------------------------------------------------------------- 1 | #import "Detector.h" 2 | 3 | @implementation Detector 4 | 5 | RCT_EXPORT_MODULE(); 6 | 7 | - (NSArray *)supportedEvents { 8 | return @[@"UIApplicationUserDidTakeScreenshotNotification"]; 9 | } 10 | 11 | - (void)startObserving { 12 | NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; 13 | [center addObserver:self 14 | selector:@selector(sendNotificationToRN:) 15 | name:UIApplicationUserDidTakeScreenshotNotification 16 | object:nil]; 17 | 18 | } 19 | 20 | - (void)stopObserving { 21 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 22 | } 23 | 24 | - (void)sendNotificationToRN:(NSNotification *)notification { 25 | [self sendEventWithName:notification.name 26 | body:nil]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /ios/Detector.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E555C0D2413F4C50049A1A2 /* Detector.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* Detector.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 134814201AA4EA6300B7C361 /* libDetector.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libDetector.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | B3E7B5881CC2AC0600A0062D /* Detector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Detector.h; sourceTree = ""; }; 28 | B3E7B5891CC2AC0600A0062D /* Detector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Detector.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 134814211AA4EA7D00B7C361 /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 134814201AA4EA6300B7C361 /* libDetector.a */, 46 | ); 47 | name = Products; 48 | sourceTree = ""; 49 | }; 50 | 58B511D21A9E6C8500147676 = { 51 | isa = PBXGroup; 52 | children = ( 53 | B3E7B5881CC2AC0600A0062D /* Detector.h */, 54 | B3E7B5891CC2AC0600A0062D /* Detector.m */, 55 | 134814211AA4EA7D00B7C361 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXNativeTarget section */ 62 | 58B511DA1A9E6C8500147676 /* Detector */ = { 63 | isa = PBXNativeTarget; 64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Detector" */; 65 | buildPhases = ( 66 | 58B511D71A9E6C8500147676 /* Sources */, 67 | 58B511D81A9E6C8500147676 /* Frameworks */, 68 | 58B511D91A9E6C8500147676 /* CopyFiles */, 69 | ); 70 | buildRules = ( 71 | ); 72 | dependencies = ( 73 | ); 74 | name = Detector; 75 | productName = RCTDataManager; 76 | productReference = 134814201AA4EA6300B7C361 /* libDetector.a */; 77 | productType = "com.apple.product-type.library.static"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | 58B511D31A9E6C8500147676 /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | LastUpgradeCheck = 0920; 86 | ORGANIZATIONNAME = Facebook; 87 | TargetAttributes = { 88 | 58B511DA1A9E6C8500147676 = { 89 | CreatedOnToolsVersion = 6.1.1; 90 | }; 91 | }; 92 | }; 93 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Detector" */; 94 | compatibilityVersion = "Xcode 3.2"; 95 | developmentRegion = English; 96 | hasScannedForEncodings = 0; 97 | knownRegions = ( 98 | English, 99 | en, 100 | ); 101 | mainGroup = 58B511D21A9E6C8500147676; 102 | productRefGroup = 58B511D21A9E6C8500147676; 103 | projectDirPath = ""; 104 | projectRoot = ""; 105 | targets = ( 106 | 58B511DA1A9E6C8500147676 /* Detector */, 107 | ); 108 | }; 109 | /* End PBXProject section */ 110 | 111 | /* Begin PBXSourcesBuildPhase section */ 112 | 58B511D71A9E6C8500147676 /* Sources */ = { 113 | isa = PBXSourcesBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | 5E555C0D2413F4C50049A1A2 /* Detector.m in Sources */, 117 | ); 118 | runOnlyForDeploymentPostprocessing = 0; 119 | }; 120 | /* End PBXSourcesBuildPhase section */ 121 | 122 | /* Begin XCBuildConfiguration section */ 123 | 58B511ED1A9E6C8500147676 /* Debug */ = { 124 | isa = XCBuildConfiguration; 125 | buildSettings = { 126 | ALWAYS_SEARCH_USER_PATHS = NO; 127 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 128 | CLANG_CXX_LIBRARY = "libc++"; 129 | CLANG_ENABLE_MODULES = YES; 130 | CLANG_ENABLE_OBJC_ARC = YES; 131 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 132 | CLANG_WARN_BOOL_CONVERSION = YES; 133 | CLANG_WARN_COMMA = YES; 134 | CLANG_WARN_CONSTANT_CONVERSION = YES; 135 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 136 | CLANG_WARN_EMPTY_BODY = YES; 137 | CLANG_WARN_ENUM_CONVERSION = YES; 138 | CLANG_WARN_INFINITE_RECURSION = YES; 139 | CLANG_WARN_INT_CONVERSION = YES; 140 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 141 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 142 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 143 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 144 | CLANG_WARN_STRICT_PROTOTYPES = YES; 145 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 146 | CLANG_WARN_UNREACHABLE_CODE = YES; 147 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 148 | COPY_PHASE_STRIP = NO; 149 | ENABLE_STRICT_OBJC_MSGSEND = YES; 150 | ENABLE_TESTABILITY = YES; 151 | GCC_C_LANGUAGE_STANDARD = gnu99; 152 | GCC_DYNAMIC_NO_PIC = NO; 153 | GCC_NO_COMMON_BLOCKS = YES; 154 | GCC_OPTIMIZATION_LEVEL = 0; 155 | GCC_PREPROCESSOR_DEFINITIONS = ( 156 | "DEBUG=1", 157 | "$(inherited)", 158 | ); 159 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 160 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 161 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 162 | GCC_WARN_UNDECLARED_SELECTOR = YES; 163 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 164 | GCC_WARN_UNUSED_FUNCTION = YES; 165 | GCC_WARN_UNUSED_VARIABLE = YES; 166 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 167 | MTL_ENABLE_DEBUG_INFO = YES; 168 | ONLY_ACTIVE_ARCH = YES; 169 | SDKROOT = iphoneos; 170 | }; 171 | name = Debug; 172 | }; 173 | 58B511EE1A9E6C8500147676 /* Release */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 178 | CLANG_CXX_LIBRARY = "libc++"; 179 | CLANG_ENABLE_MODULES = YES; 180 | CLANG_ENABLE_OBJC_ARC = YES; 181 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 182 | CLANG_WARN_BOOL_CONVERSION = YES; 183 | CLANG_WARN_COMMA = YES; 184 | CLANG_WARN_CONSTANT_CONVERSION = YES; 185 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 186 | CLANG_WARN_EMPTY_BODY = YES; 187 | CLANG_WARN_ENUM_CONVERSION = YES; 188 | CLANG_WARN_INFINITE_RECURSION = YES; 189 | CLANG_WARN_INT_CONVERSION = YES; 190 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 191 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 194 | CLANG_WARN_STRICT_PROTOTYPES = YES; 195 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 196 | CLANG_WARN_UNREACHABLE_CODE = YES; 197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 198 | COPY_PHASE_STRIP = YES; 199 | ENABLE_NS_ASSERTIONS = NO; 200 | ENABLE_STRICT_OBJC_MSGSEND = YES; 201 | GCC_C_LANGUAGE_STANDARD = gnu99; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 204 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 205 | GCC_WARN_UNDECLARED_SELECTOR = YES; 206 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 207 | GCC_WARN_UNUSED_FUNCTION = YES; 208 | GCC_WARN_UNUSED_VARIABLE = YES; 209 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 210 | MTL_ENABLE_DEBUG_INFO = NO; 211 | SDKROOT = iphoneos; 212 | VALIDATE_PRODUCT = YES; 213 | }; 214 | name = Release; 215 | }; 216 | 58B511F01A9E6C8500147676 /* Debug */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | HEADER_SEARCH_PATHS = ( 220 | "$(inherited)", 221 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 222 | "$(SRCROOT)/../../../React/**", 223 | "$(SRCROOT)/../../react-native/React/**", 224 | ); 225 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 226 | OTHER_LDFLAGS = "-ObjC"; 227 | PRODUCT_NAME = Detector; 228 | SKIP_INSTALL = YES; 229 | }; 230 | name = Debug; 231 | }; 232 | 58B511F11A9E6C8500147676 /* Release */ = { 233 | isa = XCBuildConfiguration; 234 | buildSettings = { 235 | HEADER_SEARCH_PATHS = ( 236 | "$(inherited)", 237 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 238 | "$(SRCROOT)/../../../React/**", 239 | "$(SRCROOT)/../../react-native/React/**", 240 | ); 241 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 242 | OTHER_LDFLAGS = "-ObjC"; 243 | PRODUCT_NAME = Detector; 244 | SKIP_INSTALL = YES; 245 | }; 246 | name = Release; 247 | }; 248 | /* End XCBuildConfiguration section */ 249 | 250 | /* Begin XCConfigurationList section */ 251 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Detector" */ = { 252 | isa = XCConfigurationList; 253 | buildConfigurations = ( 254 | 58B511ED1A9E6C8500147676 /* Debug */, 255 | 58B511EE1A9E6C8500147676 /* Release */, 256 | ); 257 | defaultConfigurationIsVisible = 0; 258 | defaultConfigurationName = Release; 259 | }; 260 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Detector" */ = { 261 | isa = XCConfigurationList; 262 | buildConfigurations = ( 263 | 58B511F01A9E6C8500147676 /* Debug */, 264 | 58B511F11A9E6C8500147676 /* Release */, 265 | ); 266 | defaultConfigurationIsVisible = 0; 267 | defaultConfigurationName = Release; 268 | }; 269 | /* End XCConfigurationList section */ 270 | }; 271 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 272 | } 273 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-detector", 3 | "version": "0.2.3", 4 | "description": "a screenshot detector for react native", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/src/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "react-native-detector.podspec", 17 | "!lib/typescript/example", 18 | "!**/__tests__" 19 | ], 20 | "scripts": { 21 | "test": "jest", 22 | "typescript": "tsc --noEmit", 23 | "lint": "eslint --ext .js,.ts,.tsx .", 24 | "prepare": "bob build", 25 | "release": "release-it", 26 | "example": "yarn --cwd example", 27 | "pods": "cd example && pod-install --quiet", 28 | "bootstrap": "yarn example && yarn && yarn pods" 29 | }, 30 | "keywords": [ 31 | "react-native", 32 | "ios", 33 | "android", 34 | "screenshot", 35 | "detector" 36 | ], 37 | "repository": "https://github.com/AzizAK/react-native-detector", 38 | "author": "Abdulaziz Alkharashi (https://github.com/AzizAK)", 39 | "license": "MIT", 40 | "bugs": { 41 | "url": "https://github.com/AzizAK/react-native-detector/issues" 42 | }, 43 | "homepage": "https://github.com/AzizAK/react-native-detector#readme", 44 | "devDependencies": { 45 | "@commitlint/config-conventional": "^8.3.4", 46 | "@react-native-community/bob": "^0.14.5", 47 | "@react-native-community/eslint-config": "^1.1.0", 48 | "@release-it/conventional-changelog": "^1.1.4", 49 | "@types/jest": "^25.2.1", 50 | "@types/react": "^16.9.19", 51 | "@types/react-native": "0.62.7", 52 | "commitlint": "^8.3.5", 53 | "eslint": "^6.8.0", 54 | "eslint-config-prettier": "^6.11.0", 55 | "eslint-plugin-prettier": "^3.1.3", 56 | "husky": "^4.2.5", 57 | "jest": "^26.0.1", 58 | "pod-install": "^0.1.0", 59 | "prettier": "^2.0.5", 60 | "react": "~16.9.0", 61 | "react-native": "~0.61.5", 62 | "release-it": "^13.5.8", 63 | "typescript": "^3.8.3" 64 | }, 65 | "peerDependencies": { 66 | "react": "*", 67 | "react-native": "*" 68 | }, 69 | "jest": { 70 | "preset": "react-native", 71 | "modulePathIgnorePatterns": [ 72 | "/example/node_modules", 73 | "/lib/" 74 | ] 75 | }, 76 | "husky": { 77 | "hooks": { 78 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 79 | "pre-commit": "yarn lint && yarn typescript" 80 | } 81 | }, 82 | "eslintConfig": { 83 | "extends": [ 84 | "@react-native-community", 85 | "prettier" 86 | ], 87 | "rules": { 88 | "prettier/prettier": [ 89 | "error", 90 | { 91 | "quoteProps": "consistent", 92 | "singleQuote": true, 93 | "tabWidth": 2, 94 | "trailingComma": "es5", 95 | "useTabs": false 96 | } 97 | ] 98 | } 99 | }, 100 | "eslintIgnore": [ 101 | "node_modules/", 102 | "lib/" 103 | ], 104 | "prettier": { 105 | "quoteProps": "consistent", 106 | "singleQuote": true, 107 | "tabWidth": 2, 108 | "trailingComma": "es5", 109 | "useTabs": false 110 | }, 111 | "release-it": { 112 | "git": { 113 | "commitMessage": "chore: release ${version}", 114 | "tagName": "v${version}" 115 | }, 116 | "npm": { 117 | "publish": true 118 | }, 119 | "github": { 120 | "release": true 121 | }, 122 | "plugins": { 123 | "@release-it/conventional-changelog": { 124 | "preset": "angular" 125 | } 126 | } 127 | }, 128 | "@react-native-community/bob": { 129 | "source": "src", 130 | "output": "lib", 131 | "targets": [ 132 | "commonjs", 133 | "module", 134 | "typescript" 135 | ] 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /react-native-detector.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "react-native-detector" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.homepage = package["homepage"] 10 | s.license = package["license"] 11 | s.authors = package["author"] 12 | 13 | s.platforms = { :ios => "9.0" } 14 | s.source = { :git => "https://github.com/AzizAK/react-native-detector.git", :tag => "#{s.version}" } 15 | 16 | 17 | s.source_files = "ios/**/*.{h,m,mm}" 18 | 19 | 20 | s.dependency "React" 21 | end 22 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; 2 | 3 | describe('addScreenshotListener', () => { 4 | const createIsolatedTest = ( 5 | type: 'ios' | 'android', 6 | isolatedTest: (options: { 7 | addScreenshotListener: (listener: () => void) => () => void; 8 | emitScreenshot: () => void; 9 | }) => void 10 | ) => () => { 11 | jest.isolateModules(() => { 12 | NativeModules.Detector = { 13 | addListener: jest.fn(), 14 | removeListeners: jest.fn(), 15 | startScreenshotDetection: jest.fn(), 16 | stopScreenshotDetection: jest.fn(), 17 | }; 18 | 19 | const emitter = new NativeEventEmitter(NativeModules.Detector); 20 | 21 | Platform.select = (spec: any) => spec[type]; 22 | 23 | const { addScreenshotListener } = require('../index'); 24 | 25 | const emitScreenshot = () => { 26 | emitter.emit('UIApplicationUserDidTakeScreenshotNotification'); 27 | }; 28 | 29 | isolatedTest({ addScreenshotListener, emitScreenshot }); 30 | }); 31 | }; 32 | 33 | describe('iOS', () => { 34 | it( 35 | 'should invoke each passed listener', 36 | createIsolatedTest('ios', ({ emitScreenshot, addScreenshotListener }) => { 37 | const listener1 = jest.fn(); 38 | const listener2 = jest.fn(); 39 | 40 | addScreenshotListener(listener1); 41 | addScreenshotListener(listener2); 42 | 43 | emitScreenshot(); 44 | 45 | expect(listener1).toHaveBeenCalledTimes(1); 46 | expect(listener2).toHaveBeenCalledTimes(1); 47 | }) 48 | ); 49 | 50 | it( 51 | 'should not invoke passed listener when unsubscribe', 52 | createIsolatedTest('ios', ({ emitScreenshot, addScreenshotListener }) => { 53 | const listener = jest.fn(); 54 | 55 | const unsubscribe = addScreenshotListener(listener); 56 | 57 | emitScreenshot(); 58 | 59 | expect(listener).toHaveBeenCalledTimes(1); 60 | 61 | unsubscribe(); 62 | 63 | emitScreenshot(); 64 | 65 | expect(listener).toHaveBeenCalledTimes(1); 66 | }) 67 | ); 68 | }); 69 | 70 | describe('Android', () => { 71 | it( 72 | 'should invoke each passed listener', 73 | createIsolatedTest( 74 | 'android', 75 | ({ emitScreenshot, addScreenshotListener }) => { 76 | const listener1 = jest.fn(); 77 | const listener2 = jest.fn(); 78 | 79 | addScreenshotListener(listener1); 80 | addScreenshotListener(listener2); 81 | 82 | emitScreenshot(); 83 | 84 | expect(listener1).toHaveBeenCalledTimes(1); 85 | expect(listener2).toHaveBeenCalledTimes(1); 86 | } 87 | ) 88 | ); 89 | 90 | it( 91 | 'should not invoke passed listener when unsubscribe', 92 | createIsolatedTest( 93 | 'android', 94 | ({ emitScreenshot, addScreenshotListener }) => { 95 | const listener = jest.fn(); 96 | 97 | const unsubscribe = addScreenshotListener(listener); 98 | 99 | emitScreenshot(); 100 | 101 | expect(listener).toHaveBeenCalledTimes(1); 102 | 103 | unsubscribe(); 104 | 105 | emitScreenshot(); 106 | 107 | expect(listener).toHaveBeenCalledTimes(1); 108 | } 109 | ) 110 | ); 111 | 112 | it( 113 | 'should invoke startScreenshotDetection once when add listeners', 114 | createIsolatedTest('android', ({ addScreenshotListener }) => { 115 | const { startScreenshotDetection } = NativeModules.Detector; 116 | 117 | addScreenshotListener(jest.fn()); 118 | addScreenshotListener(jest.fn()); 119 | addScreenshotListener(jest.fn()); 120 | 121 | expect(startScreenshotDetection).toHaveBeenCalledTimes(1); 122 | }) 123 | ); 124 | 125 | it( 126 | 'should invoke stopScreenshotDetection when no JS listeners', 127 | createIsolatedTest('android', ({ addScreenshotListener }) => { 128 | const { stopScreenshotDetection } = NativeModules.Detector; 129 | 130 | const unsubscribe1 = addScreenshotListener(jest.fn()); 131 | const unsubscribe2 = addScreenshotListener(jest.fn()); 132 | const unsubscribe3 = addScreenshotListener(jest.fn()); 133 | 134 | unsubscribe1(); 135 | 136 | expect(stopScreenshotDetection).toHaveBeenCalledTimes(0); 137 | 138 | unsubscribe2(); 139 | 140 | expect(stopScreenshotDetection).toHaveBeenCalledTimes(0); 141 | 142 | unsubscribe3(); 143 | 144 | expect(stopScreenshotDetection).toHaveBeenCalledTimes(1); 145 | }) 146 | ); 147 | 148 | it( 149 | 'should restore screenshot detection when resubscribe', 150 | createIsolatedTest('android', ({ addScreenshotListener }) => { 151 | const { startScreenshotDetection } = NativeModules.Detector; 152 | 153 | const unsubscribe = addScreenshotListener(jest.fn()); 154 | 155 | unsubscribe(); 156 | 157 | expect(startScreenshotDetection).toHaveBeenCalledTimes(1); 158 | 159 | addScreenshotListener(jest.fn()); 160 | 161 | expect(startScreenshotDetection).toHaveBeenCalledTimes(2); 162 | }) 163 | ); 164 | }); 165 | }); 166 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import { NativeModules, NativeEventEmitter, Platform } from 'react-native'; 2 | 3 | const { Detector } = NativeModules; 4 | 5 | enum EventsName { 6 | UserDidTakeScreenshot = 'UIApplicationUserDidTakeScreenshotNotification', 7 | } 8 | 9 | const detectorEventEmitter = new NativeEventEmitter(Detector); 10 | 11 | type Unsubscribe = () => void; 12 | 13 | const commonAddScreenshotListener = (listener: () => void): Unsubscribe => { 14 | const eventSubscription = detectorEventEmitter.addListener( 15 | EventsName.UserDidTakeScreenshot, 16 | () => listener(), 17 | {} 18 | ); 19 | 20 | return () => { 21 | eventSubscription.remove(); 22 | }; 23 | }; 24 | 25 | const getListenersCount = (): number => { 26 | return ( 27 | // React Native 0.64+ 28 | // @ts-ignore 29 | detectorEventEmitter.listenerCount?.(EventsName.UserDidTakeScreenshot) ?? 30 | // React Native < 0.64 31 | // @ts-ignore 32 | detectorEventEmitter.listeners?.(EventsName.UserDidTakeScreenshot).length ?? 33 | 0 34 | ); 35 | }; 36 | 37 | export const addScreenshotListener = Platform.select< 38 | (listener: () => void) => Unsubscribe 39 | >({ 40 | default: (): Unsubscribe => () => {}, 41 | ios: commonAddScreenshotListener, 42 | android: (listener: () => void): Unsubscribe => { 43 | if (getListenersCount() === 0) { 44 | Detector.startScreenshotDetection(); 45 | } 46 | 47 | const unsubscribe: Unsubscribe = commonAddScreenshotListener(listener); 48 | 49 | return () => { 50 | unsubscribe(); 51 | 52 | if (getListenersCount() === 0) { 53 | Detector.stopScreenshotDetection(); 54 | } 55 | }; 56 | }, 57 | }); 58 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "react-native-detector": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react", 12 | "lib": ["esnext"], 13 | "module": "esnext", 14 | "moduleResolution": "node", 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitReturns": true, 17 | "noImplicitUseStrict": false, 18 | "noStrictGenericChecks": false, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "resolveJsonModule": true, 22 | "skipLibCheck": true, 23 | "strict": true, 24 | "target": "esnext" 25 | } 26 | } 27 | --------------------------------------------------------------------------------