react-native-screenshot-aware 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/android/src/main/java/com/screenshotaware/ScreenshotAwareModule.kt +1 -1
- package/ios/ScreenshotAwareImpl.mm +3 -3
- package/lib/commonjs/index.js +62 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +63 -3
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +52 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/index.tsx +61 -3
package/README.md
CHANGED
|
@@ -37,6 +37,14 @@ npm install react-native-screenshot-aware
|
|
|
37
37
|
- Leverages the new `DETECT_SCREEN_CAPTURE` permission introduced in Android 14
|
|
38
38
|
- Provides a more privacy-friendly and performant approach to screenshot detection
|
|
39
39
|
|
|
40
|
+
### Permissions
|
|
41
|
+
|
|
42
|
+
To use the screenshot detection feature on Android, you need to add the following permission to your `AndroidManifest.xml` file:
|
|
43
|
+
|
|
44
|
+
```xml
|
|
45
|
+
<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />
|
|
46
|
+
```
|
|
47
|
+
|
|
40
48
|
> **Note**: Callbacks will never be triggered on devices running Android versions below 14. This is due to the reliance on the new `DETECT_SCREEN_CAPTURE` permission and APIs introduced in Android 14, which are not available in earlier versions.
|
|
41
49
|
|
|
42
50
|
> **Note**: The decision to support only Android 14+ is based on the introduction of new, dedicated screenshot detection APIs. These APIs offer improved performance and respect user privacy better than previous methods. For more details, see the [Android 14 screenshot detection documentation](https://developer.android.com/about/versions/14/features/screenshot-detection).
|
|
@@ -84,6 +92,20 @@ useEffect(() => {
|
|
|
84
92
|
}, [])
|
|
85
93
|
```
|
|
86
94
|
|
|
95
|
+
### `removeAllListeners()`
|
|
96
|
+
|
|
97
|
+
This function allows you to remove all listeners for the screenshot event.
|
|
98
|
+
|
|
99
|
+
#### Example
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
import ScreenshotAware from 'react-native-screenshot-aware';
|
|
103
|
+
|
|
104
|
+
function removeScreenshotListeners() {
|
|
105
|
+
ScreenshotAware.removeAllListeners();
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
87
109
|
## Contributing
|
|
88
110
|
|
|
89
111
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more details.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#import "ScreenshotAwareImpl.h"
|
|
2
2
|
#import <React/RCTUtils.h>
|
|
3
3
|
|
|
4
|
-
static NSString *const
|
|
4
|
+
static NSString *const kRNScreenshotAwareEventName = @"ScreenshotAwareEvent";
|
|
5
5
|
|
|
6
6
|
@implementation ScreenshotAwareImpl
|
|
7
7
|
|
|
8
8
|
+ (NSArray<NSString *> *)supportedEvents
|
|
9
9
|
{
|
|
10
|
-
return @[
|
|
10
|
+
return @[kRNScreenshotAwareEventName];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
- (instancetype)init
|
|
@@ -29,7 +29,7 @@ static NSString *const kRNScreenshotEventName = @"ScreenshotEvent";
|
|
|
29
29
|
|
|
30
30
|
- (void)screenshotDetected:(NSNotification *)notification
|
|
31
31
|
{
|
|
32
|
-
[self.delegate handleEventWithName:
|
|
32
|
+
[self.delegate handleEventWithName:kRNScreenshotAwareEventName];
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
@end
|
package/lib/commonjs/index.js
CHANGED
|
@@ -8,18 +8,77 @@ var _react = require("react");
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _NativeScreenshotAware = _interopRequireDefault(require("./codegenSpec/NativeScreenshotAware"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
/**
|
|
12
|
+
* @fileoverview This module provides functionality to detect screenshot events in a React Native application.
|
|
13
|
+
* It exports a hook for functional components and methods for class components to listen for screenshot events.
|
|
14
|
+
*/
|
|
15
|
+
|
|
11
16
|
const moduleEventEmitter = new _reactNative.NativeEventEmitter(_NativeScreenshotAware.default);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A React hook that listens for screenshot events and triggers a callback when a screenshot is taken.
|
|
20
|
+
*
|
|
21
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```jsx
|
|
25
|
+
* import { useScreenshotAware } from 'react-native-screenshot-aware';
|
|
26
|
+
*
|
|
27
|
+
* function MyComponent() {
|
|
28
|
+
* useScreenshotAware(() => {
|
|
29
|
+
* console.log('A screenshot was taken!');
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* return <View>...</View>;
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
12
36
|
const useScreenshotAware = callback => {
|
|
13
37
|
(0, _react.useEffect)(() => {
|
|
14
|
-
const subscription = moduleEventEmitter.addListener("
|
|
38
|
+
const subscription = moduleEventEmitter.addListener("ScreenshotAwareEvent", callback);
|
|
15
39
|
return () => subscription.remove();
|
|
16
40
|
}, [callback]);
|
|
17
41
|
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Module object for managing screenshot event listeners.
|
|
45
|
+
* Useful for class components or non-React contexts.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```jsx
|
|
49
|
+
* import ScreenshotAware from 'react-native-screenshot-aware';
|
|
50
|
+
*
|
|
51
|
+
* class MyComponent extends React.Component {
|
|
52
|
+
* componentDidMount() {
|
|
53
|
+
* this.subscription = ScreenshotAware.addListener(() => {
|
|
54
|
+
* console.log('A screenshot was taken!');
|
|
55
|
+
* });
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* componentWillUnmount() {
|
|
59
|
+
* this.subscription.remove();
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* render() {
|
|
63
|
+
* return <View>...</View>;
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
18
68
|
exports.useScreenshotAware = useScreenshotAware;
|
|
19
69
|
var _default = exports.default = {
|
|
70
|
+
/**
|
|
71
|
+
* Adds a listener for screenshot events.
|
|
72
|
+
*
|
|
73
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
74
|
+
* @returns {import('react-native').EmitterSubscription} A subscription object that can be used to remove the listener.
|
|
75
|
+
*/
|
|
20
76
|
addListener: callback => {
|
|
21
|
-
return moduleEventEmitter.addListener("
|
|
77
|
+
return moduleEventEmitter.addListener("ScreenshotAwareEvent", callback);
|
|
22
78
|
},
|
|
23
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Removes all listeners for screenshot events.
|
|
81
|
+
*/
|
|
82
|
+
removeAllListeners: () => moduleEventEmitter.removeAllListeners("ScreenshotAwareEvent")
|
|
24
83
|
};
|
|
25
84
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_NativeScreenshotAware","_interopRequireDefault","e","__esModule","default","moduleEventEmitter","NativeEventEmitter","NativeScreenshotAware","useScreenshotAware","callback","useEffect","subscription","addListener","remove","exports","_default","removeAllListeners"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAwE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAExE,MAAMG,kBAAkB,GAAG,IAAIC,+BAAkB,CAACC,8BAAqB,CAAC;
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_NativeScreenshotAware","_interopRequireDefault","e","__esModule","default","moduleEventEmitter","NativeEventEmitter","NativeScreenshotAware","useScreenshotAware","callback","useEffect","subscription","addListener","remove","exports","_default","removeAllListeners"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAAwE,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAExE;AACA;AACA;AACA;;AAEA,MAAMG,kBAAkB,GAAG,IAAIC,+BAAkB,CAACC,8BAAqB,CAAC;;AAExE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAIC,QAAoB,IAAK;EAC1D,IAAAC,gBAAS,EAAC,MAAM;IACd,MAAMC,YAAY,GAAGN,kBAAkB,CAACO,WAAW,CACjD,sBAAsB,EACtBH,QACF,CAAC;IACD,OAAO,MAAME,YAAY,CAACE,MAAM,CAAC,CAAC;EACpC,CAAC,EAAE,CAACJ,QAAQ,CAAC,CAAC;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAxBAK,OAAA,CAAAN,kBAAA,GAAAA,kBAAA;AAAA,IAAAO,QAAA,GAAAD,OAAA,CAAAV,OAAA,GAyBe;EACb;AACF;AACA;AACA;AACA;AACA;EACEQ,WAAW,EAAGH,QAAoB,IAAK;IACrC,OAAOJ,kBAAkB,CAACO,WAAW,CAAC,sBAAsB,EAAEH,QAAQ,CAAC;EACzE,CAAC;EAED;AACF;AACA;EACEO,kBAAkB,EAAEA,CAAA,KAClBX,kBAAkB,CAACW,kBAAkB,CAAC,sBAAsB;AAChE,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -3,17 +3,77 @@
|
|
|
3
3
|
import { useEffect } from "react";
|
|
4
4
|
import { NativeEventEmitter } from "react-native";
|
|
5
5
|
import NativeScreenshotAware from "./codegenSpec/NativeScreenshotAware";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview This module provides functionality to detect screenshot events in a React Native application.
|
|
9
|
+
* It exports a hook for functional components and methods for class components to listen for screenshot events.
|
|
10
|
+
*/
|
|
11
|
+
|
|
6
12
|
const moduleEventEmitter = new NativeEventEmitter(NativeScreenshotAware);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A React hook that listens for screenshot events and triggers a callback when a screenshot is taken.
|
|
16
|
+
*
|
|
17
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```jsx
|
|
21
|
+
* import { useScreenshotAware } from 'react-native-screenshot-aware';
|
|
22
|
+
*
|
|
23
|
+
* function MyComponent() {
|
|
24
|
+
* useScreenshotAware(() => {
|
|
25
|
+
* console.log('A screenshot was taken!');
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* return <View>...</View>;
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
7
32
|
export const useScreenshotAware = callback => {
|
|
8
33
|
useEffect(() => {
|
|
9
|
-
const subscription = moduleEventEmitter.addListener("
|
|
34
|
+
const subscription = moduleEventEmitter.addListener("ScreenshotAwareEvent", callback);
|
|
10
35
|
return () => subscription.remove();
|
|
11
36
|
}, [callback]);
|
|
12
37
|
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Module object for managing screenshot event listeners.
|
|
41
|
+
* Useful for class components or non-React contexts.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```jsx
|
|
45
|
+
* import ScreenshotAware from 'react-native-screenshot-aware';
|
|
46
|
+
*
|
|
47
|
+
* class MyComponent extends React.Component {
|
|
48
|
+
* componentDidMount() {
|
|
49
|
+
* this.subscription = ScreenshotAware.addListener(() => {
|
|
50
|
+
* console.log('A screenshot was taken!');
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* componentWillUnmount() {
|
|
55
|
+
* this.subscription.remove();
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* render() {
|
|
59
|
+
* return <View>...</View>;
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
13
64
|
export default {
|
|
65
|
+
/**
|
|
66
|
+
* Adds a listener for screenshot events.
|
|
67
|
+
*
|
|
68
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
69
|
+
* @returns {import('react-native').EmitterSubscription} A subscription object that can be used to remove the listener.
|
|
70
|
+
*/
|
|
14
71
|
addListener: callback => {
|
|
15
|
-
return moduleEventEmitter.addListener("
|
|
72
|
+
return moduleEventEmitter.addListener("ScreenshotAwareEvent", callback);
|
|
16
73
|
},
|
|
17
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Removes all listeners for screenshot events.
|
|
76
|
+
*/
|
|
77
|
+
removeAllListeners: () => moduleEventEmitter.removeAllListeners("ScreenshotAwareEvent")
|
|
18
78
|
};
|
|
19
79
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","NativeEventEmitter","NativeScreenshotAware","moduleEventEmitter","useScreenshotAware","callback","subscription","addListener","remove","removeAllListeners"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,kBAAkB,QAAQ,cAAc;AACjD,OAAOC,qBAAqB,MAAM,qCAAqC;
|
|
1
|
+
{"version":3,"names":["useEffect","NativeEventEmitter","NativeScreenshotAware","moduleEventEmitter","useScreenshotAware","callback","subscription","addListener","remove","removeAllListeners"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,kBAAkB,QAAQ,cAAc;AACjD,OAAOC,qBAAqB,MAAM,qCAAqC;;AAEvE;AACA;AACA;AACA;;AAEA,MAAMC,kBAAkB,GAAG,IAAIF,kBAAkB,CAACC,qBAAqB,CAAC;;AAExE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,kBAAkB,GAAIC,QAAoB,IAAK;EAC1DL,SAAS,CAAC,MAAM;IACd,MAAMM,YAAY,GAAGH,kBAAkB,CAACI,WAAW,CACjD,sBAAsB,EACtBF,QACF,CAAC;IACD,OAAO,MAAMC,YAAY,CAACE,MAAM,CAAC,CAAC;EACpC,CAAC,EAAE,CAACH,QAAQ,CAAC,CAAC;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe;EACb;AACF;AACA;AACA;AACA;AACA;EACEE,WAAW,EAAGF,QAAoB,IAAK;IACrC,OAAOF,kBAAkB,CAACI,WAAW,CAAC,sBAAsB,EAAEF,QAAQ,CAAC;EACzE,CAAC;EAED;AACF;AACA;EACEI,kBAAkB,EAAEA,CAAA,KAClBN,kBAAkB,CAACM,kBAAkB,CAAC,sBAAsB;AAChE,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React hook that listens for screenshot events and triggers a callback when a screenshot is taken.
|
|
3
|
+
*
|
|
4
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```jsx
|
|
8
|
+
* import { useScreenshotAware } from 'react-native-screenshot-aware';
|
|
9
|
+
*
|
|
10
|
+
* function MyComponent() {
|
|
11
|
+
* useScreenshotAware(() => {
|
|
12
|
+
* console.log('A screenshot was taken!');
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* return <View>...</View>;
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
1
19
|
export declare const useScreenshotAware: (callback: () => void) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Module object for managing screenshot event listeners.
|
|
22
|
+
* Useful for class components or non-React contexts.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```jsx
|
|
26
|
+
* import ScreenshotAware from 'react-native-screenshot-aware';
|
|
27
|
+
*
|
|
28
|
+
* class MyComponent extends React.Component {
|
|
29
|
+
* componentDidMount() {
|
|
30
|
+
* this.subscription = ScreenshotAware.addListener(() => {
|
|
31
|
+
* console.log('A screenshot was taken!');
|
|
32
|
+
* });
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* componentWillUnmount() {
|
|
36
|
+
* this.subscription.remove();
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* render() {
|
|
40
|
+
* return <View>...</View>;
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
2
45
|
declare const _default: {
|
|
46
|
+
/**
|
|
47
|
+
* Adds a listener for screenshot events.
|
|
48
|
+
*
|
|
49
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
50
|
+
* @returns {import('react-native').EmitterSubscription} A subscription object that can be used to remove the listener.
|
|
51
|
+
*/
|
|
3
52
|
addListener: (callback: () => void) => import("react-native").EmitterSubscription;
|
|
53
|
+
/**
|
|
54
|
+
* Removes all listeners for screenshot events.
|
|
55
|
+
*/
|
|
4
56
|
removeAllListeners: () => void;
|
|
5
57
|
};
|
|
6
58
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,aAAc,MAAM,IAAI,SAQtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;IAED;;;;;OAKG;4BACqB,MAAM,IAAI;IAIlC;;OAEG;;;AAbL,wBAgBE"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-screenshot-aware",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "React Native module for real-time screenshot detection on Android and iOS",
|
|
5
|
-
"source": "
|
|
6
|
-
"main": "
|
|
7
|
-
"react-native": "src/index.
|
|
8
|
-
"module": "
|
|
5
|
+
"source": "src/index.tsx",
|
|
6
|
+
"main": "lib/commonjs/index.js",
|
|
7
|
+
"react-native": "src/index.tsx",
|
|
8
|
+
"module": "lib/module/index.js",
|
|
9
9
|
"types": "lib/typescript/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"src",
|
package/src/index.tsx
CHANGED
|
@@ -2,22 +2,80 @@ import { useEffect } from "react";
|
|
|
2
2
|
import { NativeEventEmitter } from "react-native";
|
|
3
3
|
import NativeScreenshotAware from "./codegenSpec/NativeScreenshotAware";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview This module provides functionality to detect screenshot events in a React Native application.
|
|
7
|
+
* It exports a hook for functional components and methods for class components to listen for screenshot events.
|
|
8
|
+
*/
|
|
9
|
+
|
|
5
10
|
const moduleEventEmitter = new NativeEventEmitter(NativeScreenshotAware);
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* A React hook that listens for screenshot events and triggers a callback when a screenshot is taken.
|
|
14
|
+
*
|
|
15
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```jsx
|
|
19
|
+
* import { useScreenshotAware } from 'react-native-screenshot-aware';
|
|
20
|
+
*
|
|
21
|
+
* function MyComponent() {
|
|
22
|
+
* useScreenshotAware(() => {
|
|
23
|
+
* console.log('A screenshot was taken!');
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* return <View>...</View>;
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
7
30
|
export const useScreenshotAware = (callback: () => void) => {
|
|
8
31
|
useEffect(() => {
|
|
9
32
|
const subscription = moduleEventEmitter.addListener(
|
|
10
|
-
"
|
|
33
|
+
"ScreenshotAwareEvent",
|
|
11
34
|
callback,
|
|
12
35
|
);
|
|
13
36
|
return () => subscription.remove();
|
|
14
37
|
}, [callback]);
|
|
15
38
|
};
|
|
16
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Module object for managing screenshot event listeners.
|
|
42
|
+
* Useful for class components or non-React contexts.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```jsx
|
|
46
|
+
* import ScreenshotAware from 'react-native-screenshot-aware';
|
|
47
|
+
*
|
|
48
|
+
* class MyComponent extends React.Component {
|
|
49
|
+
* componentDidMount() {
|
|
50
|
+
* this.subscription = ScreenshotAware.addListener(() => {
|
|
51
|
+
* console.log('A screenshot was taken!');
|
|
52
|
+
* });
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* componentWillUnmount() {
|
|
56
|
+
* this.subscription.remove();
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* render() {
|
|
60
|
+
* return <View>...</View>;
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
17
65
|
export default {
|
|
66
|
+
/**
|
|
67
|
+
* Adds a listener for screenshot events.
|
|
68
|
+
*
|
|
69
|
+
* @param {() => void} callback - The function to be called when a screenshot event occurs.
|
|
70
|
+
* @returns {import('react-native').EmitterSubscription} A subscription object that can be used to remove the listener.
|
|
71
|
+
*/
|
|
18
72
|
addListener: (callback: () => void) => {
|
|
19
|
-
return moduleEventEmitter.addListener("
|
|
73
|
+
return moduleEventEmitter.addListener("ScreenshotAwareEvent", callback);
|
|
20
74
|
},
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Removes all listeners for screenshot events.
|
|
78
|
+
*/
|
|
21
79
|
removeAllListeners: () =>
|
|
22
|
-
moduleEventEmitter.removeAllListeners("
|
|
80
|
+
moduleEventEmitter.removeAllListeners("ScreenshotAwareEvent"),
|
|
23
81
|
};
|