@azzapp/react-native-snapshot-view 0.2.0 → 0.3.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.
- package/android/src/main/java/com/azzapp/rnsnapshotview/ReactNativeSnapshotViewModule.kt +46 -0
- package/ios/RNSnapshotView.mm +45 -0
- package/lib/module/NativeRNSnapshotView.js.map +1 -1
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeRNSnapshotView.d.ts +2 -0
- package/lib/typescript/src/NativeRNSnapshotView.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +13 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeRNSnapshotView.ts +2 -0
- package/src/index.tsx +19 -0
|
@@ -68,6 +68,52 @@ class ReactNativeSnapshotViewModule internal constructor(context: ReactApplicati
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
@ReactMethod
|
|
72
|
+
override fun snapshotScreen(promise: Promise) {
|
|
73
|
+
val activity = reactApplicationContext.currentActivity
|
|
74
|
+
if (activity == null) {
|
|
75
|
+
promise.reject("not_found", "Activity not found")
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
val window = activity.window
|
|
79
|
+
if (window == null) {
|
|
80
|
+
promise.reject("not_found", "Window not found")
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
val decorView = window.decorView
|
|
84
|
+
val bitmap = Bitmap.createBitmap(decorView.width, decorView.height, Bitmap.Config.ARGB_8888)
|
|
85
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
86
|
+
PixelCopy.request(window, bitmap, { result ->
|
|
87
|
+
if (result == PixelCopy.SUCCESS) {
|
|
88
|
+
val uuid = UUID.randomUUID().toString()
|
|
89
|
+
snapshotMap[uuid] = bitmap
|
|
90
|
+
promise.resolve(uuid)
|
|
91
|
+
} else {
|
|
92
|
+
bitmap.recycle()
|
|
93
|
+
promise.reject("snapshot_failed", "PixelCopy failed with result $result")
|
|
94
|
+
}
|
|
95
|
+
}, Handler(Looper.getMainLooper()))
|
|
96
|
+
} else {
|
|
97
|
+
decorView.draw(Canvas(bitmap))
|
|
98
|
+
val uuid = UUID.randomUUID().toString()
|
|
99
|
+
snapshotMap[uuid] = bitmap
|
|
100
|
+
promise.resolve(uuid)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@ReactMethod
|
|
105
|
+
override fun duplicateSnapshot(snapshotID: String, promise: Promise) {
|
|
106
|
+
val original = snapshotMap[snapshotID]
|
|
107
|
+
if (original == null) {
|
|
108
|
+
promise.reject("not_found", "Snapshot not found")
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
val copy = original.copy(original.config ?: Bitmap.Config.ARGB_8888, false)
|
|
112
|
+
val uuid = UUID.randomUUID().toString()
|
|
113
|
+
snapshotMap[uuid] = copy
|
|
114
|
+
promise.resolve(uuid)
|
|
115
|
+
}
|
|
116
|
+
|
|
71
117
|
@ReactMethod
|
|
72
118
|
override fun releaseSnapshot(snapshotID: String, promise: Promise) {
|
|
73
119
|
snapshotMap.remove(snapshotID)
|
package/ios/RNSnapshotView.mm
CHANGED
|
@@ -42,6 +42,51 @@ static NSMutableDictionary<NSString *, UIView *> *snapshotMap;
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
- (void)snapshotScreen:(RCTPromiseResolveBlock)resolve
|
|
46
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
47
|
+
{
|
|
48
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
49
|
+
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
|
|
50
|
+
if (window == nil) {
|
|
51
|
+
reject(@"not_found", @"Key window not found", nil);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
UIView *snapshot = [window snapshotViewAfterScreenUpdates:NO];
|
|
56
|
+
if (snapshot == nil) {
|
|
57
|
+
reject(@"snapshot_failed", @"Failed to capture screen snapshot", nil);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
NSString *identifier = [[NSUUID UUID] UUIDString];
|
|
62
|
+
[[RNSnapshotView getSnapShotMap] setObject:snapshot forKey:identifier];
|
|
63
|
+
resolve(identifier);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)duplicateSnapshot:(NSString *)snapshotID
|
|
68
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
69
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
70
|
+
{
|
|
71
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
72
|
+
UIView *original = [[RNSnapshotView getSnapShotMap] objectForKey:snapshotID];
|
|
73
|
+
if (original == nil) {
|
|
74
|
+
reject(@"not_found", @"Snapshot not found", nil);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
UIView *duplicate = [original snapshotViewAfterScreenUpdates:NO];
|
|
79
|
+
if (duplicate == nil) {
|
|
80
|
+
reject(@"snapshot_failed", @"Failed to duplicate snapshot", nil);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
NSString *identifier = [[NSUUID UUID] UUIDString];
|
|
85
|
+
[[RNSnapshotView getSnapShotMap] setObject:duplicate forKey:identifier];
|
|
86
|
+
resolve(identifier);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
45
90
|
- (void)releaseSnapshot:(NSString *)uuid
|
|
46
91
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
47
92
|
reject:(RCTPromiseRejectBlock)reject
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNSnapshotView.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNSnapshotView.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AASlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,gBAAgB,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -17,6 +17,25 @@ export function captureSnapshot(componentOrHandle) {
|
|
|
17
17
|
return RNSnapshotView.captureSnapshot(handle);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Captures a snapshot of the entire screen.
|
|
22
|
+
*
|
|
23
|
+
* @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
|
|
24
|
+
*/
|
|
25
|
+
export function snapshotScreen() {
|
|
26
|
+
return RNSnapshotView.snapshotScreen();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Duplicates a snapshot. The duplicate is independent and must be released separately.
|
|
31
|
+
*
|
|
32
|
+
* @param snapshotID The ID of the snapshot to duplicate.
|
|
33
|
+
* @returns A promise that resolves to the ID of the duplicated snapshot.
|
|
34
|
+
*/
|
|
35
|
+
export function duplicateSnapshot(snapshotID) {
|
|
36
|
+
return RNSnapshotView.duplicateSnapshot(snapshotID);
|
|
37
|
+
}
|
|
38
|
+
|
|
20
39
|
/**
|
|
21
40
|
* Releases a snapshot.
|
|
22
41
|
*
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["findNodeHandle","RNSnapshotView","captureSnapshot","componentOrHandle","handle","Promise","reject","Error","
|
|
1
|
+
{"version":3,"names":["findNodeHandle","RNSnapshotView","captureSnapshot","componentOrHandle","handle","Promise","reject","Error","snapshotScreen","duplicateSnapshot","snapshotID","releaseSnapshot","default","SnapshotRenderer"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,QAAQ,cAAc;AAC7C,OAAOC,cAAc,MAAM,2BAAwB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,iBAI6B,EACZ;EACjB,MAAMC,MAAM,GAAGJ,cAAc,CAACG,iBAAiB,CAAC;EAChD,IAAIC,MAAM,IAAI,IAAI,EAAE;IAClB,OAAOC,OAAO,CAACC,MAAM,CAAC,IAAIC,KAAK,CAAC,qBAAqB,CAAC,CAAC;EACzD;EACA,OAAON,cAAc,CAACC,eAAe,CAACE,MAAM,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,cAAcA,CAAA,EAAoB;EAChD,OAAOP,cAAc,CAACO,cAAc,CAAC,CAAC;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAACC,UAAkB,EAAmB;EACrE,OAAOT,cAAc,CAACQ,iBAAiB,CAACC,UAAU,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACD,UAAkB,EAAiB;EACjE,OAAOT,cAAc,CAACU,eAAe,CAACD,UAAU,CAAC;AACnD;AAEA,SAASE,OAAO,IAAIC,gBAAgB,QAAQ,uBAAoB","ignoreList":[]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { TurboModule } from 'react-native';
|
|
2
2
|
export interface Spec extends TurboModule {
|
|
3
3
|
captureSnapshot(target: number): Promise<string>;
|
|
4
|
+
snapshotScreen(): Promise<string>;
|
|
5
|
+
duplicateSnapshot(snapshotID: string): Promise<string>;
|
|
4
6
|
releaseSnapshot(a: string): Promise<void>;
|
|
5
7
|
}
|
|
6
8
|
declare const _default: Spec;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeRNSnapshotView.d.ts","sourceRoot":"","sources":["../../../src/NativeRNSnapshotView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;;AAED,wBAAwE"}
|
|
1
|
+
{"version":3,"file":"NativeRNSnapshotView.d.ts","sourceRoot":"","sources":["../../../src/NativeRNSnapshotView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvD,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;;AAED,wBAAwE"}
|
|
@@ -5,6 +5,19 @@
|
|
|
5
5
|
* @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
|
|
6
6
|
*/
|
|
7
7
|
export declare function captureSnapshot(componentOrHandle: null | number | React.Component<any, any> | React.ComponentClass<any>): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Captures a snapshot of the entire screen.
|
|
10
|
+
*
|
|
11
|
+
* @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function snapshotScreen(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Duplicates a snapshot. The duplicate is independent and must be released separately.
|
|
16
|
+
*
|
|
17
|
+
* @param snapshotID The ID of the snapshot to duplicate.
|
|
18
|
+
* @returns A promise that resolves to the ID of the duplicated snapshot.
|
|
19
|
+
*/
|
|
20
|
+
export declare function duplicateSnapshot(snapshotID: string): Promise<string>;
|
|
8
21
|
/**
|
|
9
22
|
* Releases a snapshot.
|
|
10
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,iBAAiB,EACb,IAAI,GACJ,MAAM,GACN,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,GACzB,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,CAMjB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE;AAED,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,iBAAiB,EACb,IAAI,GACJ,MAAM,GACN,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,GACzB,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,CAMjB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE;AAED,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,6 +3,8 @@ import { TurboModuleRegistry } from 'react-native';
|
|
|
3
3
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
5
|
captureSnapshot(target: number): Promise<string>;
|
|
6
|
+
snapshotScreen(): Promise<string>;
|
|
7
|
+
duplicateSnapshot(snapshotID: string): Promise<string>;
|
|
6
8
|
releaseSnapshot(a: string): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
|
package/src/index.tsx
CHANGED
|
@@ -21,6 +21,25 @@ export function captureSnapshot(
|
|
|
21
21
|
return RNSnapshotView.captureSnapshot(handle);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Captures a snapshot of the entire screen.
|
|
26
|
+
*
|
|
27
|
+
* @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
|
|
28
|
+
*/
|
|
29
|
+
export function snapshotScreen(): Promise<string> {
|
|
30
|
+
return RNSnapshotView.snapshotScreen();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Duplicates a snapshot. The duplicate is independent and must be released separately.
|
|
35
|
+
*
|
|
36
|
+
* @param snapshotID The ID of the snapshot to duplicate.
|
|
37
|
+
* @returns A promise that resolves to the ID of the duplicated snapshot.
|
|
38
|
+
*/
|
|
39
|
+
export function duplicateSnapshot(snapshotID: string): Promise<string> {
|
|
40
|
+
return RNSnapshotView.duplicateSnapshot(snapshotID);
|
|
41
|
+
}
|
|
42
|
+
|
|
24
43
|
/**
|
|
25
44
|
* Releases a snapshot.
|
|
26
45
|
*
|