@amplitude/session-replay-react-native 0.1.0-beta.0 → 0.1.0-beta.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/AmplitudeSessionReplayReactNative.podspec +43 -2
- package/README.md +125 -0
- package/android/build.gradle +145 -5
- package/android/src/androidTest/java/com/amplitude/sessionreplayreactnative/SRMaskViewTest.kt +459 -0
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRDefaultMaskingPrimitive.kt +36 -0
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRMaskingPrimitive.kt +84 -0
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +51 -16
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +41 -0
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +7 -0
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskView.kt +174 -0
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskViewManager.kt +44 -0
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskViewPointerEvents.java +36 -0
- package/android/src/{main → oldarch}/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +2 -1
- package/android/src/oldarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +20 -0
- package/cpp/SRMaskViewComponentDescriptor.h +20 -0
- package/cpp/SRMaskViewShadowNode.cpp +54 -0
- package/cpp/SRMaskViewShadowNode.h +56 -0
- package/ios/AMPNativeSessionReplay.mm +20 -0
- package/ios/NativeSessionReplay.swift +29 -8
- package/ios/SRDefaultMaskingPrimitive.swift +34 -0
- package/ios/SRMaskingPrimitive.h +26 -0
- package/ios/SRMaskingRegistry.m +105 -0
- package/ios/fabric/SRMaskView.h +10 -0
- package/ios/fabric/SRMaskView.mm +178 -0
- package/lib/commonjs/Mask.types.js +29 -0
- package/lib/commonjs/Mask.types.js.map +1 -0
- package/lib/commonjs/fabric/MaskFabric.js +92 -0
- package/lib/commonjs/fabric/MaskFabric.js.map +1 -0
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mask-fallback.js +53 -0
- package/lib/commonjs/mask-fallback.js.map +1 -0
- package/lib/commonjs/native-module.js +10 -1
- package/lib/commonjs/native-module.js.map +1 -1
- package/lib/commonjs/paper/MaskPaper.js +27 -0
- package/lib/commonjs/paper/MaskPaper.js.map +1 -0
- package/lib/commonjs/specs/NativeAmpSessionReplay.js +22 -0
- package/lib/commonjs/specs/NativeAmpSessionReplay.js.map +1 -0
- package/lib/commonjs/specs/SRMaskViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/SRMaskViewNativeComponent.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/Mask.types.js +23 -0
- package/lib/module/Mask.types.js.map +1 -0
- package/lib/module/fabric/MaskFabric.js +85 -0
- package/lib/module/fabric/MaskFabric.js.map +1 -0
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mask-fallback.js +45 -0
- package/lib/module/mask-fallback.js.map +1 -0
- package/lib/module/native-module.js +10 -2
- package/lib/module/native-module.js.map +1 -1
- package/lib/module/paper/MaskPaper.js +21 -0
- package/lib/module/paper/MaskPaper.js.map +1 -0
- package/lib/module/specs/NativeAmpSessionReplay.js +18 -0
- package/lib/module/specs/NativeAmpSessionReplay.js.map +1 -0
- package/lib/module/specs/SRMaskViewNativeComponent.js +5 -0
- package/lib/module/specs/SRMaskViewNativeComponent.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/Mask.types.d.ts +38 -0
- package/lib/typescript/Mask.types.d.ts.map +1 -0
- package/lib/typescript/fabric/MaskFabric.d.ts +8 -0
- package/lib/typescript/fabric/MaskFabric.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +11 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/mask-fallback.d.ts +27 -0
- package/lib/typescript/mask-fallback.d.ts.map +1 -0
- package/lib/typescript/native-module.d.ts.map +1 -1
- package/lib/typescript/paper/MaskPaper.d.ts +10 -0
- package/lib/typescript/paper/MaskPaper.d.ts.map +1 -0
- package/lib/typescript/specs/NativeAmpSessionReplay.d.ts +15 -0
- package/lib/typescript/specs/NativeAmpSessionReplay.d.ts.map +1 -0
- package/lib/typescript/specs/SRMaskViewNativeComponent.d.ts +11 -0
- package/lib/typescript/specs/SRMaskViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +19 -6
- package/src/Mask.types.ts +45 -0
- package/src/fabric/MaskFabric.tsx +73 -0
- package/src/index.tsx +18 -0
- package/src/mask-fallback.tsx +60 -0
- package/src/native-module.ts +16 -10
- package/src/paper/MaskPaper.tsx +24 -0
- package/src/specs/NativeAmpSessionReplay.ts +29 -0
- package/src/specs/SRMaskViewNativeComponent.ts +12 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/session-replay-react-native",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "Amplitude Session Replay for React Native",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -61,6 +61,19 @@
|
|
|
61
61
|
"react": "*",
|
|
62
62
|
"react-native": "*"
|
|
63
63
|
},
|
|
64
|
+
"codegenConfig": {
|
|
65
|
+
"name": "AmpSessionReplaySpec",
|
|
66
|
+
"type": "all",
|
|
67
|
+
"jsSrcsDir": "src/specs",
|
|
68
|
+
"android": {
|
|
69
|
+
"javaPackageName": "com.amplitude.sessionreplayreactnative"
|
|
70
|
+
},
|
|
71
|
+
"ios": {
|
|
72
|
+
"componentProvider": {
|
|
73
|
+
"SRMaskView": "SRMaskView"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
64
77
|
"react-native-builder-bob": {
|
|
65
78
|
"source": "src",
|
|
66
79
|
"output": "lib",
|
|
@@ -79,13 +92,13 @@
|
|
|
79
92
|
"build": "bob build",
|
|
80
93
|
"clean": "rimraf node_modules lib coverage",
|
|
81
94
|
"fix": "pnpm fix:eslint & pnpm fix:prettier",
|
|
82
|
-
"fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
|
|
83
|
-
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
|
|
95
|
+
"fix:eslint": "eslint '{src,test}/**/*.{ts,tsx}' --fix",
|
|
96
|
+
"fix:prettier": "prettier --write \"{src,test}/**/*.{ts,tsx}\"",
|
|
84
97
|
"lint": "pnpm lint:prettier && pnpm lint:eslint",
|
|
85
|
-
"lint:eslint": "eslint '{src,test}/**/*.ts'",
|
|
86
|
-
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
|
|
98
|
+
"lint:eslint": "eslint '{src,test}/**/*.{ts,tsx}'",
|
|
99
|
+
"lint:prettier": "prettier --check \"{src,test}/**/*.{ts,tsx}\"",
|
|
87
100
|
"test": "jest",
|
|
88
|
-
"typecheck": "tsc -p ./tsconfig.json",
|
|
101
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit",
|
|
89
102
|
"version": "pnpm version-file && pnpm build",
|
|
90
103
|
"version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
|
|
91
104
|
"typescript": "tsc --noEmit",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Masking level for `<AmpMask>`. See {@link MaskProps.maskLevel}. */
|
|
5
|
+
export type AmpMaskLevel = 'mask' | 'block';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for `<AmpMask>`, which masks its children in Session Replay
|
|
9
|
+
* recordings without affecting their layout.
|
|
10
|
+
*
|
|
11
|
+
* `style` is not supported: the wrapper is layout-transparent and never
|
|
12
|
+
* carries a layout box of its own, so styles would have no effect.
|
|
13
|
+
*/
|
|
14
|
+
export interface MaskProps extends Omit<ViewProps, 'style'> {
|
|
15
|
+
/**
|
|
16
|
+
* When false, children are rendered without masking.
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Masking level applied to children. On iOS, 'mask' and 'block' currently
|
|
23
|
+
* behave identically (both fully block).
|
|
24
|
+
* @default 'mask'
|
|
25
|
+
*/
|
|
26
|
+
maskLevel?: AmpMaskLevel;
|
|
27
|
+
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Props for `<AmpUnmask>`, which exempts its children from masking inside a
|
|
33
|
+
* masked region, without affecting their layout.
|
|
34
|
+
*
|
|
35
|
+
* `style` is not supported: the wrapper is layout-transparent and never
|
|
36
|
+
* carries a layout box of its own, so styles would have no effect.
|
|
37
|
+
*/
|
|
38
|
+
export interface UnmaskProps extends Omit<ViewProps, 'style'> {
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Maps the public {@link AmpMaskLevel} to the `<AmpMaskView>` `mask` prop value. */
|
|
43
|
+
export function ampMaskViewMaskProp(level?: AmpMaskLevel): 'amp-mask' | 'amp-block' {
|
|
44
|
+
return level === 'block' ? 'amp-block' : 'amp-mask';
|
|
45
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NativeModules, TurboModuleRegistry, UIManager } from 'react-native';
|
|
3
|
+
import SRMaskViewNative from '../specs/SRMaskViewNativeComponent';
|
|
4
|
+
import { createAmpMaskViewFallback, warnOnce } from '../mask-fallback';
|
|
5
|
+
import type { MaskProps, UnmaskProps } from '../Mask.types';
|
|
6
|
+
|
|
7
|
+
// Three-tier fail-closed probe. We never fall open (unmasked) unless the
|
|
8
|
+
// package's native code is entirely absent — i.e. the recorder itself cannot
|
|
9
|
+
// run and nothing can be captured:
|
|
10
|
+
// 1. SRMaskView registered -> use it directly, layout-transparent.
|
|
11
|
+
// 2. Only the Paper AMPMaskComponentView registered (Fabric sources not
|
|
12
|
+
// built) -> render through <AmpMaskView>: masked, layout-unsafe.
|
|
13
|
+
// 3. Neither registered -> behavior depends on RECORDER_PRESENT below.
|
|
14
|
+
const FABRIC_AVAILABLE = UIManager.hasViewManagerConfig?.('SRMaskView') ?? false;
|
|
15
|
+
const PAPER_MASK_AVAILABLE = UIManager.hasViewManagerConfig?.('AMPMaskComponentView') ?? false;
|
|
16
|
+
// Whether the Session Replay native module is linked. Must be resolved the
|
|
17
|
+
// same way src/native-module.ts resolves it (TurboModuleRegistry.get, then the
|
|
18
|
+
// legacy NativeModules interop proxy) so this gate can never disagree with the
|
|
19
|
+
// recorder's actual availability.
|
|
20
|
+
const RECORDER_PRESENT =
|
|
21
|
+
(TurboModuleRegistry?.get?.('AMPNativeSessionReplay') ?? NativeModules?.AMPNativeSessionReplay) != null;
|
|
22
|
+
|
|
23
|
+
const contents = { display: 'contents' as unknown as 'flex' }; // zero-box hint; C++ adopt() is authoritative
|
|
24
|
+
|
|
25
|
+
function MaskImpl({ enabled = true, maskLevel = 'mask', children, ...vp }: MaskProps) {
|
|
26
|
+
return (
|
|
27
|
+
<SRMaskViewNative {...vp} enabled={enabled} unmask={false} maskLevel={maskLevel} style={contents}>
|
|
28
|
+
{children}
|
|
29
|
+
</SRMaskViewNative>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function UnmaskImpl({ children, ...vp }: UnmaskProps) {
|
|
33
|
+
return (
|
|
34
|
+
<SRMaskViewNative {...vp} enabled unmask maskLevel="mask" style={contents}>
|
|
35
|
+
{children}
|
|
36
|
+
</SRMaskViewNative>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Tier 2: masked but not layout-transparent. `enabled` is intentionally
|
|
41
|
+
// ignored (over-mask), matching the Old-Arch prod fallback in MaskPaper.
|
|
42
|
+
const FALLBACK_WARNING =
|
|
43
|
+
'[AmpMask] New Architecture detected but the native SRMaskView component is unavailable — falling back to <AmpMaskView> (content stays MASKED but layout transparency is lost). Verify the Fabric masking sources were built (new architecture + RN >= 0.77) and codegen ran. Note: Fabric without bridgeless (bridge mode) cannot detect SRMaskView on iOS and always uses this fallback.';
|
|
44
|
+
const FallbackMask = createAmpMaskViewFallback<MaskProps>({ mask: 'from-maskLevel', warning: FALLBACK_WARNING });
|
|
45
|
+
const FallbackUnmask = createAmpMaskViewFallback<UnmaskProps>({ mask: 'amp-unmask', warning: FALLBACK_WARNING });
|
|
46
|
+
|
|
47
|
+
// Tier 3: no masking-capable native view exists, so children render directly.
|
|
48
|
+
// Safe only when the recorder is absent too (nothing can be captured); when
|
|
49
|
+
// the recorder IS present this is a build error we must not infer our way
|
|
50
|
+
// past — throw in dev, warn loudly in prod.
|
|
51
|
+
const UNMASKED_WARNING =
|
|
52
|
+
'[AmpMask] New Architecture detected but the native SRMaskView component is unavailable — <AmpMask>/<AmpUnmask> render children UNMASKED. Verify the Fabric masking sources were built (new architecture + RN >= 0.77) and codegen ran.';
|
|
53
|
+
const UNMASKABLE_MSG =
|
|
54
|
+
'<AmpMask> cannot mask: the Session Replay native module is present but neither SRMaskView nor AMPMaskComponentView is registered. Fix the build before shipping.';
|
|
55
|
+
const UNMASKABLE_WARNING =
|
|
56
|
+
'[AmpMask] The Session Replay native module is present but neither SRMaskView nor AMPMaskComponentView is registered — <AmpMask>/<AmpUnmask> render children UNMASKED. This is a build error (not an expected environment) — fix the build before shipping.';
|
|
57
|
+
|
|
58
|
+
function createPassthrough(warning: string, devThrowMessage?: string) {
|
|
59
|
+
return function PassthroughChildren({ children }: { children?: React.ReactNode }) {
|
|
60
|
+
if (devThrowMessage !== undefined && __DEV__) {
|
|
61
|
+
throw new Error(devThrowMessage);
|
|
62
|
+
}
|
|
63
|
+
warnOnce(warning);
|
|
64
|
+
return <>{children}</>;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const Passthrough = createPassthrough(UNMASKED_WARNING);
|
|
68
|
+
const UnmaskableGuard = createPassthrough(UNMASKABLE_WARNING, UNMASKABLE_MSG);
|
|
69
|
+
|
|
70
|
+
const NeitherAvailable = RECORDER_PRESENT ? UnmaskableGuard : Passthrough;
|
|
71
|
+
|
|
72
|
+
export const AmpMask = FABRIC_AVAILABLE ? MaskImpl : PAPER_MASK_AVAILABLE ? FallbackMask : NeitherAvailable;
|
|
73
|
+
export const AmpUnmask = FABRIC_AVAILABLE ? UnmaskImpl : PAPER_MASK_AVAILABLE ? FallbackUnmask : NeitherAvailable;
|
package/src/index.tsx
CHANGED
|
@@ -14,3 +14,21 @@ export { SessionReplayPlugin } from './plugin-session-replay';
|
|
|
14
14
|
export type { SessionReplayPluginConfig } from './plugin-session-replay-config';
|
|
15
15
|
|
|
16
16
|
export { AmpMaskView } from './amp-mask-view';
|
|
17
|
+
|
|
18
|
+
import type { ComponentType } from 'react';
|
|
19
|
+
import type { MaskProps, UnmaskProps } from './Mask.types';
|
|
20
|
+
|
|
21
|
+
const g = global as unknown as { RN$Bridgeless?: boolean; nativeFabricUIManager?: unknown };
|
|
22
|
+
const isNewArch = g.RN$Bridgeless === true || g.nativeFabricUIManager != null;
|
|
23
|
+
/**
|
|
24
|
+
* Layout-transparent Session Replay masking.
|
|
25
|
+
* `<AmpMask>` masks its children; `<AmpUnmask>` exempts children inside a masked region.
|
|
26
|
+
* Requires the New Architecture (React Native >= 0.77). On the Old Architecture:
|
|
27
|
+
* throws in dev, falls back to `<AmpMaskView>` (masked but layout-unsafe) in prod.
|
|
28
|
+
* @experimental Subject to change while experimental.
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
|
|
31
|
+
export const { AmpMask, AmpUnmask }: { AmpMask: ComponentType<MaskProps>; AmpUnmask: ComponentType<UnmaskProps> } =
|
|
32
|
+
isNewArch ? require('./fabric/MaskFabric') : require('./paper/MaskPaper');
|
|
33
|
+
// Named AmpMaskLevel because `MaskLevel` is already exported from './session-replay-config'.
|
|
34
|
+
export type { MaskProps, UnmaskProps, AmpMaskLevel } from './Mask.types';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
3
|
+
import { AmpMaskView } from './amp-mask-view';
|
|
4
|
+
import { ampMaskViewMaskProp } from './Mask.types';
|
|
5
|
+
import type { AmpMaskLevel } from './Mask.types';
|
|
6
|
+
|
|
7
|
+
let warned = false;
|
|
8
|
+
|
|
9
|
+
/** Logs at most one degraded-masking error per app session, across all fallback paths. */
|
|
10
|
+
export function warnOnce(message: string) {
|
|
11
|
+
if (!warned) {
|
|
12
|
+
warned = true;
|
|
13
|
+
console.error(message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface FallbackOptions {
|
|
18
|
+
/** `mask` value forced onto `<AmpMaskView>`; 'from-maskLevel' derives it from the caller's `maskLevel` prop. */
|
|
19
|
+
mask: 'amp-unmask' | 'from-maskLevel';
|
|
20
|
+
/** Passed to {@link warnOnce} on every render. */
|
|
21
|
+
warning: string;
|
|
22
|
+
/** When set, dev builds throw this instead of rendering the fallback. */
|
|
23
|
+
devThrowMessage?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Builds an `<AmpMask>`/`<AmpUnmask>` stand-in that renders through the Paper
|
|
28
|
+
* `<AmpMaskView>`: privacy-safe (content stays masked) but not
|
|
29
|
+
* layout-transparent. Used when the Fabric `SRMaskView` isn't available —
|
|
30
|
+
* Old-Architecture apps and New-Architecture build misconfigurations.
|
|
31
|
+
*
|
|
32
|
+
* Fail-closed rules, enforced at runtime because untyped callers can spread
|
|
33
|
+
* arbitrary props even though the public types omit them:
|
|
34
|
+
* `style`/`enabled`/`mask` are stripped, and the forced `mask` value is
|
|
35
|
+
* applied after the caller's props so it can never be overridden.
|
|
36
|
+
*/
|
|
37
|
+
export function createAmpMaskViewFallback<P extends { children?: ReactNode }>(
|
|
38
|
+
options: FallbackOptions,
|
|
39
|
+
): (props: P) => ReactElement {
|
|
40
|
+
return function AmpMaskViewFallback(props: P) {
|
|
41
|
+
if (options.devThrowMessage !== undefined && __DEV__) {
|
|
42
|
+
throw new Error(options.devThrowMessage);
|
|
43
|
+
}
|
|
44
|
+
warnOnce(options.warning);
|
|
45
|
+
const {
|
|
46
|
+
children,
|
|
47
|
+
maskLevel,
|
|
48
|
+
style: _style,
|
|
49
|
+
enabled: _enabled,
|
|
50
|
+
mask: _mask,
|
|
51
|
+
...safeProps
|
|
52
|
+
} = props as P & { maskLevel?: AmpMaskLevel; style?: unknown; enabled?: boolean; mask?: unknown };
|
|
53
|
+
const mask = options.mask === 'amp-unmask' ? 'amp-unmask' : ampMaskViewMaskProp(maskLevel);
|
|
54
|
+
return (
|
|
55
|
+
<AmpMaskView {...safeProps} mask={mask}>
|
|
56
|
+
{children}
|
|
57
|
+
</AmpMaskView>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
}
|
package/src/native-module.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import SessionReplaySpec from './specs/NativeAmpSessionReplay';
|
|
2
3
|
|
|
3
4
|
const LINKING_ERROR =
|
|
4
5
|
`The package '@amplitude/session-replay-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -6,16 +7,21 @@ const LINKING_ERROR =
|
|
|
6
7
|
'- You rebuilt the app after installing the package\n' +
|
|
7
8
|
'- You are not using Expo Go\n';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
// JS callers use the rich, hand-written types below for full type safety; the
|
|
11
|
+
// codegen `Spec` is intentionally loose (`UnsafeObject`) at the native boundary.
|
|
12
|
+
// The spec resolves the native module via `TurboModuleRegistry.get` (both
|
|
13
|
+
// architectures). When the module isn't linked it resolves to null, so we fall
|
|
14
|
+
// back to a proxy that throws a descriptive linking error on first use rather
|
|
15
|
+
// than crashing app startup at import time.
|
|
16
|
+
export const NativeSessionReplay = (SessionReplaySpec ??
|
|
17
|
+
new Proxy(
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
20
|
+
get() {
|
|
21
|
+
throw new Error(LINKING_ERROR);
|
|
17
22
|
},
|
|
18
|
-
|
|
23
|
+
},
|
|
24
|
+
)) as unknown as NativeSessionReplaySpec;
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
27
|
* Configuration interface for setting up the native iOS and Android session replay modules.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createAmpMaskViewFallback } from '../mask-fallback';
|
|
2
|
+
import type { MaskProps, UnmaskProps } from '../Mask.types';
|
|
3
|
+
|
|
4
|
+
const MSG = '<AmpMask> requires the New Architecture. Use <AmpMaskView> on the Old Architecture.';
|
|
5
|
+
const WARNING =
|
|
6
|
+
'[AmpMask] Old Architecture detected — falling back to AmpMaskView (layout-unsafe). Use <AmpMaskView> on Old Arch.';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Old-Architecture guard: dev builds throw (the developer is using an
|
|
10
|
+
* unsupported component); production falls back to `<AmpMaskView>` —
|
|
11
|
+
* privacy-safe but layout-unsafe. `enabled` is ignored: the fallback fails
|
|
12
|
+
* toward privacy.
|
|
13
|
+
*/
|
|
14
|
+
export const AmpMask = createAmpMaskViewFallback<MaskProps>({
|
|
15
|
+
mask: 'from-maskLevel',
|
|
16
|
+
warning: WARNING,
|
|
17
|
+
devThrowMessage: MSG,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const AmpUnmask = createAmpMaskViewFallback<UnmaskProps>({
|
|
21
|
+
mask: 'amp-unmask',
|
|
22
|
+
warning: WARNING,
|
|
23
|
+
devThrowMessage: MSG,
|
|
24
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
// The codegen types live in a Flow-typed file that eslint-plugin-import cannot parse.
|
|
4
|
+
// eslint-disable-next-line import/namespace
|
|
5
|
+
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
|
+
|
|
7
|
+
// Codegen TurboModule spec for the imperative Session Replay module.
|
|
8
|
+
//
|
|
9
|
+
// The config crosses the bridge as an untyped object: the native side already
|
|
10
|
+
// reads a ReadableMap / NSDictionary, and app-boundary type safety lives in the
|
|
11
|
+
// public `SessionReplayConfig`. See native-module.ts for the typed facade that
|
|
12
|
+
// JS callers actually use.
|
|
13
|
+
export interface Spec extends TurboModule {
|
|
14
|
+
setup(config: UnsafeObject): Promise<void>;
|
|
15
|
+
setSessionId(sessionId: number): Promise<void>;
|
|
16
|
+
setDeviceId(deviceId: string | null): Promise<void>;
|
|
17
|
+
getSessionId(): Promise<number>;
|
|
18
|
+
getSessionReplayProperties(): Promise<UnsafeObject>;
|
|
19
|
+
start(): Promise<void>;
|
|
20
|
+
stop(): Promise<void>;
|
|
21
|
+
flush(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Use non-enforcing `get` (returns null when the native module isn't linked)
|
|
25
|
+
// so importing the package never crashes app startup. The typed facade in
|
|
26
|
+
// native-module.ts throws a friendly linking error lazily on first use instead.
|
|
27
|
+
// Works on both architectures: JSI on the New Architecture, legacy NativeModules
|
|
28
|
+
// fallback on the old one.
|
|
29
|
+
export default TurboModuleRegistry.get<Spec>('AMPNativeSessionReplay');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable import/namespace, import/default, import/no-named-as-default, import/no-named-as-default-member */
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
import type { WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
5
|
+
|
|
6
|
+
export interface NativeProps extends ViewProps {
|
|
7
|
+
enabled?: WithDefault<boolean, true>;
|
|
8
|
+
unmask?: WithDefault<boolean, false>;
|
|
9
|
+
maskLevel?: WithDefault<string, 'mask'>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default codegenNativeComponent<NativeProps>('SRMaskView');
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.0-beta.
|
|
1
|
+
export const VERSION = '0.1.0-beta.2';
|