@goliapkg/sentori-react-native 0.7.2 → 0.7.3

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/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
- }