@goliapkg/sentori-react-native 0.7.2 → 0.7.4
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/sentori/SentoriModule.kt +10 -0
- package/android/src/main/java/com/sentori/SentoriScreenshotCapture.kt +60 -2
- package/ios/SentoriModule.swift +10 -0
- package/ios/SentoriScreenshotCapture.swift +76 -2
- package/lib/capture.d.ts.map +1 -1
- package/lib/capture.js +23 -1
- package/lib/capture.js.map +1 -1
- package/lib/handlers/screenshot.d.ts +3 -2
- package/lib/handlers/screenshot.d.ts.map +1 -1
- package/lib/handlers/screenshot.js +47 -94
- package/lib/handlers/screenshot.js.map +1 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -5
- package/lib/index.js.map +1 -1
- package/lib/init.d.ts +8 -4
- package/lib/init.d.ts.map +1 -1
- package/lib/init.js +5 -0
- package/lib/init.js.map +1 -1
- package/lib/mask.d.ts +11 -47
- package/lib/mask.d.ts.map +1 -1
- package/lib/mask.js +27 -116
- package/lib/mask.js.map +1 -1
- package/lib/native.d.ts +15 -0
- package/lib/native.d.ts.map +1 -1
- package/lib/native.js +22 -0
- package/lib/native.js.map +1 -1
- package/lib/navigation.d.ts.map +1 -1
- package/lib/navigation.js +33 -9
- package/lib/navigation.js.map +1 -1
- package/lib/netinfo.d.ts +14 -0
- package/lib/netinfo.d.ts.map +1 -0
- package/lib/netinfo.js +70 -0
- package/lib/netinfo.js.map +1 -0
- package/package.json +7 -8
- package/src/__tests__/screenshot.test.ts +6 -8
- package/src/capture.ts +26 -1
- package/src/handlers/screenshot.ts +46 -117
- package/src/index.ts +4 -5
- package/src/init.ts +13 -4
- package/src/mask.ts +41 -0
- package/src/native.ts +35 -0
- package/src/navigation.ts +37 -9
- package/src/netinfo.ts +81 -0
- package/src/mask.tsx +0 -150
package/src/mask.tsx
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// Phase 42 sub-D.09/10 + Phase 48 sub-B — mark UI regions as "do not
|
|
2
|
-
// screenshot" AND actually redact them at capture time.
|
|
3
|
-
//
|
|
4
|
-
// `<MaskRegion>` renders its children normally, plus a black overlay
|
|
5
|
-
// `<View>` that sits on top of them with `opacity: 0`. Right before
|
|
6
|
-
// `captureScreenshot()` calls into react-native-view-shot, the SDK
|
|
7
|
-
// flips every registered overlay to `opacity: 1` (black square covers
|
|
8
|
-
// the children), captures, then flips back to `opacity: 0` so the
|
|
9
|
-
// user never sees the overlay. The overlay uses `pointerEvents="none"`
|
|
10
|
-
// so it never intercepts touches.
|
|
11
|
-
//
|
|
12
|
-
// `setMaskedNode(ref)` is the imperative escape hatch for views you
|
|
13
|
-
// can't wrap. We can't inject an overlay into a foreign view, so the
|
|
14
|
-
// imperative path falls back to setting the registered view's own
|
|
15
|
-
// `opacity: 0` for the capture window — content underneath may show
|
|
16
|
-
// through, but that beats sending the sensitive content to the server.
|
|
17
|
-
// Prefer `<MaskRegion>` when you control the subtree.
|
|
18
|
-
|
|
19
|
-
import React, { type ReactNode, useEffect, useRef } from 'react';
|
|
20
|
-
import { StyleSheet, View, type ViewProps } from 'react-native';
|
|
21
|
-
|
|
22
|
-
/** What we drive in the capture window: any handle with
|
|
23
|
-
* `setNativeProps({ opacity })`. RN's View instance satisfies this. */
|
|
24
|
-
type Maskable = {
|
|
25
|
-
setNativeProps?: (props: { style?: { opacity?: number } }) => void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const _maskedRefs = new Set<Maskable>();
|
|
29
|
-
const _maskedOverlays = new Set<Maskable>();
|
|
30
|
-
const _maskedNativeIds = new Set<string>();
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Imperative registration: pass a ref obtained via `useRef()` /
|
|
34
|
-
* `createRef()` to a `<View>` you want hidden from screenshots.
|
|
35
|
-
*/
|
|
36
|
-
export function setMaskedNode(node: null | Maskable | unknown): void {
|
|
37
|
-
if (!node || typeof (node as Maskable).setNativeProps !== 'function') return;
|
|
38
|
-
_maskedRefs.add(node as Maskable);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function unsetMaskedNode(node: null | Maskable | unknown): void {
|
|
42
|
-
if (!node) return;
|
|
43
|
-
_maskedRefs.delete(node as Maskable);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Returns the current set of registered masked nodes + nativeIDs.
|
|
47
|
-
* Read by the native screenshotter layer (iOS / Android sub-E / F). */
|
|
48
|
-
export function getMaskedRegions(): {
|
|
49
|
-
nativeIds: Set<string>;
|
|
50
|
-
overlays: Set<Maskable>;
|
|
51
|
-
refs: Set<Maskable>;
|
|
52
|
-
} {
|
|
53
|
-
return { nativeIds: _maskedNativeIds, overlays: _maskedOverlays, refs: _maskedRefs };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Phase 48 sub-B — engage masking right before screenshot capture.
|
|
58
|
-
* Returns a function the caller must invoke once capture is done so
|
|
59
|
-
* the user never sees the black overlays.
|
|
60
|
-
*
|
|
61
|
-
* Two paths:
|
|
62
|
-
* - Overlays from `<MaskRegion>`: flip opacity 0 → 1 (cover children).
|
|
63
|
-
* - Imperative refs from `setMaskedNode`: flip opacity 1 → 0 on the
|
|
64
|
-
* view itself (whole subtree disappears for one frame).
|
|
65
|
-
*
|
|
66
|
-
* All `setNativeProps` calls are best-effort — a failure on one
|
|
67
|
-
* doesn't block the others or the capture.
|
|
68
|
-
*/
|
|
69
|
-
export function engageMasks(): () => void {
|
|
70
|
-
const overlaysEngaged: Maskable[] = [];
|
|
71
|
-
for (const o of _maskedOverlays) {
|
|
72
|
-
try {
|
|
73
|
-
o.setNativeProps?.({ style: { opacity: 1 } });
|
|
74
|
-
overlaysEngaged.push(o);
|
|
75
|
-
} catch {
|
|
76
|
-
// skip
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const refsEngaged: Maskable[] = [];
|
|
80
|
-
for (const r of _maskedRefs) {
|
|
81
|
-
try {
|
|
82
|
-
r.setNativeProps?.({ style: { opacity: 0 } });
|
|
83
|
-
refsEngaged.push(r);
|
|
84
|
-
} catch {
|
|
85
|
-
// skip
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return () => {
|
|
89
|
-
for (const o of overlaysEngaged) {
|
|
90
|
-
try {
|
|
91
|
-
o.setNativeProps?.({ style: { opacity: 0 } });
|
|
92
|
-
} catch {
|
|
93
|
-
// skip
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
for (const r of refsEngaged) {
|
|
97
|
-
try {
|
|
98
|
-
r.setNativeProps?.({ style: { opacity: 1 } });
|
|
99
|
-
} catch {
|
|
100
|
-
// skip
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Declarative redaction. `<MaskRegion>{children}</MaskRegion>` keeps
|
|
108
|
-
* the children visible in normal flight; under capture the overlay's
|
|
109
|
-
* opacity is flipped to 1 and the children are hidden behind a black
|
|
110
|
-
* square in the rendered screenshot.
|
|
111
|
-
*/
|
|
112
|
-
export function MaskRegion({
|
|
113
|
-
children,
|
|
114
|
-
nativeID,
|
|
115
|
-
...rest
|
|
116
|
-
}: { children: ReactNode; nativeID?: string } & ViewProps): React.JSX.Element {
|
|
117
|
-
const idRef = useRef<string>(
|
|
118
|
-
nativeID ?? `sentori-mask-${Math.random().toString(36).slice(2, 10)}`,
|
|
119
|
-
);
|
|
120
|
-
const overlayRef = useRef<null | View>(null);
|
|
121
|
-
|
|
122
|
-
useEffect(() => {
|
|
123
|
-
const id = idRef.current;
|
|
124
|
-
_maskedNativeIds.add(id);
|
|
125
|
-
const overlay = overlayRef.current as null | Maskable;
|
|
126
|
-
if (overlay) _maskedOverlays.add(overlay);
|
|
127
|
-
return () => {
|
|
128
|
-
_maskedNativeIds.delete(id);
|
|
129
|
-
if (overlay) _maskedOverlays.delete(overlay);
|
|
130
|
-
};
|
|
131
|
-
}, []);
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<View collapsable={false} nativeID={idRef.current} {...rest}>
|
|
135
|
-
{children}
|
|
136
|
-
<View
|
|
137
|
-
pointerEvents="none"
|
|
138
|
-
ref={overlayRef}
|
|
139
|
-
style={[StyleSheet.absoluteFill, { backgroundColor: '#000', opacity: 0 }]}
|
|
140
|
-
/>
|
|
141
|
-
</View>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** Test-only — flush registration tables. */
|
|
146
|
-
export function __resetMaskedRegionsForTests(): void {
|
|
147
|
-
_maskedRefs.clear();
|
|
148
|
-
_maskedOverlays.clear();
|
|
149
|
-
_maskedNativeIds.clear();
|
|
150
|
-
}
|