@amplitude/session-replay-react-native 0.1.0-beta.2 → 0.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +5 -35
- 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/ios/AmpMaskApplier.h +22 -0
- package/ios/AmpMaskApplier.m +21 -0
- package/ios/NativeSessionReplay.swift +8 -29
- 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 -19
- package/lib/commonjs/index.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/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 +0 -15
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/AmpMaskViewNativeComponent.js +10 -0
- package/lib/module/specs/AmpMaskViewNativeComponent.js.map +1 -0
- 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 +1 -12
- package/lib/typescript/index.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/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/amp-mask-view.tsx +11 -3
- package/src/index.tsx +1 -19
- package/src/specs/AmpMaskViewNativeComponent.ts +17 -0
- 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
|
@@ -3,31 +3,6 @@ require "json"
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
5
|
|
|
6
|
-
# --- RN-floor gate: Fabric SRMaskView (cpp + ios/fabric) needs new-arch + RN >= 0.77 ---
|
|
7
|
-
new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
|
8
|
-
rn_version = nil
|
|
9
|
-
begin
|
|
10
|
-
rn_pkg_path = `node -e "console.log(require.resolve('react-native/package.json'))"`.strip
|
|
11
|
-
rn_version = JSON.parse(File.read(rn_pkg_path))["version"] unless rn_pkg_path.empty?
|
|
12
|
-
rescue StandardError
|
|
13
|
-
rn_version = nil
|
|
14
|
-
end
|
|
15
|
-
srmaskview_version_ge_077 = lambda do |v|
|
|
16
|
-
next false if v.nil?
|
|
17
|
-
parts = v.split('.')
|
|
18
|
-
major = parts[0].to_i
|
|
19
|
-
minor = parts[1].to_i
|
|
20
|
-
major > 0 || (major == 0 && minor >= 77)
|
|
21
|
-
end
|
|
22
|
-
# Only a KNOWN RN below 0.77 disqualifies Fabric. When the version is unresolvable,
|
|
23
|
-
# the Fabric sources must still build: codegen (type:"all") references SRMaskViewCls
|
|
24
|
-
# unconditionally, so omitting them would break linking. (Android gates the same way.)
|
|
25
|
-
rn_known_below_077 = !rn_version.nil? && !srmaskview_version_ge_077.call(rn_version)
|
|
26
|
-
if new_arch_enabled && rn_known_below_077
|
|
27
|
-
raise "[AmplitudeSessionReplayReactNative] The Fabric SRMaskView component requires React Native >= 0.77 with the New Architecture (found #{rn_version})."
|
|
28
|
-
end
|
|
29
|
-
fabric_enabled = new_arch_enabled && !rn_known_below_077
|
|
30
|
-
|
|
31
6
|
Pod::Spec.new do |s|
|
|
32
7
|
s.name = "AmplitudeSessionReplayReactNative"
|
|
33
8
|
s.version = package["version"].split(/[-+]/).first
|
|
@@ -39,15 +14,7 @@ Pod::Spec.new do |s|
|
|
|
39
14
|
s.platforms = { :ios => min_ios_version_supported }
|
|
40
15
|
s.source = { :git => "https://github.com/amplitude/Amplitude-TypeScript.git", :tag => "#{s.version}" }
|
|
41
16
|
|
|
42
|
-
|
|
43
|
-
# Fabric build: include the C++ ShadowNode + the ios/fabric host view.
|
|
44
|
-
s.source_files = "ios/**/*.{h,m,mm,swift}", "cpp/**/*.{h,cpp}"
|
|
45
|
-
s.public_header_files = "ios/SRMaskingPrimitive.h", "ios/NativeSessionReplay-Bridging-Header.h"
|
|
46
|
-
s.private_header_files = "ios/fabric/**/*.h", "cpp/**/*.h"
|
|
47
|
-
else
|
|
48
|
-
# No Fabric: exclude cpp/** and ios/fabric/** (they pull in renderer headers).
|
|
49
|
-
s.source_files = "ios/*.{h,m,mm,swift}"
|
|
50
|
-
end
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
51
18
|
|
|
52
19
|
s.dependency 'AmplitudeSessionReplay', '>=0.11.1'
|
|
53
20
|
s.dependency 'AmplitudeCore', '>=1.4.2'
|
|
@@ -57,14 +24,6 @@ Pod::Spec.new do |s|
|
|
|
57
24
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
58
25
|
if respond_to?(:install_modules_dependencies, true)
|
|
59
26
|
install_modules_dependencies(s)
|
|
60
|
-
if fabric_enabled
|
|
61
|
-
# Fabric shadow-node C++ headers break Clang module dependency scanning.
|
|
62
|
-
existing_xcconfig = s.attributes_hash["pod_target_xcconfig"] || {}
|
|
63
|
-
s.pod_target_xcconfig = existing_xcconfig.merge({
|
|
64
|
-
"DEFINES_MODULE" => "NO",
|
|
65
|
-
"CLANG_ENABLE_EXPLICIT_MODULES" => "NO",
|
|
66
|
-
})
|
|
67
|
-
end
|
|
68
27
|
else
|
|
69
28
|
s.dependency "React-Core"
|
|
70
29
|
|
|
@@ -83,4 +42,4 @@ Pod::Spec.new do |s|
|
|
|
83
42
|
s.dependency "ReactCommon/turbomodule/core"
|
|
84
43
|
end
|
|
85
44
|
end
|
|
86
|
-
end
|
|
45
|
+
end
|
package/README.md
CHANGED
|
@@ -21,19 +21,6 @@ the SDK keeps working on older React Native versions on the legacy architecture.
|
|
|
21
21
|
The TurboModule code path is compiled only when the New Architecture is enabled,
|
|
22
22
|
which itself requires React Native 0.74 or newer.
|
|
23
23
|
|
|
24
|
-
### Fabric-based masking
|
|
25
|
-
|
|
26
|
-
The layout-transparent masking components (`AmpMask` / `AmpUnmask`, see
|
|
27
|
-
[Layout-transparent masking](#layout-transparent-masking-with-ampmask--ampunmask-experimental))
|
|
28
|
-
are built on Fabric.
|
|
29
|
-
|
|
30
|
-
The Fabric/C++ sources compile only on the New Architecture with React Native
|
|
31
|
-
0.77 or newer (they rely on capabilities that exist only in those versions).
|
|
32
|
-
On the legacy architecture, or on the New Architecture with React Native older
|
|
33
|
-
than 0.77, the Fabric sources are excluded. Enabling the New Architecture on
|
|
34
|
-
React Native older than 0.77 fails the build fast with a clear error (an
|
|
35
|
-
"RN-floor gate" enforced in both `android/build.gradle` and the iOS podspec).
|
|
36
|
-
|
|
37
24
|
## Usage
|
|
38
25
|
|
|
39
26
|
### Session Replay React Native Standalone SDK
|
|
@@ -71,7 +58,9 @@ await add(new SessionReplayPlugin(config)).promise;
|
|
|
71
58
|
|
|
72
59
|
## Masking views
|
|
73
60
|
|
|
74
|
-
To
|
|
61
|
+
To mask certain views, add the `AmpMaskView` tag with the mask property `amp-mask` around the section to be masked
|
|
62
|
+
|
|
63
|
+
`<AmpMaskView>` lays out exactly like a plain `<View>` and works on both React Native architectures: on the New Architecture it is a native Fabric component, on the old architecture it uses the classic view managers.
|
|
75
64
|
|
|
76
65
|
```js
|
|
77
66
|
import { AmpMaskView } from '@amplitude/session-replay-react-native';
|
|
@@ -115,105 +104,6 @@ import { AmpMaskView } from '@amplitude/session-replay-react-native';
|
|
|
115
104
|
</AmpMaskView>;
|
|
116
105
|
```
|
|
117
106
|
|
|
118
|
-
## Layout-transparent masking with `AmpMask` / `AmpUnmask` (Experimental)
|
|
119
|
-
|
|
120
|
-
> **@experimental** — this API is new and may change in a future release.
|
|
121
|
-
|
|
122
|
-
`AmpMaskView` wraps its children in an extra native view, which introduces a
|
|
123
|
-
layout boundary: children that depend on their parent for sizing (`flex: 1`,
|
|
124
|
-
percentage heights, `position: 'absolute'`) can shift or collapse to zero.
|
|
125
|
-
`AmpMask` and `AmpUnmask` are layout-transparent replacements: they mark their
|
|
126
|
-
children as masked/unmasked in the replay without affecting layout at all —
|
|
127
|
-
wrapping content in `<AmpMask>` renders pixel-identical to not wrapping it.
|
|
128
|
-
|
|
129
|
-
### Requirements
|
|
130
|
-
|
|
131
|
-
`AmpMask`/`AmpUnmask` require React Native **0.77 or newer** with the
|
|
132
|
-
**New Architecture** enabled (Fabric) **with bridgeless enabled** (the RN
|
|
133
|
-
0.77 default). On Fabric without bridgeless (bridge mode) — as well as on
|
|
134
|
-
the Old Architecture — they are not supported as a layout-transparent path:
|
|
135
|
-
|
|
136
|
-
- On the Old Architecture, in development they throw with a clear error;
|
|
137
|
-
in production they fall back to `AmpMaskView` and log a one-time
|
|
138
|
-
`console.error`.
|
|
139
|
-
- On Fabric without bridgeless (bridge mode), they never throw — they
|
|
140
|
-
always fall back to `AmpMaskView` and log a one-time `console.error`,
|
|
141
|
-
in both development and production (bridge-mode Fabric cannot detect
|
|
142
|
-
`SRMaskView` on iOS).
|
|
143
|
-
- Both fallbacks **ignore `enabled`** — wrapped content stays masked
|
|
144
|
-
regardless (it fails toward privacy). Neither is layout-transparent —
|
|
145
|
-
the `AmpMaskView` layout caveats above apply. Use `AmpMaskView`
|
|
146
|
-
directly outside the bridgeless-Fabric path.
|
|
147
|
-
|
|
148
|
-
### Caveats
|
|
149
|
-
|
|
150
|
-
- `style` is not supported on `<AmpMask>`/`<AmpUnmask>` — they never occupy
|
|
151
|
-
layout, so there is no box to style. Style your children directly instead.
|
|
152
|
-
- `enabled` is only honored on the layout-transparent Fabric path — all
|
|
153
|
-
fallback paths (Old Architecture, Fabric bridge-mode, and the
|
|
154
|
-
build-misconfiguration cases below) ignore it and keep content masked
|
|
155
|
-
regardless (they fail toward privacy).
|
|
156
|
-
- If the New Architecture is active but the native `SRMaskView` component is
|
|
157
|
-
missing — including on Fabric without bridgeless, which cannot detect
|
|
158
|
-
`SRMaskView` on iOS and always falls back — `<AmpMask>`/`<AmpUnmask>` log a
|
|
159
|
-
one-time `console.error` and fall back to `<AmpMaskView>` — content stays
|
|
160
|
-
**masked**, but layout-transparency is lost. Treat that log as a build
|
|
161
|
-
error to fix, not a warning to ignore.
|
|
162
|
-
- On the **New Architecture**, if the package's native code is absent
|
|
163
|
-
entirely (so Session Replay cannot record at all), `<AmpMask>`/`<AmpUnmask>`
|
|
164
|
-
log a one-time `console.error` and render children directly. If instead the
|
|
165
|
-
native module is present but neither masking component is registered (an
|
|
166
|
-
unexpected build error), they throw in development and log a distinct
|
|
167
|
-
one-time `console.error` in production instead of silently passing content
|
|
168
|
-
through. On the **Old Architecture** with the native code absent, rendering
|
|
169
|
-
fails at `requireNativeComponent` like any other native component — there
|
|
170
|
-
is no silent passthrough.
|
|
171
|
-
|
|
172
|
-
### Usage
|
|
173
|
-
|
|
174
|
-
```tsx
|
|
175
|
-
import { AmpMask, AmpUnmask } from '@amplitude/session-replay-react-native';
|
|
176
|
-
|
|
177
|
-
// Mask: children are masked in the replay, layout is unchanged.
|
|
178
|
-
<AmpMask>
|
|
179
|
-
<View style={{ flex: 1 }}>
|
|
180
|
-
<Text>{accountNumber}</Text>
|
|
181
|
-
</View>
|
|
182
|
-
</AmpMask>
|
|
183
|
-
|
|
184
|
-
// Block: fully block the subtree from the replay.
|
|
185
|
-
<AmpMask maskLevel="block">
|
|
186
|
-
<CreditCardForm />
|
|
187
|
-
</AmpMask>
|
|
188
|
-
|
|
189
|
-
// Unmask: opt content back in to the replay.
|
|
190
|
-
<AmpUnmask>
|
|
191
|
-
<Text>Public banner</Text>
|
|
192
|
-
</AmpUnmask>
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
`AmpMask` props:
|
|
196
|
-
|
|
197
|
-
| Prop | Type | Default | Description |
|
|
198
|
-
| --- | --- | --- | --- |
|
|
199
|
-
| `enabled` | `boolean` | `true` | When `false`, children render without masking. |
|
|
200
|
-
| `maskLevel` | `'mask' \| 'block'` | `'mask'` | Masking level applied to the children. On iOS, `mask` and `block` currently behave identically (both fully block). |
|
|
201
|
-
|
|
202
|
-
`AmpUnmask` takes no masking props — it always unmasks its children.
|
|
203
|
-
|
|
204
|
-
### Migrating from `AmpMaskView`
|
|
205
|
-
|
|
206
|
-
| Before | After |
|
|
207
|
-
| --- | --- |
|
|
208
|
-
| `<AmpMaskView mask="amp-mask">` | `<AmpMask>` |
|
|
209
|
-
| `<AmpMaskView mask="amp-block">` | `<AmpMask maskLevel="block">` |
|
|
210
|
-
| `<AmpMaskView mask="amp-unmask">` | `<AmpUnmask>` |
|
|
211
|
-
|
|
212
|
-
`AmpMaskView` remains supported on both architectures. Prefer
|
|
213
|
-
`AmpMask`/`AmpUnmask` on the New Architecture, especially around children that
|
|
214
|
-
are sized by their parent (`flex: 1`, percentage heights, absolute
|
|
215
|
-
positioning).
|
|
216
|
-
|
|
217
107
|
## Tracking Web Views (Beta)
|
|
218
108
|
|
|
219
109
|
Web views are blocked by default and will not be tracked. If you'd like webviews to be tracked, you can manually unmask
|
package/android/build.gradle
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import groovy.json.JsonSlurper
|
|
2
|
-
|
|
3
1
|
def reactNativeArchitectures() {
|
|
4
2
|
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
5
3
|
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
@@ -9,6 +7,16 @@ def isNewArchitectureEnabled() {
|
|
|
9
7
|
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
10
8
|
}
|
|
11
9
|
|
|
10
|
+
// Gradle configures projects alphabetically, so this project sorts before ':app'.
|
|
11
|
+
// If the app doesn't apply RN's 'com.facebook.react.rootproject' plugin, the RN gradle
|
|
12
|
+
// plugin's jvmToolchain(17) sweep reaches this project after AGP has already finalized
|
|
13
|
+
// its Java toolchain, failing with "property 'languageVersion' is final" (issue #1510).
|
|
14
|
+
// Configuring ':app' first (as rootproject would) keeps the sweep ahead of finalization.
|
|
15
|
+
// When the app already applies that plugin, this block is a harmless no-op (both force ':app' first).
|
|
16
|
+
if (findProject(':app') != null) {
|
|
17
|
+
evaluationDependsOn(':app')
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
apply plugin: "com.android.library"
|
|
13
21
|
apply plugin: "kotlin-android"
|
|
14
22
|
|
|
@@ -28,103 +36,9 @@ def supportsNamespace() {
|
|
|
28
36
|
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
29
37
|
def major = parsed[0].toInteger()
|
|
30
38
|
def minor = parsed[1].toInteger()
|
|
31
|
-
return (major == 7 && minor >= 3) || major >= 8
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// --- RN-floor gate: the Fabric SRMaskView codegen/C++ needs RN >= 0.77 under new-arch.
|
|
35
|
-
// Defensive: if RN can't be resolved, do NOT fail (don't break the happy path). ---
|
|
36
|
-
def resolveReactNativeVersion() {
|
|
37
|
-
def candidates = [
|
|
38
|
-
file("${rootProject.projectDir}/../node_modules/react-native/package.json"),
|
|
39
|
-
file("${rootProject.projectDir}/node_modules/react-native/package.json"),
|
|
40
|
-
file("${projectDir}/../../../react-native/package.json"),
|
|
41
|
-
]
|
|
42
|
-
for (c in candidates) {
|
|
43
|
-
if (c.exists()) {
|
|
44
|
-
try { return new JsonSlurper().parse(c).version } catch (ignored) {}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (isNewArchitectureEnabled()) {
|
|
51
|
-
def rnVersion = resolveReactNativeVersion()
|
|
52
|
-
if (rnVersion != null) {
|
|
53
|
-
def p = rnVersion.tokenize('.')
|
|
54
|
-
def major = p[0].toInteger()
|
|
55
|
-
def minor = p[1].toInteger()
|
|
56
|
-
def ge077 = major > 0 || (major == 0 && minor >= 77)
|
|
57
|
-
if (!ge077) {
|
|
58
|
-
throw new GradleException(
|
|
59
|
-
"[SessionReplayReactNative] The Fabric SRMaskView component requires React Native >= 0.77 " +
|
|
60
|
-
"with the New Architecture (found ${rnVersion})."
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
def patchComponentDescriptorsHeader() {
|
|
67
|
-
def componentsDir = file("$buildDir/generated/source/codegen/jni/react/renderer/components/AmpSessionReplaySpec")
|
|
68
|
-
def header = new File(componentsDir, "ComponentDescriptors.h")
|
|
69
|
-
|
|
70
|
-
if (!header.exists()) {
|
|
71
|
-
throw new GradleException(
|
|
72
|
-
"[SessionReplayReactNative] Expected codegen ComponentDescriptors.h at ${header.absolutePath}. " +
|
|
73
|
-
"Ensure newArchEnabled=true and generateCodegenArtifactsFromSchema ran successfully."
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
39
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
def typedefPattern = /using SRMaskViewComponentDescriptor = ConcreteComponentDescriptor<SRMaskViewShadowNode>;/
|
|
83
|
-
if (!(original =~ typedefPattern)) {
|
|
84
|
-
throw new GradleException(
|
|
85
|
-
"[SessionReplayReactNative] patchComponentDescriptorsHeader regex did not match ComponentDescriptors.h. " +
|
|
86
|
-
"React Native codegen output may have changed; update the patch task before shipping."
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
def patched = original.replace(
|
|
91
|
-
"#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>",
|
|
92
|
-
"""#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
|
93
|
-
#include <SRMaskViewComponentDescriptor.h>"""
|
|
94
|
-
).replaceFirst(typedefPattern, "")
|
|
95
|
-
header.write(patched, "UTF-8")
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
def patchCodegenCMakeLists() {
|
|
99
|
-
def cmakeFile = file("$buildDir/generated/source/codegen/jni/CMakeLists.txt")
|
|
100
|
-
|
|
101
|
-
if (!cmakeFile.exists()) {
|
|
102
|
-
throw new GradleException(
|
|
103
|
-
"[SessionReplayReactNative] Expected codegen CMakeLists.txt at ${cmakeFile.absolutePath}. " +
|
|
104
|
-
"Ensure newArchEnabled=true and generateCodegenArtifactsFromSchema ran successfully."
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
def original = cmakeFile.getText("UTF-8")
|
|
109
|
-
if (original.contains("SRMaskViewShadowNode.cpp")) {
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
def cppDir = file("../cpp").absolutePath.replace("\\", "/")
|
|
114
|
-
def insertion = """target_sources(react_codegen_AmpSessionReplaySpec PRIVATE
|
|
115
|
-
"${cppDir}/SRMaskViewShadowNode.cpp"
|
|
116
|
-
)
|
|
117
|
-
target_include_directories(react_codegen_AmpSessionReplaySpec PUBLIC "${cppDir}")
|
|
118
|
-
"""
|
|
119
|
-
|
|
120
|
-
if (!original.contains("target_link_libraries(")) {
|
|
121
|
-
throw new GradleException(
|
|
122
|
-
"[SessionReplayReactNative] patchCodegenCMakeLists could not find target_link_libraries in CMakeLists.txt."
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
def patched = original.replace("target_link_libraries(", insertion + "target_link_libraries(")
|
|
127
|
-
cmakeFile.write(patched, "UTF-8")
|
|
40
|
+
// Namespace support was added in 7.3.0
|
|
41
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
128
42
|
}
|
|
129
43
|
|
|
130
44
|
android {
|
|
@@ -138,8 +52,8 @@ android {
|
|
|
138
52
|
}
|
|
139
53
|
}
|
|
140
54
|
|
|
141
|
-
// New Arch compiles src/newarch (codegen spec + BaseReactPackage
|
|
142
|
-
//
|
|
55
|
+
// New Arch compiles src/newarch (codegen spec + BaseReactPackage); Old Arch
|
|
56
|
+
// compiles src/oldarch (hand-written spec + plain ReactPackage).
|
|
143
57
|
sourceSets {
|
|
144
58
|
main {
|
|
145
59
|
if (isNewArchitectureEnabled()) {
|
|
@@ -155,12 +69,7 @@ android {
|
|
|
155
69
|
defaultConfig {
|
|
156
70
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
157
71
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
158
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
159
|
-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
160
|
-
}
|
|
161
72
|
|
|
162
|
-
buildFeatures {
|
|
163
|
-
buildConfig true
|
|
164
73
|
}
|
|
165
74
|
|
|
166
75
|
buildTypes {
|
|
@@ -169,10 +78,6 @@ android {
|
|
|
169
78
|
}
|
|
170
79
|
}
|
|
171
80
|
|
|
172
|
-
packagingOptions {
|
|
173
|
-
pickFirst "lib/**/*.so"
|
|
174
|
-
}
|
|
175
|
-
|
|
176
81
|
lintOptions {
|
|
177
82
|
disable "GradleCompatible"
|
|
178
83
|
}
|
|
@@ -193,33 +98,20 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
|
193
98
|
dependencies {
|
|
194
99
|
implementation("com.amplitude:session-replay-android:[0.24.0,0.25.0)")
|
|
195
100
|
implementation("com.amplitude:analytics-android:[1.25.0,1.26.0)")
|
|
101
|
+
|
|
102
|
+
// For < 0.71, this will be from the local maven repo
|
|
103
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
196
104
|
//noinspection GradleDynamicVersion
|
|
197
105
|
implementation "com.facebook.react:react-native:+"
|
|
198
106
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
199
|
-
|
|
200
|
-
androidTestImplementation "androidx.test.ext:junit:1.2.1"
|
|
201
|
-
androidTestImplementation "androidx.test:runner:1.6.2"
|
|
202
107
|
}
|
|
203
108
|
|
|
109
|
+
// Codegen for the TurboModule spec (New Architecture only). Generates
|
|
110
|
+
// NativeAmpSessionReplaySpec from src/specs/NativeAmpSessionReplay.ts.
|
|
204
111
|
if (isNewArchitectureEnabled()) {
|
|
205
112
|
react {
|
|
206
113
|
jsRootDir = file("../src/specs/")
|
|
207
114
|
libraryName = "AmpSessionReplaySpec"
|
|
208
115
|
codegenJavaPackageName = "com.amplitude.sessionreplayreactnative"
|
|
209
116
|
}
|
|
210
|
-
|
|
211
|
-
afterEvaluate {
|
|
212
|
-
tasks.named("generateCodegenArtifactsFromSchema").configure {
|
|
213
|
-
doLast {
|
|
214
|
-
patchComponentDescriptorsHeader()
|
|
215
|
-
patchCodegenCMakeLists()
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
tasks.configureEach { task ->
|
|
220
|
-
if (task.name.contains("configureCMake")) {
|
|
221
|
-
task.dependsOn("generateCodegenArtifactsFromSchema")
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
117
|
}
|
|
@@ -9,7 +9,6 @@ import com.amplitude.core.ServerZone
|
|
|
9
9
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
10
|
import com.facebook.react.bridge.ReactMethod
|
|
11
11
|
import com.facebook.react.bridge.Promise
|
|
12
|
-
import com.facebook.react.bridge.UiThreadUtil
|
|
13
12
|
import com.facebook.react.bridge.WritableMap
|
|
14
13
|
import com.facebook.react.bridge.WritableNativeMap
|
|
15
14
|
import com.facebook.react.bridge.ReadableMap
|
|
@@ -19,7 +18,6 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
19
18
|
class SessionReplayReactNativeModule(private val reactContext: ReactApplicationContext) :
|
|
20
19
|
SessionReplayReactNativeSpec(reactContext) {
|
|
21
20
|
private lateinit var sessionReplay: SessionReplay
|
|
22
|
-
@Volatile private var invalidated = false
|
|
23
21
|
|
|
24
22
|
override fun getName(): String {
|
|
25
23
|
return NAME
|
|
@@ -80,32 +78,11 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
|
|
|
80
78
|
"EU" -> ServerZone.EU
|
|
81
79
|
else -> ServerZone.US
|
|
82
80
|
},
|
|
83
|
-
|
|
84
|
-
// be ordered before start(); behaviorally identical to SDK autoStart.
|
|
85
|
-
autoStart = false,
|
|
81
|
+
autoStart = autoStart,
|
|
86
82
|
privacyConfig = PrivacyConfig(maskLevel = maskLevel),
|
|
87
83
|
)
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
}
|
|
84
|
+
|
|
85
|
+
promise.resolve(null)
|
|
109
86
|
} catch (e: Exception) {
|
|
110
87
|
promise.reject("SETUP_ERROR", e.message, e)
|
|
111
88
|
}
|
|
@@ -200,15 +177,8 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
|
|
|
200
177
|
}
|
|
201
178
|
|
|
202
179
|
override fun invalidate() {
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
}
|
|
180
|
+
if (::sessionReplay.isInitialized) {
|
|
181
|
+
sessionReplay.shutdown()
|
|
212
182
|
}
|
|
213
183
|
}
|
|
214
184
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
package com.amplitude.sessionreplayreactnative
|
|
2
2
|
|
|
3
|
-
import com.amplitude.sessionreplayreactnative.fabric.
|
|
3
|
+
import com.amplitude.sessionreplayreactnative.fabric.AmpMaskViewManager
|
|
4
4
|
import com.facebook.react.BaseReactPackage
|
|
5
5
|
import com.facebook.react.bridge.NativeModule
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
@@ -36,6 +36,8 @@ class SessionReplayReactNativePackage : BaseReactPackage() {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
39
|
-
|
|
39
|
+
// Fabric-native AMPMaskComponentView; the legacy Paper manager of the same
|
|
40
|
+
// name is registered only by the oldarch package.
|
|
41
|
+
return listOf(AmpMaskViewManager())
|
|
40
42
|
}
|
|
41
43
|
}
|
package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/fabric/AmpMaskViewManager.kt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package com.amplitude.sessionreplayreactnative.fabric
|
|
2
|
+
|
|
3
|
+
import com.amplitude.android.sessionreplay.SessionReplay
|
|
4
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
5
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
6
|
+
import com.facebook.react.viewmanagers.AMPMaskComponentViewManagerDelegate
|
|
7
|
+
import com.facebook.react.viewmanagers.AMPMaskComponentViewManagerInterface
|
|
8
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
9
|
+
import com.facebook.react.views.view.ReactViewManager
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* New-Architecture manager for `<AmpMaskView>` (native name AMPMaskComponentView).
|
|
13
|
+
* Registered by the newarch [com.amplitude.sessionreplayreactnative.SessionReplayReactNativePackage]
|
|
14
|
+
* in place of the legacy [com.amplitude.sessionreplayreactnative.SessionReplayReactNativeViewManager],
|
|
15
|
+
* which keeps serving old-architecture builds unchanged (oldarch source set).
|
|
16
|
+
*
|
|
17
|
+
* Same base class ([ReactViewManager] — the host view is a bare [ReactViewGroup],
|
|
18
|
+
* a NORMAL layout node) and same self-tagging model as the legacy manager; the
|
|
19
|
+
* codegen [AMPMaskComponentViewManagerDelegate] routes the `mask` prop on Fabric.
|
|
20
|
+
*/
|
|
21
|
+
@ReactModule(name = AmpMaskViewManager.NAME)
|
|
22
|
+
class AmpMaskViewManager :
|
|
23
|
+
ReactViewManager(),
|
|
24
|
+
AMPMaskComponentViewManagerInterface<ReactViewGroup> {
|
|
25
|
+
|
|
26
|
+
private val delegate = AMPMaskComponentViewManagerDelegate(this)
|
|
27
|
+
|
|
28
|
+
override fun getDelegate(): ViewManagerDelegate<ReactViewGroup> = delegate
|
|
29
|
+
|
|
30
|
+
override fun getName(): String = NAME
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Same mask values as the legacy `mask` prop: `amp-mask`/`amp-block` mask or
|
|
34
|
+
* block this subtree, `amp-unmask` exempts it. Unknown values fail safe to
|
|
35
|
+
* masking.
|
|
36
|
+
*/
|
|
37
|
+
override fun setMask(view: ReactViewGroup, value: String?) {
|
|
38
|
+
when (value) {
|
|
39
|
+
"amp-unmask" -> SessionReplay.unmask(view)
|
|
40
|
+
"amp-block" -> SessionReplay.block(view)
|
|
41
|
+
else -> SessionReplay.mask(view)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
companion object {
|
|
46
|
+
const val NAME = "AMPMaskComponentView"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
// Plain-ObjC seam between the Fabric AMPMaskComponentView (ObjC++) and the
|
|
6
|
+
// AmplitudeSessionReplay Swift pod: `@import AmplitudeSessionReplay` is only
|
|
7
|
+
// reliable from ObjC (.m) translation units, so the amp_isBlocked calls live
|
|
8
|
+
// here instead of in the .mm.
|
|
9
|
+
@interface AmpMaskApplier : NSObject
|
|
10
|
+
|
|
11
|
+
// 'amp-unmask' exempts the view; 'amp-mask'/'amp-block'/unknown values fail
|
|
12
|
+
// safe to masking. Same mapping as the legacy AMPMaskComponentViewManager.
|
|
13
|
+
+ (void)applyMask:(NSString *)mask toView:(UIView *)view;
|
|
14
|
+
|
|
15
|
+
// Resets a view about to be recycled to the masked (fail-closed) state, so a
|
|
16
|
+
// reused native instance cannot inherit a previous incarnation's UNMASKED
|
|
17
|
+
// marker and expose content before updateProps re-applies its real mask value.
|
|
18
|
+
+ (void)resetView:(UIView *)view;
|
|
19
|
+
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#import "AmpMaskApplier.h"
|
|
2
|
+
@import AmplitudeSessionReplay;
|
|
3
|
+
|
|
4
|
+
@implementation AmpMaskApplier
|
|
5
|
+
|
|
6
|
+
+ (void)applyMask:(NSString *)mask toView:(UIView *)view
|
|
7
|
+
{
|
|
8
|
+
view.amp_isBlocked = ![mask isEqualToString:@"amp-unmask"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
+ (void)resetView:(UIView *)view
|
|
12
|
+
{
|
|
13
|
+
// Fail closed: amp_isBlocked is a bool with no "inherit/none" state, so a
|
|
14
|
+
// recycled view can only be reset to masked or unmasked. Reset to masked so
|
|
15
|
+
// that if a reused instance is ever captured before updateProps re-applies
|
|
16
|
+
// its real mask value, it errs toward hiding content, never exposing it.
|
|
17
|
+
// Matches applyMask's unknown-value policy and the component's masked default.
|
|
18
|
+
view.amp_isBlocked = true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@end
|
|
@@ -16,7 +16,7 @@ class NativeSessionReplay: NSObject, RCTBridgeModule {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
@objc(setup:resolve:reject:)
|
|
19
|
-
func setup(_ config: NSDictionary, resolve:
|
|
19
|
+
func setup(_ config: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
|
|
20
20
|
guard let apiKey = config["apiKey"] as? String,
|
|
21
21
|
let sessionId = config["sessionId"] as? NSNumber,
|
|
22
22
|
let serverZone = config["serverZone"] as? String,
|
|
@@ -62,25 +62,10 @@ class NativeSessionReplay: NSObject, RCTBridgeModule {
|
|
|
62
62
|
enableRemoteConfig: enableRemoteConfig
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// native-modules queue), and registration must precede start() on the
|
|
68
|
-
// capture (main) thread so an early capture frame can't snapshot
|
|
69
|
-
// SRMaskView children before their masking intents apply.
|
|
70
|
-
// Re-registering on repeated setup() calls is harmless.
|
|
71
|
-
DispatchQueue.main.async {
|
|
72
|
-
// Invalidated (e.g. RN reload) before deferred setup ran — settle
|
|
73
|
-
// the promise so JS init() never hangs.
|
|
74
|
-
guard let sessionReplay = self.sessionReplay else {
|
|
75
|
-
reject("SETUP_ERROR", "Session Replay module was invalidated before setup completed", nil)
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
SRMaskingRegistry.primitive = SRDefaultMaskingPrimitive()
|
|
79
|
-
if (autoStart) {
|
|
80
|
-
sessionReplay.start()
|
|
81
|
-
}
|
|
82
|
-
resolve(nil)
|
|
65
|
+
if (autoStart) {
|
|
66
|
+
sessionReplay.start()
|
|
83
67
|
}
|
|
68
|
+
resolve(nil)
|
|
84
69
|
}
|
|
85
70
|
|
|
86
71
|
@objc(setSessionId:resolve:reject:)
|
|
@@ -142,16 +127,10 @@ class NativeSessionReplay: NSObject, RCTBridgeModule {
|
|
|
142
127
|
|
|
143
128
|
@objc(invalidate)
|
|
144
129
|
func invalidate() {
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
DispatchQueue.main.async {
|
|
150
|
-
print("invalidate")
|
|
151
|
-
// could be nil here
|
|
152
|
-
self.sessionReplay?.stop()
|
|
153
|
-
self.sessionReplay = nil
|
|
154
|
-
}
|
|
130
|
+
print("invalidate")
|
|
131
|
+
// could be nil here
|
|
132
|
+
sessionReplay?.stop()
|
|
133
|
+
sessionReplay = nil
|
|
155
134
|
}
|
|
156
135
|
}
|
|
157
136
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Whole file is guarded: the podspec compiles ios/** unconditionally, and this
|
|
2
|
+
// header must be a no-op on old-architecture installs where the Fabric headers
|
|
3
|
+
// (React/RCTViewComponentView.h) do not exist.
|
|
4
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
|
+
|
|
6
|
+
#import <React/RCTViewComponentView.h>
|
|
7
|
+
#import <UIKit/UIKit.h>
|
|
8
|
+
|
|
9
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
10
|
+
|
|
11
|
+
@interface AMPMaskComponentView : RCTViewComponentView
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
NS_ASSUME_NONNULL_END
|
|
16
|
+
|
|
17
|
+
#endif // RCT_NEW_ARCH_ENABLED
|