@exodus/react-native-screenshot-detector 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/Example/.babelrc +3 -0
  2. package/Example/.buckconfig +6 -0
  3. package/Example/.flowconfig +46 -0
  4. package/Example/.gitattributes +1 -0
  5. package/Example/.watchmanconfig +1 -0
  6. package/Example/__tests__/index.android.js +12 -0
  7. package/Example/__tests__/index.ios.js +12 -0
  8. package/Example/android/app/BUCK +66 -0
  9. package/Example/android/app/build.gradle +140 -0
  10. package/Example/android/app/proguard-rules.pro +66 -0
  11. package/Example/android/app/src/main/AndroidManifest.xml +32 -0
  12. package/Example/android/app/src/main/java/com/example/MainActivity.java +15 -0
  13. package/Example/android/app/src/main/java/com/example/MainApplication.java +46 -0
  14. package/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  15. package/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  16. package/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  17. package/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  18. package/Example/android/app/src/main/res/values/strings.xml +3 -0
  19. package/Example/android/app/src/main/res/values/styles.xml +8 -0
  20. package/Example/android/build.gradle +24 -0
  21. package/Example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  22. package/Example/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  23. package/Example/android/gradle.properties +20 -0
  24. package/Example/android/gradlew +164 -0
  25. package/Example/android/gradlew.bat +90 -0
  26. package/Example/android/keystores/BUCK +8 -0
  27. package/Example/android/keystores/debug.keystore.properties +4 -0
  28. package/Example/android/settings.gradle +3 -0
  29. package/Example/app.json +4 -0
  30. package/Example/index.android.js +53 -0
  31. package/Example/index.ios.js +61 -0
  32. package/Example/ios/Example/AppDelegate.h +16 -0
  33. package/Example/ios/Example/AppDelegate.m +47 -0
  34. package/Example/ios/Example/Base.lproj/LaunchScreen.xib +42 -0
  35. package/Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json +38 -0
  36. package/Example/ios/Example/Info.plist +57 -0
  37. package/Example/ios/Example/main.m +18 -0
  38. package/Example/ios/Example-tvOS/Info.plist +54 -0
  39. package/Example/ios/Example-tvOSTests/Info.plist +24 -0
  40. package/Example/ios/Example.xcodeproj/project.pbxproj +1328 -0
  41. package/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example-tvOS.xcscheme +129 -0
  42. package/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +129 -0
  43. package/Example/ios/ExampleTests/ExampleTests.m +70 -0
  44. package/Example/ios/ExampleTests/Info.plist +24 -0
  45. package/Example/package.json +23 -0
  46. package/LICENSE +21 -0
  47. package/README.md +32 -0
  48. package/android/build.gradle +36 -0
  49. package/android/src/main/AndroidManifest.xml +6 -0
  50. package/android/src/main/java/com/reactlibrary/RNScreenshotDetectorModule.java +49 -0
  51. package/android/src/main/java/com/reactlibrary/RNScreenshotDetectorPackage.java +28 -0
  52. package/index.android.js +13 -0
  53. package/index.d.ts +6 -0
  54. package/index.ios.js +15 -0
  55. package/ios/RNScreenshotDetector/RNScreenshotDetector.h +14 -0
  56. package/ios/RNScreenshotDetector/RNScreenshotDetector.m +45 -0
  57. package/ios/RNScreenshotDetector.xcodeproj/project.pbxproj +271 -0
  58. package/package.json +17 -0
@@ -0,0 +1,129 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "0820"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "NO"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "2D2A28121D9B038B00D4039D"
18
+ BuildableName = "libReact.a"
19
+ BlueprintName = "React-tvOS"
20
+ ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ <BuildActionEntry
24
+ buildForTesting = "YES"
25
+ buildForRunning = "YES"
26
+ buildForProfiling = "YES"
27
+ buildForArchiving = "YES"
28
+ buildForAnalyzing = "YES">
29
+ <BuildableReference
30
+ BuildableIdentifier = "primary"
31
+ BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
32
+ BuildableName = "Example-tvOS.app"
33
+ BlueprintName = "Example-tvOS"
34
+ ReferencedContainer = "container:Example.xcodeproj">
35
+ </BuildableReference>
36
+ </BuildActionEntry>
37
+ <BuildActionEntry
38
+ buildForTesting = "YES"
39
+ buildForRunning = "YES"
40
+ buildForProfiling = "NO"
41
+ buildForArchiving = "NO"
42
+ buildForAnalyzing = "YES">
43
+ <BuildableReference
44
+ BuildableIdentifier = "primary"
45
+ BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
46
+ BuildableName = "Example-tvOSTests.xctest"
47
+ BlueprintName = "Example-tvOSTests"
48
+ ReferencedContainer = "container:Example.xcodeproj">
49
+ </BuildableReference>
50
+ </BuildActionEntry>
51
+ </BuildActionEntries>
52
+ </BuildAction>
53
+ <TestAction
54
+ buildConfiguration = "Debug"
55
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
56
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
57
+ shouldUseLaunchSchemeArgsEnv = "YES">
58
+ <Testables>
59
+ <TestableReference
60
+ skipped = "NO">
61
+ <BuildableReference
62
+ BuildableIdentifier = "primary"
63
+ BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
64
+ BuildableName = "Example-tvOSTests.xctest"
65
+ BlueprintName = "Example-tvOSTests"
66
+ ReferencedContainer = "container:Example.xcodeproj">
67
+ </BuildableReference>
68
+ </TestableReference>
69
+ </Testables>
70
+ <MacroExpansion>
71
+ <BuildableReference
72
+ BuildableIdentifier = "primary"
73
+ BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
74
+ BuildableName = "Example-tvOS.app"
75
+ BlueprintName = "Example-tvOS"
76
+ ReferencedContainer = "container:Example.xcodeproj">
77
+ </BuildableReference>
78
+ </MacroExpansion>
79
+ <AdditionalOptions>
80
+ </AdditionalOptions>
81
+ </TestAction>
82
+ <LaunchAction
83
+ buildConfiguration = "Debug"
84
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
85
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
86
+ launchStyle = "0"
87
+ useCustomWorkingDirectory = "NO"
88
+ ignoresPersistentStateOnLaunch = "NO"
89
+ debugDocumentVersioning = "YES"
90
+ debugServiceExtension = "internal"
91
+ allowLocationSimulation = "YES">
92
+ <BuildableProductRunnable
93
+ runnableDebuggingMode = "0">
94
+ <BuildableReference
95
+ BuildableIdentifier = "primary"
96
+ BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
97
+ BuildableName = "Example-tvOS.app"
98
+ BlueprintName = "Example-tvOS"
99
+ ReferencedContainer = "container:Example.xcodeproj">
100
+ </BuildableReference>
101
+ </BuildableProductRunnable>
102
+ <AdditionalOptions>
103
+ </AdditionalOptions>
104
+ </LaunchAction>
105
+ <ProfileAction
106
+ buildConfiguration = "Release"
107
+ shouldUseLaunchSchemeArgsEnv = "YES"
108
+ savedToolIdentifier = ""
109
+ useCustomWorkingDirectory = "NO"
110
+ debugDocumentVersioning = "YES">
111
+ <BuildableProductRunnable
112
+ runnableDebuggingMode = "0">
113
+ <BuildableReference
114
+ BuildableIdentifier = "primary"
115
+ BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
116
+ BuildableName = "Example-tvOS.app"
117
+ BlueprintName = "Example-tvOS"
118
+ ReferencedContainer = "container:Example.xcodeproj">
119
+ </BuildableReference>
120
+ </BuildableProductRunnable>
121
+ </ProfileAction>
122
+ <AnalyzeAction
123
+ buildConfiguration = "Debug">
124
+ </AnalyzeAction>
125
+ <ArchiveAction
126
+ buildConfiguration = "Release"
127
+ revealArchiveInOrganizer = "YES">
128
+ </ArchiveAction>
129
+ </Scheme>
@@ -0,0 +1,129 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "0620"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "NO"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "83CBBA2D1A601D0E00E9B192"
18
+ BuildableName = "libReact.a"
19
+ BlueprintName = "React"
20
+ ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ <BuildActionEntry
24
+ buildForTesting = "YES"
25
+ buildForRunning = "YES"
26
+ buildForProfiling = "YES"
27
+ buildForArchiving = "YES"
28
+ buildForAnalyzing = "YES">
29
+ <BuildableReference
30
+ BuildableIdentifier = "primary"
31
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
32
+ BuildableName = "Example.app"
33
+ BlueprintName = "Example"
34
+ ReferencedContainer = "container:Example.xcodeproj">
35
+ </BuildableReference>
36
+ </BuildActionEntry>
37
+ <BuildActionEntry
38
+ buildForTesting = "YES"
39
+ buildForRunning = "YES"
40
+ buildForProfiling = "NO"
41
+ buildForArchiving = "NO"
42
+ buildForAnalyzing = "YES">
43
+ <BuildableReference
44
+ BuildableIdentifier = "primary"
45
+ BlueprintIdentifier = "00E356ED1AD99517003FC87E"
46
+ BuildableName = "ExampleTests.xctest"
47
+ BlueprintName = "ExampleTests"
48
+ ReferencedContainer = "container:Example.xcodeproj">
49
+ </BuildableReference>
50
+ </BuildActionEntry>
51
+ </BuildActionEntries>
52
+ </BuildAction>
53
+ <TestAction
54
+ buildConfiguration = "Debug"
55
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
56
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
57
+ shouldUseLaunchSchemeArgsEnv = "YES">
58
+ <Testables>
59
+ <TestableReference
60
+ skipped = "NO">
61
+ <BuildableReference
62
+ BuildableIdentifier = "primary"
63
+ BlueprintIdentifier = "00E356ED1AD99517003FC87E"
64
+ BuildableName = "ExampleTests.xctest"
65
+ BlueprintName = "ExampleTests"
66
+ ReferencedContainer = "container:Example.xcodeproj">
67
+ </BuildableReference>
68
+ </TestableReference>
69
+ </Testables>
70
+ <MacroExpansion>
71
+ <BuildableReference
72
+ BuildableIdentifier = "primary"
73
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
74
+ BuildableName = "Example.app"
75
+ BlueprintName = "Example"
76
+ ReferencedContainer = "container:Example.xcodeproj">
77
+ </BuildableReference>
78
+ </MacroExpansion>
79
+ <AdditionalOptions>
80
+ </AdditionalOptions>
81
+ </TestAction>
82
+ <LaunchAction
83
+ buildConfiguration = "Debug"
84
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
85
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
86
+ launchStyle = "0"
87
+ useCustomWorkingDirectory = "NO"
88
+ ignoresPersistentStateOnLaunch = "NO"
89
+ debugDocumentVersioning = "YES"
90
+ debugServiceExtension = "internal"
91
+ allowLocationSimulation = "YES">
92
+ <BuildableProductRunnable
93
+ runnableDebuggingMode = "0">
94
+ <BuildableReference
95
+ BuildableIdentifier = "primary"
96
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
97
+ BuildableName = "Example.app"
98
+ BlueprintName = "Example"
99
+ ReferencedContainer = "container:Example.xcodeproj">
100
+ </BuildableReference>
101
+ </BuildableProductRunnable>
102
+ <AdditionalOptions>
103
+ </AdditionalOptions>
104
+ </LaunchAction>
105
+ <ProfileAction
106
+ buildConfiguration = "Release"
107
+ shouldUseLaunchSchemeArgsEnv = "YES"
108
+ savedToolIdentifier = ""
109
+ useCustomWorkingDirectory = "NO"
110
+ debugDocumentVersioning = "YES">
111
+ <BuildableProductRunnable
112
+ runnableDebuggingMode = "0">
113
+ <BuildableReference
114
+ BuildableIdentifier = "primary"
115
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
116
+ BuildableName = "Example.app"
117
+ BlueprintName = "Example"
118
+ ReferencedContainer = "container:Example.xcodeproj">
119
+ </BuildableReference>
120
+ </BuildableProductRunnable>
121
+ </ProfileAction>
122
+ <AnalyzeAction
123
+ buildConfiguration = "Debug">
124
+ </AnalyzeAction>
125
+ <ArchiveAction
126
+ buildConfiguration = "Release"
127
+ revealArchiveInOrganizer = "YES">
128
+ </ArchiveAction>
129
+ </Scheme>
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ #import <UIKit/UIKit.h>
11
+ #import <XCTest/XCTest.h>
12
+
13
+ #import <React/RCTLog.h>
14
+ #import <React/RCTRootView.h>
15
+
16
+ #define TIMEOUT_SECONDS 600
17
+ #define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
18
+
19
+ @interface ExampleTests : XCTestCase
20
+
21
+ @end
22
+
23
+ @implementation ExampleTests
24
+
25
+ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
26
+ {
27
+ if (test(view)) {
28
+ return YES;
29
+ }
30
+ for (UIView *subview in [view subviews]) {
31
+ if ([self findSubviewInView:subview matching:test]) {
32
+ return YES;
33
+ }
34
+ }
35
+ return NO;
36
+ }
37
+
38
+ - (void)testRendersWelcomeScreen
39
+ {
40
+ UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
41
+ NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
42
+ BOOL foundElement = NO;
43
+
44
+ __block NSString *redboxError = nil;
45
+ RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
46
+ if (level >= RCTLogLevelError) {
47
+ redboxError = message;
48
+ }
49
+ });
50
+
51
+ while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
52
+ [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
53
+ [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
54
+
55
+ foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
56
+ if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
57
+ return YES;
58
+ }
59
+ return NO;
60
+ }];
61
+ }
62
+
63
+ RCTSetLogFunction(RCTDefaultLogFunction);
64
+
65
+ XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
66
+ XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
67
+ }
68
+
69
+
70
+ @end
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>BNDL</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleSignature</key>
20
+ <string>????</string>
21
+ <key>CFBundleVersion</key>
22
+ <string>1</string>
23
+ </dict>
24
+ </plist>
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "Example",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "scripts": {
6
+ "start": "node node_modules/react-native/local-cli/cli.js start",
7
+ "test": "jest"
8
+ },
9
+ "dependencies": {
10
+ "react": "15.4.2",
11
+ "react-native": "0.42.3",
12
+ "react-native-screenshot-detector": "git+ssh://github.com/blendlabs/react-native-screenshot-detector"
13
+ },
14
+ "devDependencies": {
15
+ "babel-jest": "19.0.0",
16
+ "babel-preset-react-native": "1.9.1",
17
+ "jest": "19.0.2",
18
+ "react-test-renderer": "15.4.2"
19
+ },
20
+ "jest": {
21
+ "preset": "react-native"
22
+ }
23
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Blend
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.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+
2
+ # @exodus/react-native-screenshot-detector
3
+
4
+ *NOTE: forked and adapted from https://github.com/blend/react-native-screenshot-detector*
5
+
6
+ The goal is to prevent the user from taking screenshots in your app.
7
+
8
+ - Android: possible via the [FLAG_SECURE flag](https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SECURE)
9
+ - iOS: impossible, but you *can* detect them
10
+
11
+ Accordingly, this library exports different APIs for Android and iOS. See [Usage](#usage) below.
12
+
13
+ ## Getting started
14
+
15
+ `$ npm install @exodus/react-native-screenshot-detector --save`
16
+
17
+ `$ react-native link @exodus/react-native-screenshot-detector`
18
+
19
+ ## Usage
20
+
21
+ ```javascript
22
+ import ScreenshotDetector from '@exodus/react-native-screenshot-detector';
23
+
24
+ // iOS
25
+ ScreenshotDetector.subscribe(() => {
26
+ // yell at the user. We'll leave the choice of obscenities to you
27
+ })
28
+
29
+ // Android
30
+ ScreenshotDetector.disableScreenshots()
31
+ ScreenshotDetector.enableScreenshots()
32
+ ```
@@ -0,0 +1,36 @@
1
+
2
+ buildscript {
3
+ repositories {
4
+ jcenter()
5
+ }
6
+
7
+ dependencies {
8
+ classpath 'com.android.tools.build:gradle:1.3.1'
9
+ }
10
+ }
11
+
12
+ apply plugin: 'com.android.library'
13
+
14
+ android {
15
+ compileSdkVersion 23
16
+ buildToolsVersion "23.0.1"
17
+
18
+ defaultConfig {
19
+ minSdkVersion 16
20
+ targetSdkVersion 22
21
+ versionCode 1
22
+ versionName "1.0"
23
+ }
24
+ lintOptions {
25
+ abortOnError false
26
+ }
27
+ }
28
+
29
+ repositories {
30
+ mavenCentral()
31
+ }
32
+
33
+ dependencies {
34
+ compile 'com.facebook.react:react-native:+'
35
+ }
36
+
@@ -0,0 +1,6 @@
1
+
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ package="com.reactlibrary">
4
+
5
+ </manifest>
6
+
@@ -0,0 +1,49 @@
1
+
2
+ package com.reactlibrary;
3
+
4
+ import android.view.Window;
5
+ import android.view.WindowManager;
6
+
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
9
+ import com.facebook.react.bridge.ReactMethod;
10
+ import com.facebook.react.bridge.Callback;
11
+
12
+ public class RNScreenshotDetectorModule extends ReactContextBaseJavaModule {
13
+
14
+ private final ReactApplicationContext reactContext;
15
+
16
+ public RNScreenshotDetectorModule(ReactApplicationContext reactContext) {
17
+ super(reactContext);
18
+ this.reactContext = reactContext;
19
+ }
20
+
21
+ @Override
22
+ public String getName() {
23
+ return "RNScreenshotDetector";
24
+ }
25
+
26
+ @ReactMethod
27
+ public void disableScreenshots() {
28
+ getCurrentActivity().runOnUiThread(new Runnable() {
29
+ @Override
30
+ public void run() {
31
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
32
+ }
33
+ });
34
+ }
35
+
36
+ @ReactMethod
37
+ public void enableScreenshots() {
38
+ getCurrentActivity().runOnUiThread(new Runnable() {
39
+ @Override
40
+ public void run() {
41
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
42
+ }
43
+ });
44
+ }
45
+
46
+ private Window getWindow() {
47
+ return getCurrentActivity().getWindow();
48
+ }
49
+ }
@@ -0,0 +1,28 @@
1
+
2
+ package com.reactlibrary;
3
+
4
+ import java.util.Arrays;
5
+ import java.util.Collections;
6
+ import java.util.List;
7
+
8
+ import com.facebook.react.ReactPackage;
9
+ import com.facebook.react.bridge.NativeModule;
10
+ import com.facebook.react.bridge.ReactApplicationContext;
11
+ import com.facebook.react.uimanager.ViewManager;
12
+ import com.facebook.react.bridge.JavaScriptModule;
13
+ public class RNScreenshotDetectorPackage implements ReactPackage {
14
+ @Override
15
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
16
+ return Arrays.<NativeModule>asList(new RNScreenshotDetectorModule(reactContext));
17
+ }
18
+
19
+ // Deprecated from RN 0.47
20
+ public List<Class<? extends JavaScriptModule>> createJSModules() {
21
+ return Collections.emptyList();
22
+ }
23
+
24
+ @Override
25
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
26
+ return Collections.emptyList();
27
+ }
28
+ }
@@ -0,0 +1,13 @@
1
+ // TODO: check out https://github.com/abangfadli/shotwatch
2
+
3
+ import { NativeModules } from 'react-native'
4
+
5
+ const unsubscribe = () => {}
6
+ const subscribe = () => unsubscribe
7
+
8
+ const Detector = {
9
+ ...NativeModules.RNScreenshotDetector,
10
+ subscribe,
11
+ }
12
+
13
+ export default Detector
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ declare module "react-native-screenshot-detector" {
2
+ import { NativeEventEmitter } from 'react-native';
3
+
4
+ export function subscribe(cb: Function): NativeEventEmitter;
5
+ export function unsubscribe(eventEmitter: NativeEventEmitter): void;
6
+ }
package/index.ios.js ADDED
@@ -0,0 +1,15 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native'
2
+
3
+ const { RNScreenshotDetector } = NativeModules
4
+ const eventEmitter = new NativeEventEmitter(RNScreenshotDetector)
5
+
6
+ const SCREENSHOT_EVENT = 'ScreenshotTaken'
7
+
8
+ const subscribe = (cb) => {
9
+ const sub = eventEmitter.addListener(SCREENSHOT_EVENT, cb, {})
10
+ return () => sub.remove()
11
+ }
12
+
13
+ export default {
14
+ subscribe,
15
+ }
@@ -0,0 +1,14 @@
1
+ //
2
+ // RNScreenshotDetector.h
3
+ //
4
+ // Created by Graham Carling on 1/11/17.
5
+ //
6
+
7
+ #import <React/RCTEventEmitter.h>
8
+ #import <React/RCTBridgeModule.h>
9
+
10
+ @interface RNScreenshotDetector : RCTEventEmitter <RCTBridgeModule>
11
+
12
+ - (void)screenshotDetected:(NSNotification*)notification;
13
+
14
+ @end
@@ -0,0 +1,45 @@
1
+ //
2
+ // RNScreenshotDetector.m
3
+ //
4
+ // Created by Graham Carling on 1/11/17.
5
+ //
6
+
7
+ #import "RNScreenshotDetector.h"
8
+ #import <React/RCTBridge.h>
9
+
10
+ @implementation RNScreenshotDetector
11
+ {
12
+ id observer;
13
+ }
14
+
15
+ RCT_EXPORT_MODULE();
16
+
17
+
18
+ - (NSArray<NSString *> *)supportedEvents {
19
+ return @[@"ScreenshotTaken"];
20
+ }
21
+
22
+ - (void)startObserving {
23
+ // Now set up handler to detect if user takes a screenshot
24
+ NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
25
+ observer = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
26
+ object:nil
27
+ queue:mainQueue
28
+ usingBlock:^(NSNotification *notification) {
29
+ [self screenshotDetected:notification];
30
+ }];
31
+ }
32
+
33
+ - (void)stopObserving {
34
+ if (observer != nil) {
35
+ [[NSNotificationCenter defaultCenter] removeObserver:observer];
36
+ }
37
+ }
38
+
39
+ - (void)screenshotDetected:(NSNotification *)notification {
40
+ if (observer != nil) {
41
+ [self sendEventWithName:@"ScreenshotTaken" body:@{}];
42
+ }
43
+ }
44
+
45
+ @end