@azzapp/react-native-snapshot-view 0.1.1

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 (92) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +39 -0
  3. package/android/build.gradle +126 -0
  4. package/android/generated/java/com/azzapp/rnsnapshotview/NativeRNSnapshotViewSpec.java +42 -0
  5. package/android/generated/java/com/facebook/react/viewmanagers/RNSnapshotRendererManagerDelegate.java +31 -0
  6. package/android/generated/java/com/facebook/react/viewmanagers/RNSnapshotRendererManagerInterface.java +17 -0
  7. package/android/generated/jni/CMakeLists.txt +49 -0
  8. package/android/generated/jni/RNSnapshotViewSpec-generated.cpp +38 -0
  9. package/android/generated/jni/RNSnapshotViewSpec.h +31 -0
  10. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/ComponentDescriptors.cpp +22 -0
  11. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/ComponentDescriptors.h +24 -0
  12. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/EventEmitters.cpp +16 -0
  13. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/EventEmitters.h +23 -0
  14. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/Props.cpp +25 -0
  15. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/Props.h +27 -0
  16. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/RNSnapshotViewSpecJSI-generated.cpp +34 -0
  17. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/RNSnapshotViewSpecJSI.h +76 -0
  18. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/ShadowNodes.cpp +17 -0
  19. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/ShadowNodes.h +32 -0
  20. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/States.cpp +16 -0
  21. package/android/generated/jni/react/renderer/components/RNSnapshotViewSpec/States.h +29 -0
  22. package/android/gradle.properties +5 -0
  23. package/android/src/main/AndroidManifest.xml +3 -0
  24. package/android/src/main/AndroidManifestNew.xml +2 -0
  25. package/android/src/main/java/com/azzapp/rnsnapshotview/RNSnapshotRenderer.kt +27 -0
  26. package/android/src/main/java/com/azzapp/rnsnapshotview/RNSnapshotRendererManager.kt +28 -0
  27. package/android/src/main/java/com/azzapp/rnsnapshotview/ReactNativeSnapshotViewModule.kt +222 -0
  28. package/android/src/main/java/com/azzapp/rnsnapshotview/ReactNativeSnapshotViewPackage.kt +42 -0
  29. package/android/src/newarch/RNSnapshotRendererManagerSpec.kt +21 -0
  30. package/android/src/newarch/RNSnapshotViewSpec.kt +7 -0
  31. package/android/src/oldarch/RNSnapshotRendererManagerSpec.kt +9 -0
  32. package/android/src/oldarch/RNSnapshotViewSpec.kt +12 -0
  33. package/azzapp-react-native-snapshot-view.podspec +42 -0
  34. package/ios/RNSnapshotRenderer.h +17 -0
  35. package/ios/RNSnapshotRenderer.mm +61 -0
  36. package/ios/RNSnapshotRendererManager.mm +62 -0
  37. package/ios/RNSnapshotView.h +15 -0
  38. package/ios/RNSnapshotView.mm +71 -0
  39. package/ios/generated/RNSnapshotViewSpec/ComponentDescriptors.cpp +22 -0
  40. package/ios/generated/RNSnapshotViewSpec/ComponentDescriptors.h +24 -0
  41. package/ios/generated/RNSnapshotViewSpec/EventEmitters.cpp +16 -0
  42. package/ios/generated/RNSnapshotViewSpec/EventEmitters.h +23 -0
  43. package/ios/generated/RNSnapshotViewSpec/Props.cpp +25 -0
  44. package/ios/generated/RNSnapshotViewSpec/Props.h +27 -0
  45. package/ios/generated/RNSnapshotViewSpec/RCTComponentViewHelpers.h +20 -0
  46. package/ios/generated/RNSnapshotViewSpec/RNSnapshotViewSpec-generated.mm +36 -0
  47. package/ios/generated/RNSnapshotViewSpec/RNSnapshotViewSpec.h +54 -0
  48. package/ios/generated/RNSnapshotViewSpec/ShadowNodes.cpp +17 -0
  49. package/ios/generated/RNSnapshotViewSpec/ShadowNodes.h +32 -0
  50. package/ios/generated/RNSnapshotViewSpec/States.cpp +16 -0
  51. package/ios/generated/RNSnapshotViewSpec/States.h +29 -0
  52. package/ios/generated/RNSnapshotViewSpecJSI-generated.cpp +34 -0
  53. package/ios/generated/RNSnapshotViewSpecJSI.h +76 -0
  54. package/lib/commonjs/NativeRNSnapshotView.js +9 -0
  55. package/lib/commonjs/NativeRNSnapshotView.js.map +1 -0
  56. package/lib/commonjs/RNSnapshotRendererNativeComponent.js +10 -0
  57. package/lib/commonjs/RNSnapshotRendererNativeComponent.js.map +1 -0
  58. package/lib/commonjs/SnapshotRenderer.js +36 -0
  59. package/lib/commonjs/SnapshotRenderer.js.map +1 -0
  60. package/lib/commonjs/index.js +54 -0
  61. package/lib/commonjs/index.js.map +1 -0
  62. package/lib/module/NativeRNSnapshotView.js +5 -0
  63. package/lib/module/NativeRNSnapshotView.js.map +1 -0
  64. package/lib/module/RNSnapshotRendererNativeComponent.js +5 -0
  65. package/lib/module/RNSnapshotRendererNativeComponent.js.map +1 -0
  66. package/lib/module/SnapshotRenderer.js +31 -0
  67. package/lib/module/SnapshotRenderer.js.map +1 -0
  68. package/lib/module/index.js +42 -0
  69. package/lib/module/index.js.map +1 -0
  70. package/lib/typescript/commonjs/package.json +1 -0
  71. package/lib/typescript/commonjs/src/NativeRNSnapshotView.d.ts +8 -0
  72. package/lib/typescript/commonjs/src/NativeRNSnapshotView.d.ts.map +1 -0
  73. package/lib/typescript/commonjs/src/RNSnapshotRendererNativeComponent.d.ts +7 -0
  74. package/lib/typescript/commonjs/src/RNSnapshotRendererNativeComponent.d.ts.map +1 -0
  75. package/lib/typescript/commonjs/src/SnapshotRenderer.d.ts +27 -0
  76. package/lib/typescript/commonjs/src/SnapshotRenderer.d.ts.map +1 -0
  77. package/lib/typescript/commonjs/src/index.d.ts +16 -0
  78. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  79. package/lib/typescript/module/package.json +1 -0
  80. package/lib/typescript/module/src/NativeRNSnapshotView.d.ts +8 -0
  81. package/lib/typescript/module/src/NativeRNSnapshotView.d.ts.map +1 -0
  82. package/lib/typescript/module/src/RNSnapshotRendererNativeComponent.d.ts +7 -0
  83. package/lib/typescript/module/src/RNSnapshotRendererNativeComponent.d.ts.map +1 -0
  84. package/lib/typescript/module/src/SnapshotRenderer.d.ts +27 -0
  85. package/lib/typescript/module/src/SnapshotRenderer.d.ts.map +1 -0
  86. package/lib/typescript/module/src/index.d.ts +16 -0
  87. package/lib/typescript/module/src/index.d.ts.map +1 -0
  88. package/package.json +202 -0
  89. package/src/NativeRNSnapshotView.ts +9 -0
  90. package/src/RNSnapshotRendererNativeComponent.ts +8 -0
  91. package/src/SnapshotRenderer.tsx +44 -0
  92. package/src/index.tsx +57 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_SnapshotRenderer","_interopRequireDefault","e","__esModule","default","LINKING_ERROR","Platform","select","ios","isTurboModuleEnabled","global","__turboModuleProxy","RNSnapshotViewModule","NativeModules","RNSnapshotView","Proxy","get","Error","captureSnapshot","componentOrHandle","handle","findNodeHandle","Promise","reject","releaseSnapshot","snapshotID"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAwDA,IAAAC,iBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAiE,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAtDjE,MAAMG,aAAa,GACjB,6FAA6F,GAC7FC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMK,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,oBAAoB,GAAGH,oBAAoB,GAC7CV,OAAO,CAAC,wBAAwB,CAAC,CAACK,OAAO,GACzCS,0BAAa,CAACC,cAAc;AAEhC,MAAMA,cAAc,GAAGF,oBAAoB,GACvCA,oBAAoB,GACpB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACZ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;AACA;AACA;AACA;AACO,SAASa,eAAeA,CAC7BC,iBAI6B,EACZ;EACjB,MAAMC,MAAM,GAAG,IAAAC,2BAAc,EAACF,iBAAiB,CAAC;EAChD,IAAIC,MAAM,IAAI,IAAI,EAAE;IAClB,OAAOE,OAAO,CAACC,MAAM,CAAC,IAAIN,KAAK,CAAC,qBAAqB,CAAC,CAAC;EACzD;EACA,OAAOH,cAAc,CAACI,eAAe,CAACE,MAAM,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,eAAeA,CAACC,UAAkB,EAAiB;EACjE,OAAOX,cAAc,CAACU,eAAe,CAACC,UAAU,CAAC;AACnD","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('RNSnapshotView');
5
+ //# sourceMappingURL=NativeRNSnapshotView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNSnapshotView.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAOlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,gBAAgB,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
4
+ export default codegenNativeComponent('RNSnapshotRenderer');
5
+ //# sourceMappingURL=RNSnapshotRendererNativeComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../src","sources":["RNSnapshotRendererNativeComponent.ts"],"mappings":";;AAAA,OAAOA,sBAAsB,MAAM,yDAAyD;AAO5F,eAAeA,sBAAsB,CAAc,oBAAoB,CAAC","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ import { forwardRef, useEffect, useRef } from 'react';
4
+ import RNSnapshotRenderer from "./RNSnapshotRendererNativeComponent.js";
5
+ import { releaseSnapshot } from "./index.js";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ /**
8
+ * A view that renders a snapshot of a view.
9
+ */
10
+ const SnapshotRenderer = ({
11
+ snapshotID,
12
+ autoReleaseSnapshot = true,
13
+ ...props
14
+ }, forwardedRef) => {
15
+ const autoReleaseSnapshotRef = useRef(autoReleaseSnapshot);
16
+ useEffect(() => {
17
+ autoReleaseSnapshotRef.current = autoReleaseSnapshot;
18
+ }, [autoReleaseSnapshot]);
19
+ useEffect(() => () => {
20
+ if (autoReleaseSnapshotRef.current && snapshotID) {
21
+ releaseSnapshot(snapshotID).catch(() => {});
22
+ }
23
+ }, [snapshotID]);
24
+ return /*#__PURE__*/_jsx(RNSnapshotRenderer, {
25
+ ref: forwardedRef,
26
+ snapshotID: snapshotID,
27
+ ...props
28
+ });
29
+ };
30
+ export default /*#__PURE__*/forwardRef(SnapshotRenderer);
31
+ //# sourceMappingURL=SnapshotRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","useEffect","useRef","RNSnapshotRenderer","releaseSnapshot","jsx","_jsx","SnapshotRenderer","snapshotID","autoReleaseSnapshot","props","forwardedRef","autoReleaseSnapshotRef","current","catch","ref"],"sourceRoot":"../../src","sources":["SnapshotRenderer.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAA2B,OAAO;AAExE,OAAOC,kBAAkB,MAAM,wCAAqC;AACpE,SAASC,eAAe,QAAQ,YAAG;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAepC;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CACvB;EAAEC,UAAU;EAAEC,mBAAmB,GAAG,IAAI;EAAE,GAAGC;AAA6B,CAAC,EAC3EC,YAAgC,KAC7B;EACH,MAAMC,sBAAsB,GAAGV,MAAM,CAACO,mBAAmB,CAAC;EAC1DR,SAAS,CAAC,MAAM;IACdW,sBAAsB,CAACC,OAAO,GAAGJ,mBAAmB;EACtD,CAAC,EAAE,CAACA,mBAAmB,CAAC,CAAC;EAEzBR,SAAS,CACP,MAAM,MAAM;IACV,IAAIW,sBAAsB,CAACC,OAAO,IAAIL,UAAU,EAAE;MAChDJ,eAAe,CAACI,UAAU,CAAC,CAACM,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7C;EACF,CAAC,EACD,CAACN,UAAU,CACb,CAAC;EACD,oBACEF,IAAA,CAACH,kBAAkB;IAACY,GAAG,EAAEJ,YAAa;IAACH,UAAU,EAAEA,UAAW;IAAA,GAAKE;EAAK,CAAG,CAAC;AAEhF,CAAC;AAED,4BAAeV,UAAU,CAACO,gBAAgB,CAAC","ignoreList":[]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ import { findNodeHandle, NativeModules, Platform } from 'react-native';
4
+ const LINKING_ERROR = `The package '@azzapp/react-native-snapshot-view' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
5
+ ios: "- You have run 'pod install'\n",
6
+ default: ''
7
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
8
+
9
+ // @ts-expect-error
10
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
11
+ const RNSnapshotViewModule = isTurboModuleEnabled ? require('./NativeRNSnapshotView').default : NativeModules.RNSnapshotView;
12
+ const RNSnapshotView = RNSnapshotViewModule ? RNSnapshotViewModule : new Proxy({}, {
13
+ get() {
14
+ throw new Error(LINKING_ERROR);
15
+ }
16
+ });
17
+
18
+ /**
19
+ * Captures a snapshot of a view. The snapshot can be rendered using the `SnapshotRenderer` component.
20
+ *
21
+ * @param componentOrHandle The view to capture. Can be a view ref or a native component handle.
22
+ * @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
23
+ */
24
+ export function captureSnapshot(componentOrHandle) {
25
+ const handle = findNodeHandle(componentOrHandle);
26
+ if (handle == null) {
27
+ return Promise.reject(new Error('Invalid node handle'));
28
+ }
29
+ return RNSnapshotView.captureSnapshot(handle);
30
+ }
31
+
32
+ /**
33
+ * Releases a snapshot.
34
+ *
35
+ * @param snapshotID The ID of the snapshot to release.
36
+ * @returns A promise that resolves when the snapshot is released.
37
+ */
38
+ export function releaseSnapshot(snapshotID) {
39
+ return RNSnapshotView.releaseSnapshot(snapshotID);
40
+ }
41
+ export { default as SnapshotRenderer } from "./SnapshotRenderer.js";
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["findNodeHandle","NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","RNSnapshotViewModule","require","RNSnapshotView","Proxy","get","Error","captureSnapshot","componentOrHandle","handle","Promise","reject","releaseSnapshot","snapshotID","SnapshotRenderer"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtE,MAAMC,aAAa,GACjB,6FAA6F,GAC7FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,oBAAoB,GAAGH,oBAAoB,GAC7CI,OAAO,CAAC,wBAAwB,CAAC,CAACL,OAAO,GACzCL,aAAa,CAACW,cAAc;AAEhC,MAAMA,cAAc,GAAGF,oBAAoB,GACvCA,oBAAoB,GACpB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACZ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASa,eAAeA,CAC7BC,iBAI6B,EACZ;EACjB,MAAMC,MAAM,GAAGlB,cAAc,CAACiB,iBAAiB,CAAC;EAChD,IAAIC,MAAM,IAAI,IAAI,EAAE;IAClB,OAAOC,OAAO,CAACC,MAAM,CAAC,IAAIL,KAAK,CAAC,qBAAqB,CAAC,CAAC;EACzD;EACA,OAAOH,cAAc,CAACI,eAAe,CAACE,MAAM,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,eAAeA,CAACC,UAAkB,EAAiB;EACjE,OAAOV,cAAc,CAACS,eAAe,CAACC,UAAU,CAAC;AACnD;AAEA,SAAShB,OAAO,IAAIiB,gBAAgB,QAAQ,uBAAoB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,8 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ captureSnapshot(target: number): Promise<string>;
4
+ releaseSnapshot(a: string): Promise<void>;
5
+ }
6
+ declare const _default: Spec;
7
+ export default _default;
8
+ //# sourceMappingURL=NativeRNSnapshotView.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ import type { ViewProps } from 'react-native';
2
+ interface NativeProps extends ViewProps {
3
+ snapshotID?: string | null;
4
+ }
5
+ declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
6
+ export default _default;
7
+ //# sourceMappingURL=RNSnapshotRendererNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RNSnapshotRendererNativeComponent.d.ts","sourceRoot":"","sources":["../../../../src/RNSnapshotRendererNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,UAAU,WAAY,SAAQ,SAAS;IACrC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;;AAED,wBAAyE"}
@@ -0,0 +1,27 @@
1
+ import type { View, ViewProps } from 'react-native';
2
+ export type SnapshotRendererProps = Omit<ViewProps, 'children'> & {
3
+ /**
4
+ * The ID of the snapshot to render.
5
+ * This ID is returned by the `captureSnapshot` function.
6
+ */
7
+ snapshotID: string | null;
8
+ /**
9
+ * Whether to automatically release the snapshot when no longer displayed.
10
+ * @default true
11
+ */
12
+ autoReleaseSnapshot?: boolean;
13
+ };
14
+ declare const _default: import("react").ForwardRefExoticComponent<Omit<ViewProps, "children"> & {
15
+ /**
16
+ * The ID of the snapshot to render.
17
+ * This ID is returned by the `captureSnapshot` function.
18
+ */
19
+ snapshotID: string | null;
20
+ /**
21
+ * Whether to automatically release the snapshot when no longer displayed.
22
+ * @default true
23
+ */
24
+ autoReleaseSnapshot?: boolean;
25
+ } & import("react").RefAttributes<View>>;
26
+ export default _default;
27
+ //# sourceMappingURL=SnapshotRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnapshotRenderer.d.ts","sourceRoot":"","sources":["../../../../src/SnapshotRenderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpD,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG;IAChE;;;OAGG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;;IAVA;;;OAGG;gBACS,MAAM,GAAG,IAAI;IACzB;;;OAGG;0BACmB,OAAO;;AA4B/B,wBAA4C"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Captures a snapshot of a view. The snapshot can be rendered using the `SnapshotRenderer` component.
3
+ *
4
+ * @param componentOrHandle The view to capture. Can be a view ref or a native component handle.
5
+ * @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
6
+ */
7
+ export declare function captureSnapshot(componentOrHandle: null | number | React.Component<any, any> | React.ComponentClass<any>): Promise<string>;
8
+ /**
9
+ * Releases a snapshot.
10
+ *
11
+ * @param snapshotID The ID of the snapshot to release.
12
+ * @returns A promise that resolves when the snapshot is released.
13
+ */
14
+ export declare function releaseSnapshot(snapshotID: string): Promise<void>;
15
+ export { default as SnapshotRenderer } from './SnapshotRenderer';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AA0BA;;;;;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"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,8 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ captureSnapshot(target: number): Promise<string>;
4
+ releaseSnapshot(a: string): Promise<void>;
5
+ }
6
+ declare const _default: Spec;
7
+ export default _default;
8
+ //# sourceMappingURL=NativeRNSnapshotView.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ import type { ViewProps } from 'react-native';
2
+ interface NativeProps extends ViewProps {
3
+ snapshotID?: string | null;
4
+ }
5
+ declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
6
+ export default _default;
7
+ //# sourceMappingURL=RNSnapshotRendererNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RNSnapshotRendererNativeComponent.d.ts","sourceRoot":"","sources":["../../../../src/RNSnapshotRendererNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,UAAU,WAAY,SAAQ,SAAS;IACrC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;;AAED,wBAAyE"}
@@ -0,0 +1,27 @@
1
+ import type { View, ViewProps } from 'react-native';
2
+ export type SnapshotRendererProps = Omit<ViewProps, 'children'> & {
3
+ /**
4
+ * The ID of the snapshot to render.
5
+ * This ID is returned by the `captureSnapshot` function.
6
+ */
7
+ snapshotID: string | null;
8
+ /**
9
+ * Whether to automatically release the snapshot when no longer displayed.
10
+ * @default true
11
+ */
12
+ autoReleaseSnapshot?: boolean;
13
+ };
14
+ declare const _default: import("react").ForwardRefExoticComponent<Omit<ViewProps, "children"> & {
15
+ /**
16
+ * The ID of the snapshot to render.
17
+ * This ID is returned by the `captureSnapshot` function.
18
+ */
19
+ snapshotID: string | null;
20
+ /**
21
+ * Whether to automatically release the snapshot when no longer displayed.
22
+ * @default true
23
+ */
24
+ autoReleaseSnapshot?: boolean;
25
+ } & import("react").RefAttributes<View>>;
26
+ export default _default;
27
+ //# sourceMappingURL=SnapshotRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnapshotRenderer.d.ts","sourceRoot":"","sources":["../../../../src/SnapshotRenderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpD,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG;IAChE;;;OAGG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;;IAVA;;;OAGG;gBACS,MAAM,GAAG,IAAI;IACzB;;;OAGG;0BACmB,OAAO;;AA4B/B,wBAA4C"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Captures a snapshot of a view. The snapshot can be rendered using the `SnapshotRenderer` component.
3
+ *
4
+ * @param componentOrHandle The view to capture. Can be a view ref or a native component handle.
5
+ * @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
6
+ */
7
+ export declare function captureSnapshot(componentOrHandle: null | number | React.Component<any, any> | React.ComponentClass<any>): Promise<string>;
8
+ /**
9
+ * Releases a snapshot.
10
+ *
11
+ * @param snapshotID The ID of the snapshot to release.
12
+ * @returns A promise that resolves when the snapshot is released.
13
+ */
14
+ export declare function releaseSnapshot(snapshotID: string): Promise<void>;
15
+ export { default as SnapshotRenderer } from './SnapshotRenderer';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AA0BA;;;;;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"}
package/package.json ADDED
@@ -0,0 +1,202 @@
1
+ {
2
+ "name": "@azzapp/react-native-snapshot-view",
3
+ "version": "0.1.1",
4
+ "description": "Snapshot view for react-native",
5
+ "source": "./src/index.tsx",
6
+ "main": "./lib/commonjs/index.js",
7
+ "module": "./lib/module/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./lib/typescript/module/src/index.d.ts",
12
+ "default": "./lib/module/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./lib/typescript/commonjs/src/index.d.ts",
16
+ "default": "./lib/commonjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "src",
22
+ "lib",
23
+ "android",
24
+ "ios",
25
+ "cpp",
26
+ "*.podspec",
27
+ "!ios/build",
28
+ "!android/build",
29
+ "!android/gradle",
30
+ "!android/gradlew",
31
+ "!android/gradlew.bat",
32
+ "!android/local.properties",
33
+ "!**/__tests__",
34
+ "!**/__fixtures__",
35
+ "!**/__mocks__",
36
+ "!**/.*"
37
+ ],
38
+ "scripts": {
39
+ "example": "yarn workspace @azzapp/react-native-snapshot-view-example",
40
+ "test": "jest",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
44
+ "prepare": "bob build",
45
+ "release": "release-it"
46
+ },
47
+ "keywords": [
48
+ "react-native",
49
+ "ios",
50
+ "android"
51
+ ],
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/AzzappApp/react-native-snapshot-view.git"
55
+ },
56
+ "author": "François de Campredon <francois.de.campredon@gmail.com> (https://www.azzapp.com/fdecampredon)",
57
+ "license": "MIT",
58
+ "bugs": {
59
+ "url": "https://github.com/AzzappApp/react-native-snapshot-view/issues"
60
+ },
61
+ "homepage": "https://github.com/AzzappApp/react-native-snapshot-view#readme",
62
+ "publishConfig": {
63
+ "registry": "https://registry.npmjs.org/",
64
+ "access": "public"
65
+ },
66
+ "devDependencies": {
67
+ "@commitlint/config-conventional": "^17.0.2",
68
+ "@evilmartians/lefthook": "^1.5.0",
69
+ "@react-native/eslint-config": "^0.73.1",
70
+ "@release-it/conventional-changelog": "^5.0.0",
71
+ "@types/jest": "^29.5.5",
72
+ "@types/react": "^18.2.44",
73
+ "commitlint": "^17.0.2",
74
+ "del-cli": "^5.1.0",
75
+ "eslint": "^8.51.0",
76
+ "eslint-config-prettier": "^9.0.0",
77
+ "eslint-plugin-prettier": "^5.0.1",
78
+ "jest": "^29.7.0",
79
+ "prettier": "^3.0.3",
80
+ "react": "18.3.1",
81
+ "react-native": "0.75.3",
82
+ "react-native-builder-bob": "^0.30.2",
83
+ "release-it": "^15.0.0",
84
+ "turbo": "^1.10.7",
85
+ "typescript": "^5.2.2"
86
+ },
87
+ "resolutions": {
88
+ "@types/react": "^18.2.44",
89
+ "react-native-builder-bob@^0.30.2": "patch:react-native-builder-bob@npm%3A0.30.2#./.yarn/patches/react-native-builder-bob-npm-0.30.2-5e6e62dece.patch"
90
+ },
91
+ "peerDependencies": {
92
+ "react": "*",
93
+ "react-native": "*"
94
+ },
95
+ "workspaces": [
96
+ "example"
97
+ ],
98
+ "packageManager": "yarn@3.6.1",
99
+ "jest": {
100
+ "preset": "react-native",
101
+ "modulePathIgnorePatterns": [
102
+ "<rootDir>/example/node_modules",
103
+ "<rootDir>/lib/"
104
+ ]
105
+ },
106
+ "commitlint": {
107
+ "extends": [
108
+ "@commitlint/config-conventional"
109
+ ]
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
+ "eslintConfig": {
129
+ "root": true,
130
+ "extends": [
131
+ "@react-native",
132
+ "prettier"
133
+ ],
134
+ "rules": {
135
+ "react/react-in-jsx-scope": "off",
136
+ "prettier/prettier": [
137
+ "error",
138
+ {
139
+ "quoteProps": "consistent",
140
+ "singleQuote": true,
141
+ "tabWidth": 2,
142
+ "trailingComma": "es5",
143
+ "useTabs": false
144
+ }
145
+ ]
146
+ }
147
+ },
148
+ "eslintIgnore": [
149
+ "node_modules/",
150
+ "lib/"
151
+ ],
152
+ "prettier": {
153
+ "quoteProps": "consistent",
154
+ "singleQuote": true,
155
+ "tabWidth": 2,
156
+ "trailingComma": "es5",
157
+ "useTabs": false
158
+ },
159
+ "react-native-builder-bob": {
160
+ "source": "src",
161
+ "output": "lib",
162
+ "targets": [
163
+ "codegen",
164
+ [
165
+ "commonjs",
166
+ {
167
+ "esm": true
168
+ }
169
+ ],
170
+ [
171
+ "module",
172
+ {
173
+ "esm": true
174
+ }
175
+ ],
176
+ [
177
+ "typescript",
178
+ {
179
+ "project": "tsconfig.build.json",
180
+ "esm": true
181
+ }
182
+ ]
183
+ ]
184
+ },
185
+ "codegenConfig": {
186
+ "name": "RNSnapshotViewSpec",
187
+ "type": "all",
188
+ "jsSrcsDir": "src",
189
+ "outputDir": {
190
+ "ios": "ios/generated",
191
+ "android": "android/generated"
192
+ },
193
+ "android": {
194
+ "javaPackageName": "com.azzapp.rnsnapshotview"
195
+ },
196
+ "includesGeneratedCode": true
197
+ },
198
+ "create-react-native-library": {
199
+ "type": "view-mixed",
200
+ "version": "0.41.2"
201
+ }
202
+ }
@@ -0,0 +1,9 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ captureSnapshot(target: number): Promise<string>;
6
+ releaseSnapshot(a: string): Promise<void>;
7
+ }
8
+
9
+ export default TurboModuleRegistry.getEnforcing<Spec>('RNSnapshotView');
@@ -0,0 +1,8 @@
1
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ import type { ViewProps } from 'react-native';
3
+
4
+ interface NativeProps extends ViewProps {
5
+ snapshotID?: string | null;
6
+ }
7
+
8
+ export default codegenNativeComponent<NativeProps>('RNSnapshotRenderer');
@@ -0,0 +1,44 @@
1
+ import { forwardRef, useEffect, useRef, type ForwardedRef } from 'react';
2
+ import type { View, ViewProps } from 'react-native';
3
+ import RNSnapshotRenderer from './RNSnapshotRendererNativeComponent';
4
+ import { releaseSnapshot } from '.';
5
+
6
+ export type SnapshotRendererProps = Omit<ViewProps, 'children'> & {
7
+ /**
8
+ * The ID of the snapshot to render.
9
+ * This ID is returned by the `captureSnapshot` function.
10
+ */
11
+ snapshotID: string | null;
12
+ /**
13
+ * Whether to automatically release the snapshot when no longer displayed.
14
+ * @default true
15
+ */
16
+ autoReleaseSnapshot?: boolean;
17
+ };
18
+
19
+ /**
20
+ * A view that renders a snapshot of a view.
21
+ */
22
+ const SnapshotRenderer = (
23
+ { snapshotID, autoReleaseSnapshot = true, ...props }: SnapshotRendererProps,
24
+ forwardedRef: ForwardedRef<View>
25
+ ) => {
26
+ const autoReleaseSnapshotRef = useRef(autoReleaseSnapshot);
27
+ useEffect(() => {
28
+ autoReleaseSnapshotRef.current = autoReleaseSnapshot;
29
+ }, [autoReleaseSnapshot]);
30
+
31
+ useEffect(
32
+ () => () => {
33
+ if (autoReleaseSnapshotRef.current && snapshotID) {
34
+ releaseSnapshot(snapshotID).catch(() => {});
35
+ }
36
+ },
37
+ [snapshotID]
38
+ );
39
+ return (
40
+ <RNSnapshotRenderer ref={forwardedRef} snapshotID={snapshotID} {...props} />
41
+ );
42
+ };
43
+
44
+ export default forwardRef(SnapshotRenderer);
package/src/index.tsx ADDED
@@ -0,0 +1,57 @@
1
+ import { findNodeHandle, NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package '@azzapp/react-native-snapshot-view' doesn't seem to be linked. Make sure: \n\n` +
5
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
+
9
+ // @ts-expect-error
10
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
11
+
12
+ const RNSnapshotViewModule = isTurboModuleEnabled
13
+ ? require('./NativeRNSnapshotView').default
14
+ : NativeModules.RNSnapshotView;
15
+
16
+ const RNSnapshotView = RNSnapshotViewModule
17
+ ? RNSnapshotViewModule
18
+ : new Proxy(
19
+ {},
20
+ {
21
+ get() {
22
+ throw new Error(LINKING_ERROR);
23
+ },
24
+ }
25
+ );
26
+
27
+ /**
28
+ * Captures a snapshot of a view. The snapshot can be rendered using the `SnapshotRenderer` component.
29
+ *
30
+ * @param componentOrHandle The view to capture. Can be a view ref or a native component handle.
31
+ * @returns A promise that resolves to the ID of the snapshot. The snapshot should be released when no longer needed.
32
+ */
33
+ export function captureSnapshot(
34
+ componentOrHandle:
35
+ | null
36
+ | number
37
+ | React.Component<any, any>
38
+ | React.ComponentClass<any>
39
+ ): Promise<string> {
40
+ const handle = findNodeHandle(componentOrHandle);
41
+ if (handle == null) {
42
+ return Promise.reject(new Error('Invalid node handle'));
43
+ }
44
+ return RNSnapshotView.captureSnapshot(handle);
45
+ }
46
+
47
+ /**
48
+ * Releases a snapshot.
49
+ *
50
+ * @param snapshotID The ID of the snapshot to release.
51
+ * @returns A promise that resolves when the snapshot is released.
52
+ */
53
+ export function releaseSnapshot(snapshotID: string): Promise<void> {
54
+ return RNSnapshotView.releaseSnapshot(snapshotID);
55
+ }
56
+
57
+ export { default as SnapshotRenderer } from './SnapshotRenderer';