@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.
Files changed (84) hide show
  1. package/AmplitudeSessionReplayReactNative.podspec +43 -2
  2. package/README.md +125 -0
  3. package/android/build.gradle +145 -5
  4. package/android/src/androidTest/java/com/amplitude/sessionreplayreactnative/SRMaskViewTest.kt +459 -0
  5. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRDefaultMaskingPrimitive.kt +36 -0
  6. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SRMaskingPrimitive.kt +84 -0
  7. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +51 -16
  8. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +41 -0
  9. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +7 -0
  10. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskView.kt +174 -0
  11. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskViewManager.kt +44 -0
  12. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/SRMaskViewPointerEvents.java +36 -0
  13. package/android/src/{main → oldarch}/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +2 -1
  14. package/android/src/oldarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +20 -0
  15. package/cpp/SRMaskViewComponentDescriptor.h +20 -0
  16. package/cpp/SRMaskViewShadowNode.cpp +54 -0
  17. package/cpp/SRMaskViewShadowNode.h +56 -0
  18. package/ios/AMPNativeSessionReplay.mm +20 -0
  19. package/ios/NativeSessionReplay.swift +29 -8
  20. package/ios/SRDefaultMaskingPrimitive.swift +34 -0
  21. package/ios/SRMaskingPrimitive.h +26 -0
  22. package/ios/SRMaskingRegistry.m +105 -0
  23. package/ios/fabric/SRMaskView.h +10 -0
  24. package/ios/fabric/SRMaskView.mm +178 -0
  25. package/lib/commonjs/Mask.types.js +29 -0
  26. package/lib/commonjs/Mask.types.js.map +1 -0
  27. package/lib/commonjs/fabric/MaskFabric.js +92 -0
  28. package/lib/commonjs/fabric/MaskFabric.js.map +1 -0
  29. package/lib/commonjs/index.js +19 -0
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/mask-fallback.js +53 -0
  32. package/lib/commonjs/mask-fallback.js.map +1 -0
  33. package/lib/commonjs/native-module.js +10 -1
  34. package/lib/commonjs/native-module.js.map +1 -1
  35. package/lib/commonjs/paper/MaskPaper.js +27 -0
  36. package/lib/commonjs/paper/MaskPaper.js.map +1 -0
  37. package/lib/commonjs/specs/NativeAmpSessionReplay.js +22 -0
  38. package/lib/commonjs/specs/NativeAmpSessionReplay.js.map +1 -0
  39. package/lib/commonjs/specs/SRMaskViewNativeComponent.js +11 -0
  40. package/lib/commonjs/specs/SRMaskViewNativeComponent.js.map +1 -0
  41. package/lib/commonjs/version.js +1 -1
  42. package/lib/module/Mask.types.js +23 -0
  43. package/lib/module/Mask.types.js.map +1 -0
  44. package/lib/module/fabric/MaskFabric.js +85 -0
  45. package/lib/module/fabric/MaskFabric.js.map +1 -0
  46. package/lib/module/index.js +15 -0
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/mask-fallback.js +45 -0
  49. package/lib/module/mask-fallback.js.map +1 -0
  50. package/lib/module/native-module.js +10 -2
  51. package/lib/module/native-module.js.map +1 -1
  52. package/lib/module/paper/MaskPaper.js +21 -0
  53. package/lib/module/paper/MaskPaper.js.map +1 -0
  54. package/lib/module/specs/NativeAmpSessionReplay.js +18 -0
  55. package/lib/module/specs/NativeAmpSessionReplay.js.map +1 -0
  56. package/lib/module/specs/SRMaskViewNativeComponent.js +5 -0
  57. package/lib/module/specs/SRMaskViewNativeComponent.js.map +1 -0
  58. package/lib/module/version.js +1 -1
  59. package/lib/typescript/Mask.types.d.ts +38 -0
  60. package/lib/typescript/Mask.types.d.ts.map +1 -0
  61. package/lib/typescript/fabric/MaskFabric.d.ts +8 -0
  62. package/lib/typescript/fabric/MaskFabric.d.ts.map +1 -0
  63. package/lib/typescript/index.d.ts +11 -0
  64. package/lib/typescript/index.d.ts.map +1 -1
  65. package/lib/typescript/mask-fallback.d.ts +27 -0
  66. package/lib/typescript/mask-fallback.d.ts.map +1 -0
  67. package/lib/typescript/native-module.d.ts.map +1 -1
  68. package/lib/typescript/paper/MaskPaper.d.ts +10 -0
  69. package/lib/typescript/paper/MaskPaper.d.ts.map +1 -0
  70. package/lib/typescript/specs/NativeAmpSessionReplay.d.ts +15 -0
  71. package/lib/typescript/specs/NativeAmpSessionReplay.d.ts.map +1 -0
  72. package/lib/typescript/specs/SRMaskViewNativeComponent.d.ts +11 -0
  73. package/lib/typescript/specs/SRMaskViewNativeComponent.d.ts.map +1 -0
  74. package/lib/typescript/version.d.ts +1 -1
  75. package/package.json +19 -6
  76. package/src/Mask.types.ts +45 -0
  77. package/src/fabric/MaskFabric.tsx +73 -0
  78. package/src/index.tsx +18 -0
  79. package/src/mask-fallback.tsx +60 -0
  80. package/src/native-module.ts +16 -10
  81. package/src/paper/MaskPaper.tsx +24 -0
  82. package/src/specs/NativeAmpSessionReplay.ts +29 -0
  83. package/src/specs/SRMaskViewNativeComponent.ts +12 -0
  84. package/src/version.ts +1 -1
@@ -7,23 +7,26 @@ import com.amplitude.common.Logger
7
7
  import com.amplitude.common.android.LogcatLogger
8
8
  import com.amplitude.core.ServerZone
9
9
  import com.facebook.react.bridge.ReactApplicationContext
10
- import com.facebook.react.bridge.ReactContextBaseJavaModule
11
10
  import com.facebook.react.bridge.ReactMethod
12
11
  import com.facebook.react.bridge.Promise
12
+ import com.facebook.react.bridge.UiThreadUtil
13
13
  import com.facebook.react.bridge.WritableMap
14
14
  import com.facebook.react.bridge.WritableNativeMap
15
15
  import com.facebook.react.bridge.ReadableMap
16
16
 
17
+ // `@ReactMethod` is required on the legacy architecture and ignored on the new
18
+ // one, so it stays on the overrides below.
17
19
  class SessionReplayReactNativeModule(private val reactContext: ReactApplicationContext) :
18
- ReactContextBaseJavaModule(reactContext) {
20
+ SessionReplayReactNativeSpec(reactContext) {
19
21
  private lateinit var sessionReplay: SessionReplay
22
+ @Volatile private var invalidated = false
20
23
 
21
24
  override fun getName(): String {
22
- return "AMPNativeSessionReplay"
25
+ return NAME
23
26
  }
24
27
 
25
28
  @ReactMethod
26
- fun setup(config: ReadableMap, promise: Promise) {
29
+ override fun setup(config: ReadableMap, promise: Promise) {
27
30
  try {
28
31
  val apiKey = config.getString("apiKey") ?: throw IllegalArgumentException("apiKey is required")
29
32
  val deviceId = config.getString("deviceId")
@@ -77,18 +80,39 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
77
80
  "EU" -> ServerZone.EU
78
81
  else -> ServerZone.US
79
82
  },
80
- autoStart = autoStart,
83
+ // Deferred to the UI-thread block below so primitive registration can
84
+ // be ordered before start(); behaviorally identical to SDK autoStart.
85
+ autoStart = false,
81
86
  privacyConfig = PrivacyConfig(maskLevel = maskLevel),
82
87
  )
83
-
84
- promise.resolve(null)
88
+
89
+ // Register the primitive, start capture, and resolve in ONE UI-thread
90
+ // block: the registry is UI-thread-only, and registration must precede
91
+ // start() on the capture (UI) thread so an early capture frame can't
92
+ // snapshot SRMaskView children before their masking intents apply.
93
+ // Re-registering on repeated setup() calls is harmless.
94
+ UiThreadUtil.runOnUiThread {
95
+ if (invalidated) {
96
+ promise.reject("SETUP_ERROR", "Session Replay module was invalidated before setup completed", null)
97
+ return@runOnUiThread
98
+ }
99
+ try {
100
+ SRMaskingRegistry.setPrimitive(SRDefaultMaskingPrimitive())
101
+ if (autoStart) {
102
+ sessionReplay.start()
103
+ }
104
+ promise.resolve(null)
105
+ } catch (e: Exception) {
106
+ promise.reject("SETUP_ERROR", e.message, e)
107
+ }
108
+ }
85
109
  } catch (e: Exception) {
86
110
  promise.reject("SETUP_ERROR", e.message, e)
87
111
  }
88
112
  }
89
113
 
90
114
  @ReactMethod
91
- fun setSessionId(sessionId: Double, promise: Promise) {
115
+ override fun setSessionId(sessionId: Double, promise: Promise) {
92
116
  try {
93
117
  sessionReplay.setSessionId(sessionId.toLong())
94
118
  promise.resolve(null)
@@ -98,7 +122,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
98
122
  }
99
123
 
100
124
  @ReactMethod
101
- fun setDeviceId(deviceId: String?, promise: Promise) {
125
+ override fun setDeviceId(deviceId: String?, promise: Promise) {
102
126
  try {
103
127
  sessionReplay.setDeviceId(deviceId ?: "")
104
128
  promise.resolve(null)
@@ -108,7 +132,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
108
132
  }
109
133
 
110
134
  @ReactMethod
111
- fun getSessionId(promise: Promise) {
135
+ override fun getSessionId(promise: Promise) {
112
136
  try {
113
137
  promise.resolve(sessionReplay.getSessionId().toDouble())
114
138
  } catch (e: Exception) {
@@ -117,7 +141,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
117
141
  }
118
142
 
119
143
  @ReactMethod
120
- fun getSessionReplayProperties(promise: Promise) {
144
+ override fun getSessionReplayProperties(promise: Promise) {
121
145
  try {
122
146
  val properties: Map<String, Any> = sessionReplay.getSessionReplayProperties()
123
147
  val map: WritableMap = WritableNativeMap()
@@ -141,7 +165,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
141
165
  }
142
166
 
143
167
  @ReactMethod
144
- fun start(promise: Promise) {
168
+ override fun start(promise: Promise) {
145
169
  try {
146
170
  sessionReplay.start()
147
171
  promise.resolve(null)
@@ -151,7 +175,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
151
175
  }
152
176
 
153
177
  @ReactMethod
154
- fun stop(promise: Promise) {
178
+ override fun stop(promise: Promise) {
155
179
  try {
156
180
  sessionReplay.stop()
157
181
  promise.resolve(null)
@@ -161,7 +185,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
161
185
  }
162
186
 
163
187
  @ReactMethod
164
- fun flush(promise: Promise) {
188
+ override fun flush(promise: Promise) {
165
189
  try {
166
190
  sessionReplay.flush()
167
191
  promise.resolve(null)
@@ -176,8 +200,19 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
176
200
  }
177
201
 
178
202
  override fun invalidate() {
179
- if (::sessionReplay.isInitialized) {
180
- sessionReplay.shutdown()
203
+ invalidated = true
204
+ // Serialize teardown with the deferred setup() block: both run on the UI
205
+ // queue, so a mid-setup invalidate can no longer interleave — shutdown
206
+ // always runs either before the block (flag rejects it) or after start()
207
+ // (normal stop).
208
+ UiThreadUtil.runOnUiThread {
209
+ if (::sessionReplay.isInitialized) {
210
+ sessionReplay.shutdown()
211
+ }
181
212
  }
182
213
  }
214
+
215
+ companion object {
216
+ const val NAME = "AMPNativeSessionReplay"
217
+ }
183
218
  }
@@ -0,0 +1,41 @@
1
+ package com.amplitude.sessionreplayreactnative
2
+
3
+ import com.amplitude.sessionreplayreactnative.fabric.SRMaskViewManager
4
+ import com.facebook.react.BaseReactPackage
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.module.model.ReactModuleInfo
8
+ import com.facebook.react.module.model.ReactModuleInfoProvider
9
+ import com.facebook.react.uimanager.ViewManager
10
+
11
+ // BaseReactPackage (RN >= 0.74) registers the module as a TurboModule. It lives in
12
+ // the newarch source set so it is compiled only when the New Architecture is
13
+ // enabled; legacy-arch apps on older RN never reference it.
14
+ class SessionReplayReactNativePackage : BaseReactPackage() {
15
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
16
+ return if (name == SessionReplayReactNativeModule.NAME) {
17
+ SessionReplayReactNativeModule(reactContext)
18
+ } else {
19
+ null
20
+ }
21
+ }
22
+
23
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
24
+ return ReactModuleInfoProvider {
25
+ mapOf(
26
+ SessionReplayReactNativeModule.NAME to ReactModuleInfo(
27
+ SessionReplayReactNativeModule.NAME, // name
28
+ SessionReplayReactNativeModule.NAME, // className
29
+ false, // canOverrideExistingModule
30
+ false, // needsEagerInit
31
+ false, // isCxxModule
32
+ true, // isTurboModule
33
+ ),
34
+ )
35
+ }
36
+ }
37
+
38
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
39
+ return listOf(SessionReplayReactNativeViewManager(), SRMaskViewManager())
40
+ }
41
+ }
@@ -0,0 +1,7 @@
1
+ package com.amplitude.sessionreplayreactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ // Codegen-generated base (from src/specs/NativeAmpSessionReplay.ts); makes the module a TurboModule.
6
+ abstract class SessionReplayReactNativeSpec(reactContext: ReactApplicationContext) :
7
+ NativeAmpSessionReplaySpec(reactContext)
@@ -0,0 +1,174 @@
1
+ package com.amplitude.sessionreplayreactnative.fabric
2
+
3
+ import android.content.Context
4
+ import android.view.View
5
+ import com.amplitude.sessionreplayreactnative.SRMaskingRegistry
6
+ import com.facebook.react.views.view.ReactViewGroup
7
+
8
+ /**
9
+ * Fabric host view for the layout-transparent mask component. Its Yoga node is
10
+ * `display:contents`, so Fabric assigns it a 0x0 native frame; the view
11
+ * compensates in two ways that must not affect the Yoga layout of its children:
12
+ * disabled child clipping (a 0x0 host would otherwise clip children invisible)
13
+ * and [expandBoundsToChildrenUnion], which widens only this host's own frame so
14
+ * the session-replay capture gate (width>0 && height>0) doesn't drop the
15
+ * (mask-tagged) subtree.
16
+ */
17
+ class SRMaskView(context: Context) : ReactViewGroup(context) {
18
+ var enabled: Boolean = true
19
+ private set
20
+ var unmask: Boolean = false
21
+ private set
22
+ var maskLevel: String = "mask"
23
+ private set
24
+
25
+ // Guards recursion: setLeftTopRightBottom() can trigger another onLayout.
26
+ private var expanding = false
27
+
28
+ init {
29
+ clipChildren = false
30
+ clipToPadding = false
31
+ // The widened frame (see expandBoundsToChildrenUnion) necessarily spans
32
+ // from the host's Fabric-assigned origin to the children's far corner, so
33
+ // it overlaps sibling views that have nothing to do with this mask. The
34
+ // host must therefore never participate in touch targeting itself:
35
+ // BOX_NONE makes RN's TouchTargetHelper skip the host (only its children
36
+ // can be targets) and lets misses fall through to views underneath.
37
+ // Children are unaffected. This view is never created from a JS
38
+ // pointerEvents prop, so nothing else writes this field.
39
+ //
40
+ // CROSS-VERSION CONSTRAINT (do not "simplify" to a Kotlin call/assignment
41
+ // or an accessor override): pointerEvents has three incompatible
42
+ // source-level shapes across RN versions and no single Kotlin syntax
43
+ // compiles against all of them — see SRMaskViewPointerEvents.java, which
44
+ // resolves the ever-present bytecode setter instead. Re-asserted in
45
+ // onLayout below so a recycling reset can never be observed by capture
46
+ // or touch.
47
+ SRMaskViewPointerEvents.forceBoxNone(this)
48
+ }
49
+
50
+ // Children can be laid out after the host's own layout pass; re-widen then.
51
+ private val childLayoutChangeListener =
52
+ OnLayoutChangeListener { _, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
53
+ if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
54
+ expandBoundsToChildrenUnion()
55
+ }
56
+ }
57
+
58
+ fun setMaskingProps(enabled: Boolean, unmask: Boolean, maskLevel: String) {
59
+ this.enabled = enabled
60
+ this.unmask = unmask
61
+ this.maskLevel = maskLevel
62
+ reapplyMaskingToAllChildren()
63
+ }
64
+
65
+ override fun addView(child: View, index: Int) {
66
+ super.addView(child, index)
67
+ applyMaskingToChild(child)
68
+ child.addOnLayoutChangeListener(childLayoutChangeListener)
69
+ expandBoundsToChildrenUnion()
70
+ }
71
+
72
+ override fun removeView(view: View) {
73
+ view.removeOnLayoutChangeListener(childLayoutChangeListener)
74
+ SRMaskingRegistry.reset(view)
75
+ super.removeView(view)
76
+ expandBoundsToChildrenUnion()
77
+ }
78
+
79
+ override fun removeViewAt(index: Int) {
80
+ val child = getChildAt(index)
81
+ child?.removeOnLayoutChangeListener(childLayoutChangeListener)
82
+ child?.let { SRMaskingRegistry.reset(it) }
83
+ super.removeViewAt(index)
84
+ expandBoundsToChildrenUnion()
85
+ }
86
+
87
+ // Fabric applies the degenerate 0x0 frame via the final View.layout();
88
+ // onLayout is the hook that runs right after, where we can re-widen it.
89
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
90
+ super.onLayout(changed, left, top, right, bottom)
91
+ // Re-assert touch transparency in case a recycling path reset the field
92
+ // (version-agnostic replacement for an accessor override; see init).
93
+ SRMaskViewPointerEvents.forceBoxNone(this)
94
+ expandBoundsToChildrenUnion()
95
+ }
96
+
97
+ // Widen this host's native frame to enclose its children WITHOUT moving it.
98
+ //
99
+ // Measured coordinate model (SDKRN-33, RN 0.77.2 Fabric, on-device):
100
+ // children are ALWAYS host-relative — a child renders at
101
+ // (host.left + child.left, host.top + child.top), standard Android. The
102
+ // host's Fabric-assigned degenerate frame is (X,Y,X,Y) where (X,Y) is the
103
+ // accumulated origin of any flattened views between the host and its
104
+ // mounted parent: (0,0) for top-level masks (where host-relative and
105
+ // parent-space coincide numerically), non-zero for e.g. an AmpUnmask nested
106
+ // inside an AmpMask through a flattened <View>, a mask inside a list row,
107
+ // or a mask whose child uses negative offsets. Therefore the enclosing
108
+ // extent in parent space is origin + max child extent. The origin must
109
+ // never move (children would shift on screen), so children at negative
110
+ // host-relative coordinates cannot be enclosed; the extents are clamped so
111
+ // the frame is never degenerate or inverted while children exist — the
112
+ // session-replay capture gate (width>0 && height>0) is the whole point of
113
+ // the widening. The widened frame can overlap unrelated siblings, which is
114
+ // why the host is pointer-events BOX_NONE (see init) and must never be a
115
+ // touch target itself.
116
+ private fun expandBoundsToChildrenUnion() {
117
+ if (expanding) return
118
+ if (childCount == 0) return
119
+
120
+ var maxChildRight = 0
121
+ var maxChildBottom = 0
122
+ for (i in 0 until childCount) {
123
+ val c = getChildAt(i) ?: continue
124
+ if (c.right > maxChildRight) maxChildRight = c.right
125
+ if (c.bottom > maxChildBottom) maxChildBottom = c.bottom
126
+ }
127
+
128
+ // Children are host-relative, so parent-space extent = origin + extent.
129
+ // Clamp to a 1px minimum so a child at fully negative coordinates can
130
+ // never produce a zero/inverted frame that the capture gate would drop.
131
+ val newRight = left + maxOf(maxChildRight, 1)
132
+ val newBottom = top + maxOf(maxChildBottom, 1)
133
+
134
+ if (newRight != right || newBottom != bottom) {
135
+ expanding = true
136
+ try {
137
+ setLeftTopRightBottom(left, top, newRight, newBottom)
138
+ } finally {
139
+ expanding = false
140
+ }
141
+ }
142
+ }
143
+
144
+ // Called from SRMaskViewManager.onDropViewInstance. Fabric can drop the host
145
+ // without routing children through removeView*; detach their listeners (which
146
+ // close over — and would keep alive — this host) and reset their masking.
147
+ fun onHostDropped() {
148
+ for (i in 0 until childCount) {
149
+ val child = getChildAt(i) ?: continue
150
+ child.removeOnLayoutChangeListener(childLayoutChangeListener)
151
+ SRMaskingRegistry.reset(child)
152
+ }
153
+ }
154
+
155
+ private fun reapplyMaskingToAllChildren() {
156
+ for (i in 0 until childCount) {
157
+ applyMaskingToChild(getChildAt(i))
158
+ }
159
+ }
160
+
161
+ private fun applyMaskingToChild(child: View) {
162
+ if (!enabled) {
163
+ SRMaskingRegistry.reset(child)
164
+ return
165
+ }
166
+
167
+ if (unmask) {
168
+ SRMaskingRegistry.unmask(child)
169
+ return
170
+ }
171
+
172
+ SRMaskingRegistry.mask(child, maskLevel)
173
+ }
174
+ }
@@ -0,0 +1,44 @@
1
+ package com.amplitude.sessionreplayreactnative.fabric
2
+
3
+ import com.facebook.react.module.annotations.ReactModule
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.ViewGroupManager
6
+ import com.facebook.react.uimanager.ViewManagerDelegate
7
+ import com.facebook.react.viewmanagers.SRMaskViewManagerDelegate
8
+ import com.facebook.react.viewmanagers.SRMaskViewManagerInterface
9
+
10
+ @ReactModule(name = SRMaskViewManager.NAME)
11
+ class SRMaskViewManager :
12
+ ViewGroupManager<SRMaskView>(),
13
+ SRMaskViewManagerInterface<SRMaskView> {
14
+
15
+ private val delegate = SRMaskViewManagerDelegate(this)
16
+
17
+ override fun getDelegate(): ViewManagerDelegate<SRMaskView> = delegate
18
+
19
+ override fun getName(): String = NAME
20
+
21
+ override fun createViewInstance(reactContext: ThemedReactContext): SRMaskView =
22
+ SRMaskView(reactContext)
23
+
24
+ override fun setEnabled(view: SRMaskView, value: Boolean) {
25
+ view.setMaskingProps(value, view.unmask, view.maskLevel)
26
+ }
27
+
28
+ override fun setUnmask(view: SRMaskView, value: Boolean) {
29
+ view.setMaskingProps(view.enabled, value, view.maskLevel)
30
+ }
31
+
32
+ override fun setMaskLevel(view: SRMaskView, value: String?) {
33
+ view.setMaskingProps(view.enabled, view.unmask, value ?: "mask")
34
+ }
35
+
36
+ override fun onDropViewInstance(view: SRMaskView) {
37
+ super.onDropViewInstance(view)
38
+ view.onHostDropped()
39
+ }
40
+
41
+ companion object {
42
+ const val NAME = "SRMaskView"
43
+ }
44
+ }
@@ -0,0 +1,36 @@
1
+ package com.amplitude.sessionreplayreactnative.fabric;
2
+
3
+ import com.facebook.react.uimanager.PointerEvents;
4
+ import com.facebook.react.views.view.ReactViewGroup;
5
+
6
+ /**
7
+ * Java on purpose. {@code pointerEvents} has THREE incompatible source-level
8
+ * shapes across React Native versions, so no single Kotlin syntax compiles
9
+ * against all of them:
10
+ *
11
+ * <ul>
12
+ * <li>&le; ~0.77: Java interface + Java {@code ReactViewGroup} get/set pair
13
+ * (Kotlin property syntax OK, setter call OK)</li>
14
+ * <li>~0.78&ndash;0.80: Kotlin {@code ReactPointerEventsView} declares
15
+ * {@code val pointerEvents} while {@code ReactViewGroup} is still Java —
16
+ * Kotlin resolves assignment against the interface's {@code val} and
17
+ * rejects it ({@code 'val' cannot be reassigned}); only an explicit
18
+ * {@code setPointerEvents(...)} call compiles</li>
19
+ * <li>0.81+: {@code ReactViewGroup} is Kotlin with {@code var pointerEvents} —
20
+ * property syntax OK, but {@code setPointerEvents(...)} is an unresolved
21
+ * reference from Kotlin source</li>
22
+ * </ul>
23
+ *
24
+ * The BYTECODE, however, has a {@code setPointerEvents(PointerEvents)} method
25
+ * in every era (the Java method through 0.80; the Kotlin-var-generated setter
26
+ * from 0.81, verified via javap of react-android AARs). Java source resolves
27
+ * against bytecode, so this shim compiles and works on every supported RN
28
+ * version.
29
+ */
30
+ final class SRMaskViewPointerEvents {
31
+ private SRMaskViewPointerEvents() {}
32
+
33
+ static void forceBoxNone(ReactViewGroup view) {
34
+ view.setPointerEvents(PointerEvents.BOX_NONE);
35
+ }
36
+ }
@@ -5,7 +5,8 @@ import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.uimanager.ViewManager
7
7
 
8
-
8
+ // Plain ReactPackage using only APIs present in every supported RN version, so
9
+ // older legacy-arch apps keep building unchanged (no peerDependencies floor).
9
10
  class SessionReplayReactNativePackage : ReactPackage {
10
11
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
12
  return listOf(SessionReplayReactNativeModule(reactContext))
@@ -0,0 +1,20 @@
1
+ package com.amplitude.sessionreplayreactnative
2
+
3
+ import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReadableMap
7
+
8
+ // Legacy-arch counterpart of the codegen spec: same method signatures so the
9
+ // module's `override`s compile against both bases.
10
+ abstract class SessionReplayReactNativeSpec(reactContext: ReactApplicationContext) :
11
+ ReactContextBaseJavaModule(reactContext) {
12
+ abstract fun setup(config: ReadableMap, promise: Promise)
13
+ abstract fun setSessionId(sessionId: Double, promise: Promise)
14
+ abstract fun setDeviceId(deviceId: String?, promise: Promise)
15
+ abstract fun getSessionId(promise: Promise)
16
+ abstract fun getSessionReplayProperties(promise: Promise)
17
+ abstract fun start(promise: Promise)
18
+ abstract fun stop(promise: Promise)
19
+ abstract fun flush(promise: Promise)
20
+ }
@@ -0,0 +1,20 @@
1
+ #pragma once
2
+
3
+ #include "SRMaskViewShadowNode.h"
4
+
5
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
6
+
7
+ namespace facebook::react {
8
+
9
+ // Replaces the codegen typedef of the same name (patched on Android; iOS binds
10
+ // via +componentDescriptorProvider). Exists only to bind the custom
11
+ // SRMaskViewContentsShadowNode class — no adopt() override; the ShadowNode's
12
+ // own constructors handle the ForceFlattenView unset (see
13
+ // SRMaskViewShadowNode.h).
14
+ class SRMaskViewComponentDescriptor final
15
+ : public ConcreteComponentDescriptor<SRMaskViewContentsShadowNode> {
16
+ public:
17
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
18
+ };
19
+
20
+ } // namespace facebook::react
@@ -0,0 +1,54 @@
1
+ #include "SRMaskViewShadowNode.h"
2
+
3
+ #include <react/renderer/core/ShadowNodeFragment.h>
4
+ #include <react/renderer/core/ShadowNodeTraits.h>
5
+ #include <yoga/Yoga.h>
6
+
7
+ namespace facebook::react {
8
+
9
+ void SRMaskViewContentsShadowNode::initialize() {
10
+ // display:contents comes from the JS style prop and is already in
11
+ // yogaNode_'s style (parsed by RN's own updateYogaProps(), which also set
12
+ // ForceFlattenView). We never write the Yoga style in C++; the only trait
13
+ // customization is keeping the host view mounted (the session-replay SDK
14
+ // needs a real view to tag for masking) while Yoga still lays the children
15
+ // out as if the host didn't exist.
16
+ if (YGNodeStyleGetDisplay(&yogaNode_) != YGDisplayContents) {
17
+ return;
18
+ }
19
+
20
+ traits_.unset(ShadowNodeTraits::Trait::ForceFlattenView);
21
+
22
+ // Workaround for an upstream Yoga display:contents bug present in
23
+ // RN 0.77-0.82 (fixed by facebook/react-native#56422, shipped in 0.86 and
24
+ // backports): because contents nodes are skipped by Yoga's layout
25
+ // traversal, their children are cloned through side channels
26
+ // (cleanupContentsNodesRecursively / layoutAbsoluteDescendants) that call
27
+ // cloneChildrenIfNeeded() on a contents node even when it is clean and
28
+ // belongs to an already-committed (sealed) tree. If this node was cloned
29
+ // without re-adopting its children, that fires the ShadowNode clone
30
+ // callback on the sealed node and SIGABRTs debug builds
31
+ // (Sealable::ensureUnsealed). Defuse the precondition: eagerly take
32
+ // ownership of every Yoga child at construction time (we are unsealed
33
+ // here), so cloneChildrenIfNeeded() on this node is always a no-op later.
34
+ // This mirrors what YogaLayoutableShadowNode::cloneChildInPlace() does
35
+ // lazily during layout, just moved to a legal (unsealed) point in time.
36
+ auto yogaChildren = yogaNode_.getChildren(); // copy: replaceChild mutates
37
+ for (yoga::Node* childYogaNode : yogaChildren) {
38
+ if (childYogaNode->getOwner() == &yogaNode_) {
39
+ continue;
40
+ }
41
+ auto& childShadowNode = *static_cast<YogaLayoutableShadowNode*>(
42
+ childYogaNode->getContext());
43
+ auto clonedChildShadowNode = childShadowNode.clone(
44
+ {ShadowNodeFragment::propsPlaceholder(),
45
+ ShadowNodeFragment::childrenPlaceholder(),
46
+ childShadowNode.getState()});
47
+ // Public replaceChild() performs the same Yoga bookkeeping as RN's
48
+ // private cloneChildInPlace(): swaps the ShadowNode child and re-owns
49
+ // the fresh clone's Yoga node under yogaNode_.
50
+ replaceChild(childShadowNode, clonedChildShadowNode);
51
+ }
52
+ }
53
+
54
+ } // namespace facebook::react
@@ -0,0 +1,56 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/AmpSessionReplaySpec/EventEmitters.h>
4
+ #include <react/renderer/components/AmpSessionReplaySpec/Props.h>
5
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
6
+
7
+ namespace facebook::react {
8
+
9
+ // Named distinctly from codegen's SRMaskViewShadowNode typealias to avoid ODR
10
+ // clashes with generated ShadowNodes.h while reusing the same component name.
11
+ extern const char SRMaskViewComponentName[];
12
+
13
+ // The JS component passes style={display:'contents'}; RN's own
14
+ // updateYogaProps() (run inside the base constructors) parses it into the
15
+ // Yoga style and sets ShadowNodeTraits::ForceFlattenView. We never mutate the
16
+ // Yoga style in C++ — the only customization is unsetting ForceFlattenView
17
+ // after each construction so the Android/iOS host view stays mounted (the
18
+ // session-replay SDK needs a real view to tag for masking) while Yoga still
19
+ // lays the children out as if the host didn't exist.
20
+ //
21
+ // This mirrors the pattern shipped by Expensify react-native-live-markdown
22
+ // (MarkdownTextInputDecoratorShadowNode) and Expo's expo-modules-core
23
+ // (ExpoViewShadowNode's disableForceFlatten): a post-constructor hook invoked
24
+ // from BOTH constructors (create + clone), no ComponentDescriptor::adopt()
25
+ // override, no Yoga style writes.
26
+ class SRMaskViewContentsShadowNode final
27
+ : public ConcreteViewShadowNode<
28
+ SRMaskViewComponentName,
29
+ SRMaskViewProps,
30
+ SRMaskViewEventEmitter> {
31
+ public:
32
+ SRMaskViewContentsShadowNode(
33
+ const ShadowNodeFragment& fragment,
34
+ const ShadowNodeFamily::Shared& family,
35
+ ShadowNodeTraits traits)
36
+ : ConcreteViewShadowNode(fragment, family, traits) {
37
+ initialize();
38
+ }
39
+
40
+ SRMaskViewContentsShadowNode(
41
+ const ShadowNode& sourceShadowNode,
42
+ const ShadowNodeFragment& fragment)
43
+ : ConcreteViewShadowNode(sourceShadowNode, fragment) {
44
+ initialize();
45
+ }
46
+
47
+ private:
48
+ // Runs after the base constructors (and therefore after updateYogaProps(),
49
+ // which re-sets ForceFlattenView on every clone that carries new props).
50
+ // Must be called from every constructor. Besides the trait unset it also
51
+ // eagerly re-owns this node's Yoga children — a workaround for an upstream
52
+ // RN 0.77-0.82 display:contents crash; see the .cpp for details.
53
+ void initialize();
54
+ };
55
+
56
+ } // namespace facebook::react
@@ -19,3 +19,23 @@ RCT_EXTERN_METHOD(start:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseReject
19
19
  RCT_EXTERN_METHOD(stop:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
20
20
 
21
21
  @end
22
+
23
+ #ifdef RCT_NEW_ARCH_ENABLED
24
+ // Bind the Swift module to the codegen TurboModule interface. A named category is
25
+ // required because a Swift class cannot gain protocol conformance via an anonymous
26
+ // class extension.
27
+ #import <AmpSessionReplaySpec/AmpSessionReplaySpec.h>
28
+
29
+ @interface AMPNativeSessionReplay (TurboModule) <RCTTurboModule>
30
+ @end
31
+
32
+ @implementation AMPNativeSessionReplay (TurboModule)
33
+
34
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
35
+ (const facebook::react::ObjCTurboModule::InitParams &)params
36
+ {
37
+ return std::make_shared<facebook::react::NativeAmpSessionReplaySpecJSI>(params);
38
+ }
39
+
40
+ @end
41
+ #endif