@amplitude/session-replay-react-native 0.1.0-beta.2 → 0.1.0-beta.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/AmplitudeSessionReplayReactNative.podspec +2 -43
- package/README.md +3 -113
- package/android/build.gradle +19 -127
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +4 -62
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +4 -2
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/AmpMaskViewManager.kt +48 -0
- package/android/src/oldarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +0 -1
- package/ios/AMPNativeSessionReplay.mm +0 -2
- package/ios/AmpMaskApplier.h +22 -0
- package/ios/AmpMaskApplier.m +21 -0
- package/ios/NativeSessionReplay.swift +6 -41
- package/ios/fabric/AMPMaskComponentView.h +17 -0
- package/ios/fabric/AMPMaskComponentView.mm +78 -0
- package/lib/commonjs/amp-mask-view.js +9 -2
- package/lib/commonjs/amp-mask-view.js.map +1 -1
- package/lib/commonjs/index.js +0 -25
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-module.js.map +1 -1
- package/lib/commonjs/plugin-session-replay.js +5 -34
- package/lib/commonjs/plugin-session-replay.js.map +1 -1
- package/lib/commonjs/session-replay-config.js +0 -1
- package/lib/commonjs/session-replay-config.js.map +1 -1
- package/lib/commonjs/session-replay.js +4 -35
- package/lib/commonjs/session-replay.js.map +1 -1
- package/lib/commonjs/specs/{SRMaskViewNativeComponent.js → AmpMaskViewNativeComponent.js} +7 -2
- package/lib/commonjs/specs/AmpMaskViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeAmpSessionReplay.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/amp-mask-view.js +8 -2
- package/lib/module/amp-mask-view.js.map +1 -1
- package/lib/module/index.js +1 -16
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-module.js.map +1 -1
- package/lib/module/plugin-session-replay.js +6 -35
- package/lib/module/plugin-session-replay.js.map +1 -1
- package/lib/module/session-replay-config.js +0 -1
- package/lib/module/session-replay-config.js.map +1 -1
- package/lib/module/session-replay.js +4 -34
- package/lib/module/session-replay.js.map +1 -1
- package/lib/module/specs/AmpMaskViewNativeComponent.js +10 -0
- package/lib/module/specs/AmpMaskViewNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeAmpSessionReplay.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/amp-mask-view.d.ts +4 -4
- package/lib/typescript/amp-mask-view.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -13
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/native-module.d.ts +0 -12
- package/lib/typescript/native-module.d.ts.map +1 -1
- package/lib/typescript/plugin-session-replay.d.ts +0 -16
- package/lib/typescript/plugin-session-replay.d.ts.map +1 -1
- package/lib/typescript/session-replay-config.d.ts +0 -5
- package/lib/typescript/session-replay-config.d.ts.map +1 -1
- package/lib/typescript/session-replay.d.ts +4 -28
- package/lib/typescript/session-replay.d.ts.map +1 -1
- package/lib/typescript/specs/{SRMaskViewNativeComponent.d.ts → AmpMaskViewNativeComponent.d.ts} +2 -4
- package/lib/typescript/specs/AmpMaskViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/NativeAmpSessionReplay.d.ts +0 -1
- package/lib/typescript/specs/NativeAmpSessionReplay.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/amp-mask-view.tsx +11 -3
- package/src/index.tsx +2 -29
- package/src/native-module.ts +0 -14
- package/src/plugin-session-replay.ts +4 -33
- package/src/session-replay-config.ts +0 -7
- package/src/session-replay.ts +4 -37
- package/src/specs/AmpMaskViewNativeComponent.ts +17 -0
- package/src/specs/NativeAmpSessionReplay.ts +0 -1
- package/src/version.ts +1 -1
- package/android/src/androidTest/java/com/amplitude/sessionreplayreactnative/SRMaskViewTest.kt +0 -459
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRDefaultMaskingPrimitive.kt +0 -36
- package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRMaskingPrimitive.kt +0 -84
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskView.kt +0 -174
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskViewManager.kt +0 -44
- package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskViewPointerEvents.java +0 -36
- package/cpp/SRMaskViewComponentDescriptor.h +0 -20
- package/cpp/SRMaskViewShadowNode.cpp +0 -54
- package/cpp/SRMaskViewShadowNode.h +0 -56
- package/ios/SRDefaultMaskingPrimitive.swift +0 -34
- package/ios/SRMaskingPrimitive.h +0 -26
- package/ios/SRMaskingRegistry.m +0 -105
- package/ios/fabric/SRMaskView.h +0 -10
- package/ios/fabric/SRMaskView.mm +0 -178
- package/lib/commonjs/Mask.types.js +0 -29
- package/lib/commonjs/Mask.types.js.map +0 -1
- package/lib/commonjs/fabric/MaskFabric.js +0 -92
- package/lib/commonjs/fabric/MaskFabric.js.map +0 -1
- package/lib/commonjs/mask-fallback.js +0 -53
- package/lib/commonjs/mask-fallback.js.map +0 -1
- package/lib/commonjs/paper/MaskPaper.js +0 -27
- package/lib/commonjs/paper/MaskPaper.js.map +0 -1
- package/lib/commonjs/specs/SRMaskViewNativeComponent.js.map +0 -1
- package/lib/module/Mask.types.js +0 -23
- package/lib/module/Mask.types.js.map +0 -1
- package/lib/module/fabric/MaskFabric.js +0 -85
- package/lib/module/fabric/MaskFabric.js.map +0 -1
- package/lib/module/mask-fallback.js +0 -45
- package/lib/module/mask-fallback.js.map +0 -1
- package/lib/module/paper/MaskPaper.js +0 -21
- package/lib/module/paper/MaskPaper.js.map +0 -1
- package/lib/module/specs/SRMaskViewNativeComponent.js +0 -5
- package/lib/module/specs/SRMaskViewNativeComponent.js.map +0 -1
- package/lib/typescript/Mask.types.d.ts +0 -38
- package/lib/typescript/Mask.types.d.ts.map +0 -1
- package/lib/typescript/fabric/MaskFabric.d.ts +0 -8
- package/lib/typescript/fabric/MaskFabric.d.ts.map +0 -1
- package/lib/typescript/mask-fallback.d.ts +0 -27
- package/lib/typescript/mask-fallback.d.ts.map +0 -1
- package/lib/typescript/paper/MaskPaper.d.ts +0 -10
- package/lib/typescript/paper/MaskPaper.d.ts.map +0 -1
- package/lib/typescript/specs/SRMaskViewNativeComponent.d.ts.map +0 -1
- package/src/Mask.types.ts +0 -45
- package/src/fabric/MaskFabric.tsx +0 -73
- package/src/mask-fallback.tsx +0 -60
- package/src/paper/MaskPaper.tsx +0 -24
- package/src/specs/SRMaskViewNativeComponent.ts +0 -12
package/src/session-replay.ts
CHANGED
|
@@ -32,12 +32,12 @@ let isInitialized = false;
|
|
|
32
32
|
let logger = createSessionReplayLogger();
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Configure the SDK
|
|
35
|
+
* Configure the SDK. Call `start()` explicitly to begin collecting replays.
|
|
36
36
|
* This function must be called before any other session replay operations.
|
|
37
37
|
*
|
|
38
38
|
* @param config - Configuration object containing API key, device ID, session ID, and other options
|
|
39
|
-
* @returns Promise that resolves when initialization is complete
|
|
40
|
-
*
|
|
39
|
+
* @returns Promise that resolves when initialization is complete. Native setup
|
|
40
|
+
* failures are logged and do not reject the promise.
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* ```typescript
|
|
@@ -139,38 +139,6 @@ export async function getSessionId(): Promise<number | null> {
|
|
|
139
139
|
return await NativeSessionReplay.getSessionId();
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
/**
|
|
143
|
-
* Interface for session replay properties that should be attached to Amplitude events.
|
|
144
|
-
* These properties help correlate events with session recordings.
|
|
145
|
-
*/
|
|
146
|
-
export interface SessionReplayProperties {
|
|
147
|
-
[key: string]: string | boolean | null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* When you send events to Amplitude, call this function to get the most up-to-date session replay properties for the event.
|
|
152
|
-
* Collect Session Replay properties to send with other event properties.
|
|
153
|
-
*
|
|
154
|
-
* @returns Promise that resolves to an object containing session replay metadata
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* const sessionReplayProperties = await getSessionReplayProperties();
|
|
159
|
-
* analytics.track('Button Clicked', {
|
|
160
|
-
* buttonName: 'submit',
|
|
161
|
-
* ...sessionReplayProperties // Merge session replay properties
|
|
162
|
-
* });
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export async function getSessionReplayProperties(): Promise<SessionReplayProperties> {
|
|
166
|
-
if (!isInitialized) {
|
|
167
|
-
logger.warn('SessionReplay is not initialized');
|
|
168
|
-
return {};
|
|
169
|
-
}
|
|
170
|
-
const properties = await NativeSessionReplay.getSessionReplayProperties();
|
|
171
|
-
return properties as SessionReplayProperties;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
142
|
/**
|
|
175
143
|
* Flush any pending session replay data to the server.
|
|
176
144
|
* Forces immediate upload of recorded session data that may be buffered locally.
|
|
@@ -194,13 +162,12 @@ export async function flush(): Promise<void> {
|
|
|
194
162
|
/**
|
|
195
163
|
* Start session replay recording.
|
|
196
164
|
* Begins capturing user interactions and screen content for replay.
|
|
197
|
-
* If autoStart is enabled in the configuration, this is called automatically during initialization.
|
|
198
165
|
*
|
|
199
166
|
* @returns Promise that resolves when recording starts
|
|
200
167
|
*
|
|
201
168
|
* @example
|
|
202
169
|
* ```typescript
|
|
203
|
-
* //
|
|
170
|
+
* // Recording starts only after this explicit call.
|
|
204
171
|
* await start();
|
|
205
172
|
* ```
|
|
206
173
|
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
// 'amp-mask' | 'amp-unmask' | 'amp-block' as a codegen-compatible string;
|
|
8
|
+
// unknown values fail safe to masking.
|
|
9
|
+
mask?: WithDefault<string, 'amp-mask'>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Same native name on both architectures: on the New Architecture this resolves
|
|
13
|
+
// to the Fabric AMPMaskComponentView (ios/fabric, android/src/newarch); on the
|
|
14
|
+
// old architecture codegenNativeComponent falls back to
|
|
15
|
+
// requireNativeComponent('AMPMaskComponentView'), which resolves to the
|
|
16
|
+
// unchanged legacy Paper view managers.
|
|
17
|
+
export default codegenNativeComponent<NativeProps>('AMPMaskComponentView');
|
|
@@ -15,7 +15,6 @@ export interface Spec extends TurboModule {
|
|
|
15
15
|
setSessionId(sessionId: number): Promise<void>;
|
|
16
16
|
setDeviceId(deviceId: string | null): Promise<void>;
|
|
17
17
|
getSessionId(): Promise<number>;
|
|
18
|
-
getSessionReplayProperties(): Promise<UnsafeObject>;
|
|
19
18
|
start(): Promise<void>;
|
|
20
19
|
stop(): Promise<void>;
|
|
21
20
|
flush(): Promise<void>;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.0-beta.
|
|
1
|
+
export const VERSION = '0.1.0-beta.4';
|
package/android/src/androidTest/java/com/amplitude/sessionreplayreactnative/SRMaskViewTest.kt
DELETED
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
package com.amplitude.sessionreplayreactnative
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.view.View
|
|
5
|
-
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
6
|
-
import androidx.test.platform.app.InstrumentationRegistry
|
|
7
|
-
import com.amplitude.android.sessionreplay.SessionReplay
|
|
8
|
-
import com.amplitude.sessionreplayreactnative.fabric.SRMaskView
|
|
9
|
-
import com.amplitude.sessionreplayreactnative.fabric.SRMaskViewManager
|
|
10
|
-
import org.junit.After
|
|
11
|
-
import org.junit.Assert.assertEquals
|
|
12
|
-
import org.junit.Assert.assertNotNull
|
|
13
|
-
import org.junit.Assert.assertNull
|
|
14
|
-
import org.junit.Assert.assertSame
|
|
15
|
-
import org.junit.Assert.assertTrue
|
|
16
|
-
import org.junit.Before
|
|
17
|
-
import org.junit.Test
|
|
18
|
-
import com.facebook.react.uimanager.PointerEvents
|
|
19
|
-
import org.junit.runner.RunWith
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Instrumented canaries locking the masking model of the Fabric `SRMaskView`
|
|
23
|
-
* host and the `SRMaskingRegistry` seam:
|
|
24
|
-
* - per-child mask intent on add (one [SRMaskingPrimitive.mask] per direct child)
|
|
25
|
-
* - reset on child removal and on host drop ([SRMaskViewManager.onDropViewInstance])
|
|
26
|
-
* - capture-bounds: a degenerate 0x0 host frame is widened to the union of
|
|
27
|
-
* its children so `shouldCapture()` (width>0 && height>0) would pass
|
|
28
|
-
* - masking intent recorded before a primitive registers is replayed once
|
|
29
|
-
* a primitive registers
|
|
30
|
-
*
|
|
31
|
-
* The registry is process-global state. [SRMaskingRegistry.setPrimitive] is
|
|
32
|
-
* cleared (`null`) in [setUp]/[tearDown], but the registry intentionally retains
|
|
33
|
-
* its weak-keyed `intents` map (for replay-on-register) and exposes no public
|
|
34
|
-
* way to clear it. Because registering a primitive replays *every* still-live
|
|
35
|
-
* recorded intent, tests register their primitive first and then clear the
|
|
36
|
-
* recording before acting, so each assertion counts only its own calls (or
|
|
37
|
-
* scopes assertions to the specific view under test).
|
|
38
|
-
*/
|
|
39
|
-
@RunWith(AndroidJUnit4::class)
|
|
40
|
-
class SRMaskViewTest {
|
|
41
|
-
|
|
42
|
-
/** Records every call the Fabric host / registry routes through the seam. */
|
|
43
|
-
private class RecordingPrimitive : SRMaskingPrimitive {
|
|
44
|
-
sealed interface Call {
|
|
45
|
-
val view: View
|
|
46
|
-
|
|
47
|
-
data class Mask(override val view: View, val level: String) : Call
|
|
48
|
-
data class Unmask(override val view: View) : Call
|
|
49
|
-
data class Reset(override val view: View) : Call
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
val calls = mutableListOf<Call>()
|
|
53
|
-
|
|
54
|
-
val maskCalls get() = calls.filterIsInstance<Call.Mask>()
|
|
55
|
-
val resetCalls get() = calls.filterIsInstance<Call.Reset>()
|
|
56
|
-
|
|
57
|
-
override fun mask(view: View, level: String) {
|
|
58
|
-
calls.add(Call.Mask(view, level))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
override fun unmask(view: View) {
|
|
62
|
-
calls.add(Call.Unmask(view))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
override fun reset(view: View) {
|
|
66
|
-
calls.add(Call.Reset(view))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
fun resetCountFor(view: View): Int = resetCalls.count { it.view === view }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private val context: Context
|
|
73
|
-
get() = InstrumentationRegistry.getInstrumentation().targetContext
|
|
74
|
-
|
|
75
|
-
/** Run on the main looper; view layout/listeners require the UI thread. */
|
|
76
|
-
private fun onMain(block: () -> Unit) =
|
|
77
|
-
InstrumentationRegistry.getInstrumentation().runOnMainSync(block)
|
|
78
|
-
|
|
79
|
-
@Before
|
|
80
|
-
fun setUp() {
|
|
81
|
-
// Start each test from a clean, primitive-less registry.
|
|
82
|
-
SRMaskingRegistry.setPrimitive(null)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
@After
|
|
86
|
-
fun tearDown() {
|
|
87
|
-
SRMaskingRegistry.setPrimitive(null)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 1. Per-child mask: each direct child added to the host produces exactly one
|
|
91
|
-
// mask call, in add order.
|
|
92
|
-
@Test
|
|
93
|
-
fun perChildMask_emitsOneMaskPerDirectChild_inOrder() {
|
|
94
|
-
val recording = RecordingPrimitive()
|
|
95
|
-
SRMaskingRegistry.setPrimitive(recording)
|
|
96
|
-
// Drop any intents replayed from earlier tests; count only this test's adds.
|
|
97
|
-
recording.calls.clear()
|
|
98
|
-
|
|
99
|
-
val children = mutableListOf<View>()
|
|
100
|
-
onMain {
|
|
101
|
-
val host = SRMaskView(context)
|
|
102
|
-
repeat(3) {
|
|
103
|
-
val child = View(context)
|
|
104
|
-
children.add(child)
|
|
105
|
-
host.addView(child)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
assertEquals(
|
|
110
|
-
"expected one mask call per direct child",
|
|
111
|
-
3,
|
|
112
|
-
recording.maskCalls.size,
|
|
113
|
-
)
|
|
114
|
-
// Same views, same order, default level "mask".
|
|
115
|
-
recording.maskCalls.forEachIndexed { i, call ->
|
|
116
|
-
assertSame("mask call $i targets the wrong view", children[i], call.view)
|
|
117
|
-
assertEquals("default mask level should be \"mask\"", "mask", call.level)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 2. Reset on removeView: removing a child fires reset for exactly that child.
|
|
122
|
-
@Test
|
|
123
|
-
fun removeView_resetsRemovedChild() {
|
|
124
|
-
val recording = RecordingPrimitive()
|
|
125
|
-
SRMaskingRegistry.setPrimitive(recording)
|
|
126
|
-
recording.calls.clear()
|
|
127
|
-
|
|
128
|
-
lateinit var child: View
|
|
129
|
-
onMain {
|
|
130
|
-
val host = SRMaskView(context)
|
|
131
|
-
child = View(context)
|
|
132
|
-
host.addView(child)
|
|
133
|
-
host.removeView(child)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
assertEquals(
|
|
137
|
-
"removeView should reset exactly the removed child once",
|
|
138
|
-
1,
|
|
139
|
-
recording.resetCountFor(child),
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 3. Reset on onDropViewInstance: dropping the host resets every child.
|
|
144
|
-
@Test
|
|
145
|
-
fun onDropViewInstance_resetsAllChildren() {
|
|
146
|
-
val recording = RecordingPrimitive()
|
|
147
|
-
SRMaskingRegistry.setPrimitive(recording)
|
|
148
|
-
recording.calls.clear()
|
|
149
|
-
|
|
150
|
-
val manager = SRMaskViewManager()
|
|
151
|
-
val children = mutableListOf<View>()
|
|
152
|
-
onMain {
|
|
153
|
-
val host = SRMaskView(context)
|
|
154
|
-
repeat(3) {
|
|
155
|
-
val child = View(context)
|
|
156
|
-
children.add(child)
|
|
157
|
-
host.addView(child)
|
|
158
|
-
}
|
|
159
|
-
manager.onDropViewInstance(host)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
children.forEach { child ->
|
|
163
|
-
assertTrue(
|
|
164
|
-
"onDropViewInstance should reset child $child",
|
|
165
|
-
recording.resetCountFor(child) >= 1,
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 4. Capture-bounds: a host given a degenerate 0x0 frame widens itself to
|
|
171
|
-
// the union of its laid-out children, so width>0 && height>0
|
|
172
|
-
// (shouldCapture() would pass).
|
|
173
|
-
@Test
|
|
174
|
-
fun degenerateHostFrame_widensToChildrenUnion() {
|
|
175
|
-
lateinit var host: SRMaskView
|
|
176
|
-
onMain {
|
|
177
|
-
host = SRMaskView(context)
|
|
178
|
-
val a = View(context)
|
|
179
|
-
val b = View(context)
|
|
180
|
-
host.addView(a)
|
|
181
|
-
host.addView(b)
|
|
182
|
-
// Give children non-zero, disjoint frames.
|
|
183
|
-
a.layout(0, 0, 100, 50)
|
|
184
|
-
b.layout(120, 60, 200, 140)
|
|
185
|
-
// Simulate Fabric's display:contents 0x0 host frame. View.layout is final
|
|
186
|
-
// and invokes the overridden onLayout -> expandBoundsToChildrenUnion.
|
|
187
|
-
host.layout(0, 0, 0, 0)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
assertTrue(
|
|
191
|
-
"host width should be widened to the children union (got ${host.width})",
|
|
192
|
-
host.width > 0,
|
|
193
|
-
)
|
|
194
|
-
assertTrue(
|
|
195
|
-
"host height should be widened to the children union (got ${host.height})",
|
|
196
|
-
host.height > 0,
|
|
197
|
-
)
|
|
198
|
-
// Union of (0,0,100,50) and (120,60,200,140) is (0,0,200,140).
|
|
199
|
-
assertEquals("union width", 200, host.width)
|
|
200
|
-
assertEquals("union height", 140, host.height)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// 4b. A childless host stays 0x0 after a degenerate layout — nothing to
|
|
204
|
-
// capture, nothing to widen.
|
|
205
|
-
@Test
|
|
206
|
-
fun degenerateHostFrame_withNoChildren_staysZero() {
|
|
207
|
-
lateinit var host: SRMaskView
|
|
208
|
-
onMain {
|
|
209
|
-
host = SRMaskView(context)
|
|
210
|
-
host.layout(0, 0, 0, 0)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
assertEquals("childless host width should stay 0", 0, host.width)
|
|
214
|
-
assertEquals("childless host height should stay 0", 0, host.height)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 4c. Regression (measured on-device, RN 0.77.2 Fabric): Fabric lays the
|
|
218
|
-
// degenerate display:contents host out at a NON-ZERO parent offset
|
|
219
|
-
// (flattened intermediate views accumulate into the host origin — e.g.
|
|
220
|
-
// an AmpUnmask nested in an AmpMask through a flattened <View>, or a
|
|
221
|
-
// mask inside a list row) and the children frames are HOST-relative
|
|
222
|
-
// (a child renders at host.left + child.left). The host must widen to
|
|
223
|
-
// origin + children extent WITHOUT moving; treating the child extents
|
|
224
|
-
// as absolute (a previous revision) produced inverted frames
|
|
225
|
-
// (bottom < top) that the capture gate dropped.
|
|
226
|
-
@Test
|
|
227
|
-
fun degenerateHostFrame_atNonZeroOffset_widensWithoutMoving() {
|
|
228
|
-
lateinit var host: SRMaskView
|
|
229
|
-
onMain {
|
|
230
|
-
host = SRMaskView(context)
|
|
231
|
-
val a = View(context)
|
|
232
|
-
val b = View(context)
|
|
233
|
-
host.addView(a)
|
|
234
|
-
host.addView(b)
|
|
235
|
-
// Children laid out HOST-relative — as measured from Fabric.
|
|
236
|
-
a.layout(0, 0, 100, 50)
|
|
237
|
-
b.layout(120, 60, 200, 140)
|
|
238
|
-
// Fabric places the 0x0 display:contents host at a non-zero parent offset.
|
|
239
|
-
host.layout(300, 400, 300, 400)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Extent == origin + children union max right/bottom → (300,400,500,540).
|
|
243
|
-
assertEquals("union width at offset", 200, host.width)
|
|
244
|
-
assertEquals("union height at offset", 140, host.height)
|
|
245
|
-
// Position preserved — the host was NOT moved (else children shift absolutely).
|
|
246
|
-
assertEquals("host left preserved", 300, host.left)
|
|
247
|
-
assertEquals("host top preserved", 400, host.top)
|
|
248
|
-
// Never inverted: bottom/right beyond origin.
|
|
249
|
-
assertTrue("frame not inverted", host.bottom > host.top && host.right > host.left)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// 4d. A child at fully negative host-relative coordinates (e.g. the
|
|
253
|
-
// negative-offset badge shape) cannot be enclosed without moving the
|
|
254
|
-
// origin (forbidden). The frame must still never be degenerate or
|
|
255
|
-
// inverted — clamp to a 1x1 minimum so shouldCapture() keeps the
|
|
256
|
-
// subtree.
|
|
257
|
-
@Test
|
|
258
|
-
fun degenerateHostFrame_withFullyNegativeChild_clampsToOnePixel() {
|
|
259
|
-
lateinit var host: SRMaskView
|
|
260
|
-
onMain {
|
|
261
|
-
host = SRMaskView(context)
|
|
262
|
-
val a = View(context)
|
|
263
|
-
host.addView(a)
|
|
264
|
-
a.layout(-50, -60, -10, -20) // entirely above/left of the host origin
|
|
265
|
-
host.layout(74, 3018, 74, 3018)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
assertEquals("clamped width", 1, host.width)
|
|
269
|
-
assertEquals("clamped height", 1, host.height)
|
|
270
|
-
assertEquals("host left preserved", 74, host.left)
|
|
271
|
-
assertEquals("host top preserved", 3018, host.top)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// 4e. Nested-mask shape (AmpUnmask host inside an AmpMask host): the inner
|
|
275
|
-
// host sits at a non-zero offset inside the outer host with its own
|
|
276
|
-
// host-relative children; the outer host's union must enclose the
|
|
277
|
-
// inner host's WIDENED frame. Mirrors the measured Mask-screen nesting
|
|
278
|
-
// (outer at (0,0,0,0); inner fabric frame (32,2016,32,2016), inner
|
|
279
|
-
// child (0,124,1017,175)).
|
|
280
|
-
@Test
|
|
281
|
-
fun nestedHosts_outerEnclosesInnerWidenedFrame() {
|
|
282
|
-
lateinit var outer: SRMaskView
|
|
283
|
-
lateinit var inner: SRMaskView
|
|
284
|
-
onMain {
|
|
285
|
-
outer = SRMaskView(context)
|
|
286
|
-
inner = SRMaskView(context)
|
|
287
|
-
val innerChild = View(context)
|
|
288
|
-
val outerText = View(context)
|
|
289
|
-
outer.addView(outerText)
|
|
290
|
-
outer.addView(inner)
|
|
291
|
-
inner.addView(innerChild)
|
|
292
|
-
outerText.layout(32, 2047, 1049, 2098) // host-relative to outer
|
|
293
|
-
innerChild.layout(0, 124, 1017, 175) // host-relative to inner
|
|
294
|
-
inner.layout(32, 2016, 32, 2016) // Fabric's degenerate offset frame
|
|
295
|
-
outer.layout(0, 0, 0, 0)
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Inner: origin + child extent = (32,2016,1049,2191), never inverted.
|
|
299
|
-
assertEquals("inner left", 32, inner.left)
|
|
300
|
-
assertEquals("inner top", 2016, inner.top)
|
|
301
|
-
assertEquals("inner width", 1017, inner.width)
|
|
302
|
-
assertEquals("inner height", 175, inner.height)
|
|
303
|
-
// Outer: encloses max(outerText.right, inner.right)=1049 and
|
|
304
|
-
// max(outerText.bottom, inner.bottom)=2191 from its (0,0) origin.
|
|
305
|
-
assertEquals("outer width", 1049, outer.width)
|
|
306
|
-
assertEquals("outer height", 2191, outer.height)
|
|
307
|
-
assertTrue("outer capture gate", outer.width > 0 && outer.height > 0)
|
|
308
|
-
assertTrue("inner capture gate", inner.width > 0 && inner.height > 0)
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// 5. Dropping the host detaches each child's layout listener, so a child that is
|
|
312
|
-
// recycled/reparented WITHOUT going through removeView no longer fires layout
|
|
313
|
-
// callbacks against (or leaks) the dropped host.
|
|
314
|
-
@Test
|
|
315
|
-
fun onHostDropped_detachesChildLayoutListeners() {
|
|
316
|
-
lateinit var host: SRMaskView
|
|
317
|
-
lateinit var child: View
|
|
318
|
-
onMain {
|
|
319
|
-
host = SRMaskView(context)
|
|
320
|
-
child = View(context)
|
|
321
|
-
host.addView(child)
|
|
322
|
-
child.layout(0, 0, 100, 100)
|
|
323
|
-
host.layout(0, 0, 0, 0) // onLayout widens the host to enclose the child
|
|
324
|
-
}
|
|
325
|
-
assertEquals("precondition: host widened to child", 100, host.width)
|
|
326
|
-
|
|
327
|
-
onMain { host.onHostDropped() } // detaches the child's layout listener
|
|
328
|
-
|
|
329
|
-
// Grow the child WITHOUT driving host.onLayout: only a still-attached listener
|
|
330
|
-
// would re-widen the host. It must not, now that the listener is detached.
|
|
331
|
-
onMain { child.layout(0, 0, 500, 500) }
|
|
332
|
-
assertEquals("host must not re-widen after drop (listener detached)", 100, host.width)
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// 6. The host must disable child clipping (iOS parity: SRMaskView.mm sets
|
|
336
|
-
// clipsToBounds=NO). Its Yoga node is display:contents, so the native host is
|
|
337
|
-
// 0x0; with default clipChildren=true the masked subtree would paint
|
|
338
|
-
// invisibly on-screen even though its layout is correct.
|
|
339
|
-
@Test
|
|
340
|
-
fun srMaskViewDisablesChildClipping() {
|
|
341
|
-
lateinit var host: SRMaskView
|
|
342
|
-
onMain { host = SRMaskView(context) }
|
|
343
|
-
assertTrue(
|
|
344
|
-
"SRMaskView must not clip children (else masked content renders invisibly)",
|
|
345
|
-
!host.clipChildren,
|
|
346
|
-
)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// 5. Replay-on-register: masking intent recorded with no primitive is replayed when a
|
|
350
|
-
// primitive later registers.
|
|
351
|
-
@Test
|
|
352
|
-
fun maskIntentBeforeRegistration_isReplayedOnRegister() {
|
|
353
|
-
lateinit var someView: View
|
|
354
|
-
val recording = RecordingPrimitive()
|
|
355
|
-
|
|
356
|
-
onMain {
|
|
357
|
-
someView = View(context)
|
|
358
|
-
// No primitive registered yet (setUp cleared it): intent is only recorded.
|
|
359
|
-
SRMaskingRegistry.setPrimitive(null)
|
|
360
|
-
SRMaskingRegistry.mask(someView, "custom")
|
|
361
|
-
// Register the primitive AFTER the mask intent.
|
|
362
|
-
SRMaskingRegistry.setPrimitive(recording)
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Scope to someView: setPrimitive replays *all* still-live intents (incl.
|
|
366
|
-
// any leaked from earlier tests), so assert on this view specifically.
|
|
367
|
-
val masksForSomeView = recording.maskCalls.filter { it.view === someView }
|
|
368
|
-
assertEquals(
|
|
369
|
-
"registering a primitive should replay exactly one mask intent for the view",
|
|
370
|
-
1,
|
|
371
|
-
masksForSomeView.size,
|
|
372
|
-
)
|
|
373
|
-
assertEquals(
|
|
374
|
-
"replayed mask level should match the recorded intent",
|
|
375
|
-
"custom",
|
|
376
|
-
masksForSomeView.single().level,
|
|
377
|
-
)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// 7. Default primitive mapping (Task 2.6): [SRDefaultMaskingPrimitive] bridges
|
|
381
|
-
// the seam to the Session Replay SDK's tag-based hooks. Each level is
|
|
382
|
-
// compared against a control view driven through the SDK static directly,
|
|
383
|
-
// so the tests don't depend on the SDK's internal tag constants.
|
|
384
|
-
@Test
|
|
385
|
-
fun defaultPrimitive_maskLevelMask_matchesSdkMask() {
|
|
386
|
-
val primitive = SRDefaultMaskingPrimitive()
|
|
387
|
-
lateinit var view: View
|
|
388
|
-
lateinit var control: View
|
|
389
|
-
onMain {
|
|
390
|
-
view = View(context)
|
|
391
|
-
control = View(context)
|
|
392
|
-
primitive.mask(view, "mask")
|
|
393
|
-
SessionReplay.mask(control)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
assertNotNull("SDK mask should set a tag on the control view", control.tag)
|
|
397
|
-
assertEquals("mask(\"mask\") must apply the SDK's mask tag", control.tag, view.tag)
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
@Test
|
|
401
|
-
fun defaultPrimitive_maskLevelBlock_matchesSdkBlock() {
|
|
402
|
-
val primitive = SRDefaultMaskingPrimitive()
|
|
403
|
-
lateinit var view: View
|
|
404
|
-
lateinit var control: View
|
|
405
|
-
onMain {
|
|
406
|
-
view = View(context)
|
|
407
|
-
control = View(context)
|
|
408
|
-
primitive.mask(view, "block")
|
|
409
|
-
SessionReplay.block(control)
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
assertNotNull("SDK block should set a tag on the control view", control.tag)
|
|
413
|
-
assertEquals("mask(\"block\") must apply the SDK's block tag", control.tag, view.tag)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
@Test
|
|
417
|
-
fun defaultPrimitive_unmask_matchesSdkUnmask() {
|
|
418
|
-
val primitive = SRDefaultMaskingPrimitive()
|
|
419
|
-
lateinit var view: View
|
|
420
|
-
lateinit var control: View
|
|
421
|
-
onMain {
|
|
422
|
-
view = View(context)
|
|
423
|
-
control = View(context)
|
|
424
|
-
primitive.unmask(view)
|
|
425
|
-
SessionReplay.unmask(control)
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
assertNotNull("SDK unmask should set a tag on the control view", control.tag)
|
|
429
|
-
assertEquals("unmask must apply the SDK's unmask tag", control.tag, view.tag)
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
@Test
|
|
433
|
-
fun defaultPrimitive_reset_clearsTag() {
|
|
434
|
-
val primitive = SRDefaultMaskingPrimitive()
|
|
435
|
-
lateinit var view: View
|
|
436
|
-
onMain {
|
|
437
|
-
view = View(context)
|
|
438
|
-
primitive.mask(view, "mask")
|
|
439
|
-
}
|
|
440
|
-
assertNotNull("precondition: mask should set a tag", view.tag)
|
|
441
|
-
|
|
442
|
-
onMain { primitive.reset(view) }
|
|
443
|
-
assertNull("reset must clear the SDK tag (return to inherit)", view.tag)
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// 7. Touch transparency: the widened host frame necessarily overlaps
|
|
447
|
-
// unrelated siblings, so the host itself must never be a touch target —
|
|
448
|
-
// RN touch targeting must skip it (BOX_NONE) and only consider children.
|
|
449
|
-
@Test
|
|
450
|
-
fun host_pointerEvents_isBoxNone() {
|
|
451
|
-
lateinit var host: SRMaskView
|
|
452
|
-
onMain { host = SRMaskView(context) }
|
|
453
|
-
assertEquals(
|
|
454
|
-
"SRMaskView host must be BOX_NONE so its widened frame can't swallow input",
|
|
455
|
-
PointerEvents.BOX_NONE,
|
|
456
|
-
host.pointerEvents,
|
|
457
|
-
)
|
|
458
|
-
}
|
|
459
|
-
}
|
package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRDefaultMaskingPrimitive.kt
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
package com.amplitude.sessionreplayreactnative
|
|
2
|
-
|
|
3
|
-
import android.view.View
|
|
4
|
-
import com.amplitude.android.sessionreplay.SessionReplay
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default [SRMaskingPrimitive] bridging the masking seam to the Amplitude
|
|
8
|
-
* Session Replay Android SDK's existing tag-based hooks:
|
|
9
|
-
*
|
|
10
|
-
* - `mask(view, "mask")` -> [SessionReplay.mask]
|
|
11
|
-
* - `mask(view, "block")` -> [SessionReplay.block]
|
|
12
|
-
* - `unmask(view)` -> [SessionReplay.unmask]
|
|
13
|
-
* - `reset(view)` -> `view.tag = null` (the SDK hooks are tag-based;
|
|
14
|
-
* clearing the tag returns the view to "inherit")
|
|
15
|
-
*
|
|
16
|
-
* Registered on the UI thread at SDK init
|
|
17
|
-
* ([SessionReplayReactNativeModule.setup]); registration replays intents
|
|
18
|
-
* recorded before init, so mount-before-init masking still applies.
|
|
19
|
-
*/
|
|
20
|
-
class SRDefaultMaskingPrimitive : SRMaskingPrimitive {
|
|
21
|
-
override fun mask(view: View, level: String) {
|
|
22
|
-
when (level) {
|
|
23
|
-
"block" -> SessionReplay.block(view)
|
|
24
|
-
// Default mask level is "mask"; unknown levels fail safe to masking.
|
|
25
|
-
else -> SessionReplay.mask(view)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override fun unmask(view: View) {
|
|
30
|
-
SessionReplay.unmask(view)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
override fun reset(view: View) {
|
|
34
|
-
view.tag = null
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
package com.amplitude.sessionreplayreactnative
|
|
2
|
-
|
|
3
|
-
import android.view.View
|
|
4
|
-
import java.util.WeakHashMap
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Recorder-agnostic masking primitive. Until a concrete implementation is
|
|
8
|
-
* registered at SDK init, [SRMaskingRegistry] is inert.
|
|
9
|
-
*/
|
|
10
|
-
interface SRMaskingPrimitive {
|
|
11
|
-
fun mask(view: View, level: String)
|
|
12
|
-
fun unmask(view: View)
|
|
13
|
-
|
|
14
|
-
/** Return the view to "inherit" — no longer explicitly masked or unmasked. */
|
|
15
|
-
fun reset(view: View)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Indirection between the Fabric `SRMaskView` and the concrete masking
|
|
20
|
-
* primitive. Records each live view's masking intent and replays it when a
|
|
21
|
-
* primitive registers, so views masked before registration are still applied
|
|
22
|
-
* (without a JS re-render).
|
|
23
|
-
*
|
|
24
|
-
* Single-threaded (main/UI thread) use, so no locking.
|
|
25
|
-
*/
|
|
26
|
-
object SRMaskingRegistry {
|
|
27
|
-
|
|
28
|
-
private sealed interface Intent {
|
|
29
|
-
data class Mask(val level: String) : Intent
|
|
30
|
-
object Unmask : Intent
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@JvmStatic
|
|
34
|
-
var primitive: SRMaskingPrimitive? = null
|
|
35
|
-
private set
|
|
36
|
-
|
|
37
|
-
private var warnedUnregistered = false
|
|
38
|
-
|
|
39
|
-
// Weak keys let views GC naturally without leaking.
|
|
40
|
-
private val intents = WeakHashMap<View, Intent>()
|
|
41
|
-
|
|
42
|
-
@JvmStatic
|
|
43
|
-
fun setPrimitive(value: SRMaskingPrimitive?) {
|
|
44
|
-
primitive = value
|
|
45
|
-
if (value == null) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
for ((view, intent) in intents) {
|
|
49
|
-
when (intent) {
|
|
50
|
-
is Intent.Mask -> value.mask(view, intent.level)
|
|
51
|
-
Intent.Unmask -> value.unmask(view)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@JvmStatic
|
|
57
|
-
fun mask(view: View, level: String) {
|
|
58
|
-
intents[view] = Intent.Mask(level)
|
|
59
|
-
primitive?.mask(view, level) ?: warnUnregisteredOnce()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@JvmStatic
|
|
63
|
-
fun unmask(view: View) {
|
|
64
|
-
intents[view] = Intent.Unmask
|
|
65
|
-
primitive?.unmask(view) ?: warnUnregisteredOnce()
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@JvmStatic
|
|
69
|
-
fun reset(view: View) {
|
|
70
|
-
intents.remove(view)
|
|
71
|
-
primitive?.reset(view) ?: warnUnregisteredOnce()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private fun warnUnregisteredOnce() {
|
|
75
|
-
if (!warnedUnregistered && BuildConfig.DEBUG) {
|
|
76
|
-
warnedUnregistered = true
|
|
77
|
-
android.util.Log.w(
|
|
78
|
-
"SRMaskingRegistry",
|
|
79
|
-
"No masking primitive registered; masking calls are recorded and will " +
|
|
80
|
-
"replay once a primitive registers.",
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|