@datadog/mobile-react-native-session-replay 2.13.2 → 2.14.0

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.
@@ -137,7 +137,9 @@ android {
137
137
  java.srcDirs += ['src/oldarch/kotlin']
138
138
  }
139
139
 
140
- if (reactNativeMinorVersion >= 80) {
140
+ if (reactNativeMinorVersion >= 83) {
141
+ java.srcDirs += ['src/rn83/kotlin']
142
+ } else if (reactNativeMinorVersion >= 80) {
141
143
  java.srcDirs += ['src/rn80/kotlin']
142
144
  } else if (reactNativeMinorVersion >= 79) {
143
145
  java.srcDirs += ['src/rn79/kotlin']
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+ package com.datadog.reactnative.sessionreplay.extensions
7
+
8
+ import com.facebook.react.uimanager.style.ComputedBorderRadius
9
+ import com.facebook.react.uimanager.style.ComputedBorderRadiusProp
10
+
11
+ internal fun ComputedBorderRadius?.getAverage(): Float {
12
+ val topRightRadius = this
13
+ ?.getAverageForProp(ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_RIGHT_RADIUS) ?: 0f
14
+ val topLeftRadius = this
15
+ ?.getAverageForProp(ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_LEFT_RADIUS) ?: 0f
16
+ val bottomRightRadius = this
17
+ ?.getAverageForProp(ComputedBorderRadiusProp.COMPUTED_BORDER_BOTTOM_RIGHT_RADIUS) ?: 0f
18
+ val bottomLeftRadius = this
19
+ ?.getAverageForProp(ComputedBorderRadiusProp.COMPUTED_BORDER_BOTTOM_LEFT_RADIUS) ?: 0f
20
+ return (topRightRadius + topLeftRadius + bottomRightRadius + bottomLeftRadius) / 4f
21
+ }
22
+
23
+ internal fun ComputedBorderRadius?.getAverageForProp(prop: ComputedBorderRadiusProp): Float {
24
+ val vertical = this?.get(prop)?.vertical ?: 0f
25
+ val horizontal = this?.get(prop)?.vertical ?: 0f
26
+ return (vertical + horizontal) / 2f
27
+ }
@@ -0,0 +1,103 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+ import android.graphics.Canvas
7
+ import android.graphics.Color
8
+ import android.graphics.ColorFilter
9
+ import android.graphics.PixelFormat
10
+ import android.graphics.drawable.Drawable
11
+ import android.graphics.drawable.InsetDrawable
12
+ import android.graphics.drawable.LayerDrawable
13
+ import com.datadog.android.sessionreplay.model.MobileSegment
14
+ import com.datadog.reactnative.sessionreplay.extensions.getAverage
15
+ import com.datadog.reactnative.sessionreplay.utils.DrawableUtils
16
+ import com.datadog.reactnative.sessionreplay.utils.formatAsRgba
17
+ import com.facebook.react.common.annotations.UnstableReactNativeAPI
18
+ import com.facebook.react.uimanager.Spacing
19
+ import com.facebook.react.uimanager.style.ComputedBorderRadius
20
+
21
+ internal class ReactViewBackgroundDrawableUtils : DrawableUtils() {
22
+ /**
23
+ * Used to wrap instances of internal class:
24
+ * com.facebook.react.uimanager.drawable.BackgroundDrawable
25
+ */
26
+ class BackgroundDrawableWrapper(
27
+ val backgroundColor: String,
28
+ val cornerRadius: Float
29
+ ) : Drawable() {
30
+ override fun draw(p0: Canvas) {}
31
+ override fun setAlpha(p0: Int) {}
32
+ override fun setColorFilter(p0: ColorFilter?) {}
33
+ @Suppress("OVERRIDE_DEPRECATION")
34
+ override fun getOpacity(): Int { return PixelFormat.OPAQUE }
35
+ }
36
+
37
+ @OptIn(UnstableReactNativeAPI::class)
38
+ override fun resolveShapeAndBorder(
39
+ drawable: Drawable,
40
+ opacity: Float,
41
+ pixelDensity: Float
42
+ ): Pair<MobileSegment.ShapeStyle?, MobileSegment.ShapeBorder?> {
43
+ if (drawable is BackgroundDrawableWrapper) {
44
+ return MobileSegment.ShapeStyle(
45
+ drawable.backgroundColor,
46
+ opacity,
47
+ drawable.cornerRadius
48
+ ) to null
49
+ }
50
+
51
+ return null to null
52
+ }
53
+
54
+ @OptIn(UnstableReactNativeAPI::class)
55
+ override fun getReactBackgroundFromDrawable(drawable: Drawable?): Drawable? {
56
+ return when(drawable) {
57
+ is InsetDrawable -> getReactBackgroundFromDrawable(drawable.drawable)
58
+ is LayerDrawable -> getDrawableFromLayerDrawable(drawable)
59
+ else -> null
60
+ }
61
+ }
62
+
63
+ @OptIn(UnstableReactNativeAPI::class)
64
+ private fun getDrawableFromLayerDrawable(layerDrawable: LayerDrawable): Drawable? {
65
+ for (layerNumber in 0 until layerDrawable.numberOfLayers) {
66
+ val layer = layerDrawable.getDrawable(layerNumber)
67
+ if (layer != null) {
68
+ if (layer.javaClass.name == "com.facebook.react.uimanager.drawable.BackgroundDrawable") {
69
+ val backgroundColor = getBackgroundColor(layer) ?: Color.TRANSPARENT
70
+ val cornerRadius = getComputedBorderRadius(layer)?.getAverage() ?: 0f
71
+ return BackgroundDrawableWrapper(
72
+ backgroundColor = formatAsRgba(backgroundColor),
73
+ cornerRadius = cornerRadius,
74
+ )
75
+ }
76
+ }
77
+ }
78
+ return null
79
+ }
80
+
81
+ private fun getComputedBorderRadius(
82
+ drawable: Any
83
+ ): ComputedBorderRadius? {
84
+ return reflectionUtils.getDeclaredField(
85
+ drawable,
86
+ COMPUTED_BORDER_RADIUS_FIELD_NAME
87
+ ) as? ComputedBorderRadius
88
+ }
89
+
90
+ private fun getBackgroundColor(
91
+ backgroundDrawable: Any
92
+ ): Int? {
93
+ return reflectionUtils.getDeclaredField(
94
+ backgroundDrawable,
95
+ BACKGROUND_COLOR_FIELD_NAME
96
+ ) as? Int
97
+ }
98
+
99
+ private companion object {
100
+ private const val COMPUTED_BORDER_RADIUS_FIELD_NAME = "computedBorderRadius"
101
+ private const val BACKGROUND_COLOR_FIELD_NAME = "backgroundColor"
102
+ }
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native-session-replay",
3
- "version": "2.13.2",
3
+ "version": "2.14.0",
4
4
  "description": "A client-side React Native module to enable session replay with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -96,5 +96,5 @@
96
96
  "dependencies": {
97
97
  "chokidar": "^4.0.3"
98
98
  },
99
- "gitHead": "c87943251791af901cc49d1444d4a224e3846ac0"
99
+ "gitHead": "5a2b777da2d65922cc423992feee052f5c2b104f"
100
100
  }