@truewatchtech/react-native-session-replay 0.4.1

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 (130) hide show
  1. package/FTSessionReplayReactNative.podspec +50 -0
  2. package/README.md +33 -0
  3. package/android/build.gradle +228 -0
  4. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  6. package/android/gradle.properties +4 -0
  7. package/android/gradlew +185 -0
  8. package/android/gradlew.bat +89 -0
  9. package/android/settings.gradle +1 -0
  10. package/android/src/main/AndroidManifest.xml +4 -0
  11. package/android/src/main/AndroidManifestNew.xml +3 -0
  12. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/FTSessionReplayImpl.java +119 -0
  13. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/NoopTextPropertiesResolver.java +23 -0
  14. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/ReactNativeSessionReplayExtensionSupport.java +57 -0
  15. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/ShadowNodeWrapper.java +84 -0
  16. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/TextPropertiesResolver.java +20 -0
  17. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/extensions/ReactDrawablesExt.java +155 -0
  18. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/DefaultMapper.java +78 -0
  19. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/Pair.java +11 -0
  20. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactEditTextMapper.java +136 -0
  21. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactNativeImageViewMapper.java +117 -0
  22. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactTextMapper.java +57 -0
  23. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactViewGroupMapper.java +22 -0
  24. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactViewModalMapper.java +21 -0
  25. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/resources/ReactDrawableCopier.java +35 -0
  26. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/ColorUtils.java +24 -0
  27. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/DrawableUtils.java +34 -0
  28. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactNativeUtils.java +18 -0
  29. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/ReflectionUtils.java +43 -0
  30. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/FabricTextViewUtils.java +69 -0
  31. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/LegacyTextViewUtils.java +97 -0
  32. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/TextViewUtils.java +184 -0
  33. package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/views/FTPrivacyView.java +113 -0
  34. package/android/src/newarch/java/com/ft/sdk/reactnative/sessionreplay/FTSessionReplayModule.java +20 -0
  35. package/android/src/newarch/java/com/ft/sdk/reactnative/sessionreplay/views/FTPrivacyViewManager.java +87 -0
  36. package/android/src/oldarch/java/com/ft/sdk/reactnative/sessionreplay/FTSessionReplayModule.java +25 -0
  37. package/android/src/oldarch/java/com/ft/sdk/reactnative/sessionreplay/views/FTPrivacyViewManager.java +70 -0
  38. package/android/src/rn69/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +100 -0
  39. package/android/src/rn75/java/com/ft/sdk/reactnative/sessionreplay/extensions/LengthPercentageExt.java +27 -0
  40. package/android/src/rn75/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +116 -0
  41. package/android/src/rn76/java/com/ft/sdk/reactnative/sessionreplay/extensions/LengthPercentageExt.java +38 -0
  42. package/android/src/rn76/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +117 -0
  43. package/android/src/rn79/java/com/ft/sdk/reactnative/sessionreplay/extensions/LengthPercentageExt.java +38 -0
  44. package/android/src/rn79/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +132 -0
  45. package/android/src/rn80/java/com/ft/sdk/reactnative/sessionreplay/extensions/ComputedBorderRadiusExt.java +58 -0
  46. package/android/src/rn80/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +190 -0
  47. package/android/src/rnlegacy/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +120 -0
  48. package/android/src/rnpost74/java/com/ft/sdk/reactnative/sessionreplay/FTSessionReplayPackage.java +58 -0
  49. package/android/src/rnpre74/java/com/ft/sdk/reactnative/sessionreplay/FTSessionReplayPackage.java +30 -0
  50. package/ios/FTPrivacyViewFabric.h +22 -0
  51. package/ios/FTPrivacyViewFabric.mm +84 -0
  52. package/ios/FTPrivacyViewPaper.h +17 -0
  53. package/ios/FTPrivacyViewPaper.mm +85 -0
  54. package/ios/FTRCTFabricWrapper.h +13 -0
  55. package/ios/FTRCTFabricWrapper.mm +113 -0
  56. package/ios/FTRCTTextPropertiesWrapper.h +24 -0
  57. package/ios/FTRCTTextPropertiesWrapper.mm +28 -0
  58. package/ios/FTRCTTextViewRecorder.h +33 -0
  59. package/ios/FTRCTTextViewRecorder.m +172 -0
  60. package/ios/FTReactNativeSessionReplay.h +13 -0
  61. package/ios/FTReactNativeSessionReplay.mm +85 -0
  62. package/ios/FTSessionReplayReactNative.xcodeproj/project.pbxproj +304 -0
  63. package/lib/commonjs/components/SessionReplayView/HideView.js +19 -0
  64. package/lib/commonjs/components/SessionReplayView/HideView.js.map +1 -0
  65. package/lib/commonjs/components/SessionReplayView/MaskAllView.js +25 -0
  66. package/lib/commonjs/components/SessionReplayView/MaskAllView.js.map +1 -0
  67. package/lib/commonjs/components/SessionReplayView/MaskNoneView.js +23 -0
  68. package/lib/commonjs/components/SessionReplayView/MaskNoneView.js.map +1 -0
  69. package/lib/commonjs/components/SessionReplayView/PrivacyView.js +28 -0
  70. package/lib/commonjs/components/SessionReplayView/PrivacyView.js.map +1 -0
  71. package/lib/commonjs/components/SessionReplayView/index.js +29 -0
  72. package/lib/commonjs/components/SessionReplayView/index.js.map +1 -0
  73. package/lib/commonjs/ft_session_replay.js +69 -0
  74. package/lib/commonjs/ft_session_replay.js.map +1 -0
  75. package/lib/commonjs/index.js +50 -0
  76. package/lib/commonjs/index.js.map +1 -0
  77. package/lib/commonjs/specs/FTPrivacyViewNative.js +29 -0
  78. package/lib/commonjs/specs/FTPrivacyViewNative.js.map +1 -0
  79. package/lib/commonjs/specs/FTPrivacyViewNativeComponent.js +10 -0
  80. package/lib/commonjs/specs/FTPrivacyViewNativeComponent.js.map +1 -0
  81. package/lib/commonjs/specs/NativeFTReactNativeSessionReplay.js +10 -0
  82. package/lib/commonjs/specs/NativeFTReactNativeSessionReplay.js.map +1 -0
  83. package/lib/commonjs/types.js +6 -0
  84. package/lib/commonjs/types.js.map +1 -0
  85. package/lib/module/components/SessionReplayView/HideView.js +12 -0
  86. package/lib/module/components/SessionReplayView/HideView.js.map +1 -0
  87. package/lib/module/components/SessionReplayView/MaskAllView.js +18 -0
  88. package/lib/module/components/SessionReplayView/MaskAllView.js.map +1 -0
  89. package/lib/module/components/SessionReplayView/MaskNoneView.js +16 -0
  90. package/lib/module/components/SessionReplayView/MaskNoneView.js.map +1 -0
  91. package/lib/module/components/SessionReplayView/PrivacyView.js +21 -0
  92. package/lib/module/components/SessionReplayView/PrivacyView.js.map +1 -0
  93. package/lib/module/components/SessionReplayView/index.js +23 -0
  94. package/lib/module/components/SessionReplayView/index.js.map +1 -0
  95. package/lib/module/ft_session_replay.js +67 -0
  96. package/lib/module/ft_session_replay.js.map +1 -0
  97. package/lib/module/index.js +4 -0
  98. package/lib/module/index.js.map +1 -0
  99. package/lib/module/specs/FTPrivacyViewNative.js +24 -0
  100. package/lib/module/specs/FTPrivacyViewNative.js.map +1 -0
  101. package/lib/module/specs/FTPrivacyViewNativeComponent.js +3 -0
  102. package/lib/module/specs/FTPrivacyViewNativeComponent.js.map +1 -0
  103. package/lib/module/specs/NativeFTReactNativeSessionReplay.js +5 -0
  104. package/lib/module/specs/NativeFTReactNativeSessionReplay.js.map +1 -0
  105. package/lib/module/types.js +2 -0
  106. package/lib/module/types.js.map +1 -0
  107. package/lib/typescript/components/SessionReplayView/HideView.d.ts +7 -0
  108. package/lib/typescript/components/SessionReplayView/MaskAllView.d.ts +8 -0
  109. package/lib/typescript/components/SessionReplayView/MaskNoneView.d.ts +7 -0
  110. package/lib/typescript/components/SessionReplayView/PrivacyView.d.ts +12 -0
  111. package/lib/typescript/components/SessionReplayView/index.d.ts +22 -0
  112. package/lib/typescript/ft_session_replay.d.ts +61 -0
  113. package/lib/typescript/index.d.ts +3 -0
  114. package/lib/typescript/specs/FTPrivacyViewNative.d.ts +2 -0
  115. package/lib/typescript/specs/FTPrivacyViewNativeComponent.d.ts +10 -0
  116. package/lib/typescript/specs/NativeFTReactNativeSessionReplay.d.ts +11 -0
  117. package/lib/typescript/types.d.ts +8 -0
  118. package/package.json +97 -0
  119. package/scripts/set-ios-rn-version.js +47 -0
  120. package/src/components/SessionReplayView/HideView.tsx +15 -0
  121. package/src/components/SessionReplayView/MaskAllView.tsx +35 -0
  122. package/src/components/SessionReplayView/MaskNoneView.tsx +26 -0
  123. package/src/components/SessionReplayView/PrivacyView.tsx +40 -0
  124. package/src/components/SessionReplayView/index.ts +26 -0
  125. package/src/ft_session_replay.tsx +78 -0
  126. package/src/index.tsx +19 -0
  127. package/src/specs/FTPrivacyViewNative.ts +32 -0
  128. package/src/specs/FTPrivacyViewNativeComponent.ts +14 -0
  129. package/src/specs/NativeFTReactNativeSessionReplay.ts +13 -0
  130. package/src/types.ts +9 -0
@@ -0,0 +1,116 @@
1
+ package com.ft.sdk.reactnative.sessionreplay.utils;
2
+
3
+ import android.graphics.drawable.Drawable;
4
+ import android.graphics.drawable.InsetDrawable;
5
+ import android.graphics.drawable.LayerDrawable;
6
+
7
+ import com.ft.sdk.reactnative.sessionreplay.extensions.LengthPercentageExt;
8
+ import com.ft.sdk.reactnative.sessionreplay.mappers.Pair;
9
+ import com.ft.sdk.reactnative.sessionreplay.utils.ColorUtils;
10
+ import com.facebook.react.common.annotations.UnstableReactNativeAPI;
11
+ import com.facebook.react.uimanager.Spacing;
12
+ import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
13
+ import com.ft.sdk.sessionreplay.model.ShapeBorder;
14
+ import com.ft.sdk.sessionreplay.model.ShapeStyle;
15
+
16
+ public class ReactViewBackgroundDrawableUtils extends DrawableUtils {
17
+ private static final String COLOR_FIELD_NAME = "mColor";
18
+
19
+ private final ReflectionUtils reflectionUtils;
20
+
21
+ public ReactViewBackgroundDrawableUtils() {
22
+ this(new ReflectionUtils());
23
+ }
24
+
25
+ public ReactViewBackgroundDrawableUtils(ReflectionUtils reflectionUtils) {
26
+ this.reflectionUtils = reflectionUtils;
27
+ }
28
+
29
+ @UnstableReactNativeAPI
30
+ @Override
31
+ public Pair<ShapeStyle, ShapeBorder> resolveShapeAndBorder(
32
+ Drawable drawable,
33
+ float opacity,
34
+ float pixelDensity
35
+ ) {
36
+ if (!(drawable instanceof CSSBackgroundDrawable)) {
37
+ return new Pair<>(null, null);
38
+ }
39
+ CSSBackgroundDrawable cssDrawable = (CSSBackgroundDrawable) drawable;
40
+ ShapeBorder borderProps = resolveBorder(cssDrawable, pixelDensity);
41
+ Integer backgroundColor = getBackgroundColor(cssDrawable);
42
+ String colorHexString;
43
+ if (backgroundColor != null) {
44
+ colorHexString = ColorUtils.formatAsRgba(backgroundColor);
45
+ } else {
46
+ return new Pair<>(null, borderProps);
47
+ }
48
+ return new Pair<>(
49
+ new ShapeStyle(
50
+ colorHexString,
51
+ opacity,
52
+ getBorderRadius(cssDrawable)
53
+ ),
54
+ borderProps
55
+ );
56
+ }
57
+
58
+ @UnstableReactNativeAPI
59
+ @Override
60
+ public Drawable getReactBackgroundFromDrawable(Drawable drawable) {
61
+ if (drawable instanceof CSSBackgroundDrawable) {
62
+ return drawable;
63
+ } else if (drawable instanceof InsetDrawable) {
64
+ return getReactBackgroundFromDrawable(((InsetDrawable) drawable).getDrawable());
65
+ } else if (drawable instanceof LayerDrawable) {
66
+ return getDrawableFromLayerDrawable((LayerDrawable) drawable);
67
+ } else {
68
+ return null;
69
+ }
70
+ }
71
+
72
+ @UnstableReactNativeAPI
73
+ private Drawable getDrawableFromLayerDrawable(LayerDrawable layerDrawable) {
74
+ for (int layerNumber = 0; layerNumber < layerDrawable.getNumberOfLayers(); layerNumber++) {
75
+ Drawable layer = layerDrawable.getDrawable(layerNumber);
76
+ if (layer instanceof CSSBackgroundDrawable) {
77
+ return layer;
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+
83
+ @UnstableReactNativeAPI
84
+ private float getBorderRadius(CSSBackgroundDrawable drawable) {
85
+ float width = (float) drawable.getIntrinsicWidth();
86
+ float height = (float) drawable.getIntrinsicHeight();
87
+ if (drawable.getBorderRadius().getUniform() != null) {
88
+ return LengthPercentageExt.getRadius(drawable.getBorderRadius().getUniform(), width, height);
89
+ } else {
90
+ return 0f;
91
+ }
92
+ }
93
+
94
+ @UnstableReactNativeAPI
95
+ private Integer getBackgroundColor(CSSBackgroundDrawable backgroundDrawable) {
96
+ Object value = reflectionUtils.getDeclaredField(
97
+ backgroundDrawable,
98
+ COLOR_FIELD_NAME
99
+ );
100
+ return value instanceof Integer ? (Integer) value : null;
101
+ }
102
+
103
+ @UnstableReactNativeAPI
104
+ private ShapeBorder resolveBorder(
105
+ CSSBackgroundDrawable backgroundDrawable,
106
+ float pixelDensity
107
+ ) {
108
+ long borderWidth = (long) (backgroundDrawable.getFullBorderWidth() / pixelDensity);
109
+ String borderColor = ColorUtils.formatAsRgba(backgroundDrawable.getBorderColor(Spacing.ALL));
110
+ return new ShapeBorder(
111
+ borderColor,
112
+ borderWidth
113
+ );
114
+ }
115
+
116
+ }
@@ -0,0 +1,38 @@
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.ft.sdk.reactnative.sessionreplay.extensions;
7
+
8
+ import com.facebook.react.uimanager.LengthPercentage;
9
+ import com.facebook.react.uimanager.style.CornerRadii;
10
+
11
+ public final class LengthPercentageExt {
12
+
13
+ private LengthPercentageExt() {
14
+ // Utility class, prevent instantiation
15
+ }
16
+
17
+ /**
18
+ * Gets the average radius value from a LengthPercentage, or returns 0f if the LengthPercentage is null.
19
+ * The radius is calculated as the average of horizontal and vertical values.
20
+ *
21
+ * @param lengthPercentage the LengthPercentage to resolve, can be null
22
+ * @param width the width to resolve against
23
+ * @param height the height to resolve against
24
+ * @return the average radius value, or 0f if lengthPercentage is null
25
+ */
26
+ public static float getRadius(LengthPercentage lengthPercentage, float width, float height) {
27
+ if (lengthPercentage == null) {
28
+ return 0f;
29
+ }
30
+
31
+ CornerRadii value = lengthPercentage.resolve(width, height);
32
+ if (value == null) {
33
+ return 0f;
34
+ }
35
+
36
+ return (value.getHorizontal() + value.getVertical()) / 2f;
37
+ }
38
+ }
@@ -0,0 +1,117 @@
1
+ package com.ft.sdk.reactnative.sessionreplay.utils;
2
+
3
+ import android.graphics.drawable.Drawable;
4
+ import android.graphics.drawable.InsetDrawable;
5
+ import android.graphics.drawable.LayerDrawable;
6
+
7
+ import com.ft.sdk.reactnative.sessionreplay.extensions.LengthPercentageExt;
8
+ import com.ft.sdk.reactnative.sessionreplay.mappers.Pair;
9
+ import com.ft.sdk.reactnative.sessionreplay.utils.ColorUtils;
10
+ import com.facebook.react.common.annotations.UnstableReactNativeAPI;
11
+ import com.facebook.react.uimanager.Spacing;
12
+ import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
13
+ import com.ft.sdk.sessionreplay.model.ShapeBorder;
14
+ import com.ft.sdk.sessionreplay.model.ShapeStyle;
15
+
16
+ public class ReactViewBackgroundDrawableUtils extends DrawableUtils {
17
+ private static final String COLOR_FIELD_NAME = "mColor";
18
+
19
+ private final ReflectionUtils reflectionUtils;
20
+
21
+ public ReactViewBackgroundDrawableUtils() {
22
+ this(new ReflectionUtils());
23
+ }
24
+
25
+ public ReactViewBackgroundDrawableUtils(ReflectionUtils reflectionUtils) {
26
+ this.reflectionUtils = reflectionUtils;
27
+ }
28
+
29
+ @UnstableReactNativeAPI
30
+ @Override
31
+ public Pair<ShapeStyle, ShapeBorder> resolveShapeAndBorder(
32
+ Drawable drawable,
33
+ float opacity,
34
+ float pixelDensity
35
+ ) {
36
+ if (!(drawable instanceof CSSBackgroundDrawable)) {
37
+ return new Pair<>(null, null);
38
+ }
39
+ CSSBackgroundDrawable cssDrawable = (CSSBackgroundDrawable) drawable;
40
+ ShapeBorder borderProps = resolveBorder(cssDrawable, pixelDensity);
41
+ Integer backgroundColor = getBackgroundColor(cssDrawable);
42
+ String colorHexString;
43
+ if (backgroundColor != null) {
44
+ colorHexString = ColorUtils.formatAsRgba(backgroundColor);
45
+ } else {
46
+ return new Pair<>(null, borderProps);
47
+ }
48
+ return new Pair<>(
49
+ new ShapeStyle(
50
+ colorHexString,
51
+ opacity,
52
+ getBorderRadius(cssDrawable)
53
+ ),
54
+ borderProps
55
+ );
56
+ }
57
+
58
+ @UnstableReactNativeAPI
59
+ @Override
60
+ public Drawable getReactBackgroundFromDrawable(Drawable drawable) {
61
+ if (drawable instanceof CSSBackgroundDrawable) {
62
+ return drawable;
63
+ } else if (drawable instanceof InsetDrawable) {
64
+ return getReactBackgroundFromDrawable(((InsetDrawable) drawable).getDrawable());
65
+ } else if (drawable instanceof LayerDrawable) {
66
+ return getDrawableFromLayerDrawable((LayerDrawable) drawable);
67
+ } else {
68
+ return null;
69
+ }
70
+ }
71
+
72
+ @UnstableReactNativeAPI
73
+ private Drawable getDrawableFromLayerDrawable(LayerDrawable layerDrawable) {
74
+ for (int layerNumber = 0; layerNumber < layerDrawable.getNumberOfLayers(); layerNumber++) {
75
+ Drawable layer = layerDrawable.getDrawable(layerNumber);
76
+ if (layer instanceof CSSBackgroundDrawable) {
77
+ return layer;
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+
83
+ @UnstableReactNativeAPI
84
+ private float getBorderRadius(CSSBackgroundDrawable drawable) {
85
+ float width = (float) drawable.getIntrinsicWidth();
86
+ float height = (float) drawable.getIntrinsicHeight();
87
+
88
+ if (drawable.getBorderRadius().getUniform() != null) {
89
+ return LengthPercentageExt.getRadius(drawable.getBorderRadius().getUniform(), width, height);
90
+ } else {
91
+ return 0f;
92
+ }
93
+ }
94
+
95
+ @UnstableReactNativeAPI
96
+ private Integer getBackgroundColor(CSSBackgroundDrawable backgroundDrawable) {
97
+ Object value = reflectionUtils.getDeclaredField(
98
+ backgroundDrawable,
99
+ COLOR_FIELD_NAME
100
+ );
101
+ return value instanceof Integer ? (Integer) value : null;
102
+ }
103
+
104
+ @UnstableReactNativeAPI
105
+ private ShapeBorder resolveBorder(
106
+ CSSBackgroundDrawable backgroundDrawable,
107
+ float pixelDensity
108
+ ) {
109
+ long borderWidth = (long) (backgroundDrawable.getFullBorderWidth() / pixelDensity);
110
+ String borderColor = ColorUtils.formatAsRgba(backgroundDrawable.getBorderColor(Spacing.ALL));
111
+ return new ShapeBorder(
112
+ borderColor,
113
+ borderWidth
114
+ );
115
+ }
116
+
117
+ }
@@ -0,0 +1,38 @@
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.ft.sdk.reactnative.sessionreplay.extensions;
7
+
8
+ import com.facebook.react.uimanager.LengthPercentage;
9
+ import com.facebook.react.uimanager.style.CornerRadii;
10
+
11
+ public final class LengthPercentageExt {
12
+
13
+ private LengthPercentageExt() {
14
+ // Utility class, prevent instantiation
15
+ }
16
+
17
+ /**
18
+ * Gets the average radius value from a LengthPercentage, or returns 0f if the LengthPercentage is null.
19
+ * The radius is calculated as the average of horizontal and vertical values.
20
+ *
21
+ * @param lengthPercentage the LengthPercentage to resolve, can be null
22
+ * @param width the width to resolve against
23
+ * @param height the height to resolve against
24
+ * @return the average radius value, or 0f if lengthPercentage is null
25
+ */
26
+ public static float getRadius(LengthPercentage lengthPercentage, float width, float height) {
27
+ if (lengthPercentage == null) {
28
+ return 0f;
29
+ }
30
+
31
+ CornerRadii value = lengthPercentage.resolve(width, height);
32
+ if (value == null) {
33
+ return 0f;
34
+ }
35
+
36
+ return (value.getHorizontal() + value.getVertical()) / 2f;
37
+ }
38
+ }
@@ -0,0 +1,132 @@
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.ft.sdk.reactnative.sessionreplay.utils;
7
+
8
+ import android.graphics.drawable.Drawable;
9
+ import android.graphics.drawable.InsetDrawable;
10
+ import android.graphics.drawable.LayerDrawable;
11
+
12
+ import com.ft.sdk.reactnative.sessionreplay.extensions.LengthPercentageExt;
13
+ import com.ft.sdk.reactnative.sessionreplay.mappers.Pair;
14
+ import com.ft.sdk.reactnative.sessionreplay.utils.ColorUtils;
15
+ import com.facebook.react.common.annotations.UnstableReactNativeAPI;
16
+ import com.facebook.react.uimanager.LengthPercentage;
17
+ import com.facebook.react.uimanager.Spacing;
18
+ import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
19
+ import com.ft.sdk.sessionreplay.model.ShapeBorder;
20
+ import com.ft.sdk.sessionreplay.model.ShapeStyle;
21
+
22
+ public class ReactViewBackgroundDrawableUtils extends DrawableUtils {
23
+ private static final String COLOR_FIELD_NAME = "mColor";
24
+ private static final String UNIFORM_FIELD_NAME = "uniform";
25
+ private final ReflectionUtils reflectionUtils;
26
+
27
+ public ReactViewBackgroundDrawableUtils() {
28
+ this(new ReflectionUtils());
29
+ }
30
+
31
+ public ReactViewBackgroundDrawableUtils(ReflectionUtils reflectionUtils) {
32
+ this.reflectionUtils = reflectionUtils;
33
+ }
34
+
35
+ @UnstableReactNativeAPI
36
+ @Override
37
+ public Pair<ShapeStyle, ShapeBorder> resolveShapeAndBorder(
38
+ Drawable drawable,
39
+ float opacity,
40
+ float pixelDensity
41
+ ) {
42
+ if (!(drawable instanceof CSSBackgroundDrawable)) {
43
+ return new Pair<>(null, null);
44
+ }
45
+ CSSBackgroundDrawable cssDrawable = (CSSBackgroundDrawable) drawable;
46
+ ShapeBorder borderProps = resolveBorder(cssDrawable, pixelDensity);
47
+ Integer backgroundColor = getBackgroundColor(cssDrawable);
48
+ String colorHexString;
49
+ if (backgroundColor != null) {
50
+ colorHexString = ColorUtils.formatAsRgba(backgroundColor);
51
+ } else {
52
+ return new Pair<>(null, borderProps);
53
+ }
54
+ return new Pair<>(
55
+ new ShapeStyle(
56
+ colorHexString,
57
+ opacity,
58
+ getBorderRadius(cssDrawable)
59
+ ),
60
+ borderProps
61
+ );
62
+ }
63
+
64
+ @UnstableReactNativeAPI
65
+ @Override
66
+ public Drawable getReactBackgroundFromDrawable(Drawable drawable) {
67
+ if (drawable instanceof CSSBackgroundDrawable) {
68
+ return drawable;
69
+ } else if (drawable instanceof InsetDrawable) {
70
+ return getReactBackgroundFromDrawable(((InsetDrawable) drawable).getDrawable());
71
+ } else if (drawable instanceof LayerDrawable) {
72
+ return getDrawableFromLayerDrawable((LayerDrawable) drawable);
73
+ } else {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ @UnstableReactNativeAPI
79
+ private Drawable getDrawableFromLayerDrawable(LayerDrawable layerDrawable) {
80
+ for (int layerNumber = 0; layerNumber < layerDrawable.getNumberOfLayers(); layerNumber++) {
81
+ Drawable layer = layerDrawable.getDrawable(layerNumber);
82
+ if (layer instanceof CSSBackgroundDrawable) {
83
+ return layer;
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+
89
+ @UnstableReactNativeAPI
90
+ private float getBorderRadius(CSSBackgroundDrawable drawable) {
91
+ float width = (float) drawable.getIntrinsicWidth();
92
+ float height = (float) drawable.getIntrinsicHeight();
93
+ LengthPercentage uniform = getBorderRadiusUniform(drawable);
94
+ if (uniform != null) {
95
+ return LengthPercentageExt.getRadius(uniform, width, height);
96
+ } else {
97
+ return 0f;
98
+ }
99
+ }
100
+
101
+ @UnstableReactNativeAPI
102
+ private LengthPercentage getBorderRadiusUniform(CSSBackgroundDrawable drawable) {
103
+ Object value = reflectionUtils.getDeclaredField(
104
+ drawable.getBorderRadius(),
105
+ UNIFORM_FIELD_NAME
106
+ );
107
+ return value instanceof LengthPercentage ? (LengthPercentage) value : null;
108
+ }
109
+
110
+ @UnstableReactNativeAPI
111
+ private Integer getBackgroundColor(CSSBackgroundDrawable backgroundDrawable) {
112
+ Object value = reflectionUtils.getDeclaredField(
113
+ backgroundDrawable,
114
+ COLOR_FIELD_NAME
115
+ );
116
+ return value instanceof Integer ? (Integer) value : null;
117
+ }
118
+
119
+ @UnstableReactNativeAPI
120
+ private ShapeBorder resolveBorder(
121
+ CSSBackgroundDrawable backgroundDrawable,
122
+ float pixelDensity
123
+ ) {
124
+ long borderWidth = (long) (backgroundDrawable.getFullBorderWidth() / pixelDensity);
125
+ String borderColor = ColorUtils.formatAsRgba(backgroundDrawable.getBorderColor(Spacing.ALL));
126
+ return new ShapeBorder(
127
+ borderColor,
128
+ borderWidth
129
+ );
130
+ }
131
+
132
+ }
@@ -0,0 +1,58 @@
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.ft.sdk.reactnative.sessionreplay.extensions;
7
+
8
+ import com.facebook.react.uimanager.style.ComputedBorderRadius;
9
+ import com.facebook.react.uimanager.style.ComputedBorderRadiusProp;
10
+ import com.facebook.react.uimanager.style.CornerRadii;
11
+
12
+ public final class ComputedBorderRadiusExt {
13
+
14
+ private ComputedBorderRadiusExt() {
15
+ // Utility class, prevent instantiation
16
+ }
17
+
18
+ /**
19
+ * Gets the average border radius from all four corners of a ComputedBorderRadius.
20
+ *
21
+ * @param computedBorderRadius the ComputedBorderRadius to calculate average from, can be null
22
+ * @return the average border radius value, or 0f if computedBorderRadius is null
23
+ */
24
+ public static float getAverage(ComputedBorderRadius computedBorderRadius) {
25
+ if (computedBorderRadius == null) {
26
+ return 0f;
27
+ }
28
+
29
+ float topRightRadius = getAverageForProp(computedBorderRadius, ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_RIGHT_RADIUS);
30
+ float topLeftRadius = getAverageForProp(computedBorderRadius, ComputedBorderRadiusProp.COMPUTED_BORDER_TOP_LEFT_RADIUS);
31
+ float bottomRightRadius = getAverageForProp(computedBorderRadius, ComputedBorderRadiusProp.COMPUTED_BORDER_BOTTOM_RIGHT_RADIUS);
32
+ float bottomLeftRadius = getAverageForProp(computedBorderRadius, ComputedBorderRadiusProp.COMPUTED_BORDER_BOTTOM_LEFT_RADIUS);
33
+
34
+ return (topRightRadius + topLeftRadius + bottomRightRadius + bottomLeftRadius) / 4f;
35
+ }
36
+
37
+ /**
38
+ * Gets the average border radius for a specific property of ComputedBorderRadius.
39
+ *
40
+ * @param computedBorderRadius the ComputedBorderRadius to get value from, can be null
41
+ * @param prop the ComputedBorderRadiusProp to get the average for
42
+ * @return the average border radius value for the specified property, or 0f if computedBorderRadius is null
43
+ */
44
+ public static float getAverageForProp(ComputedBorderRadius computedBorderRadius, ComputedBorderRadiusProp prop) {
45
+ if (computedBorderRadius == null) {
46
+ return 0f;
47
+ }
48
+
49
+ CornerRadii borderRadius = computedBorderRadius.get(prop);
50
+ if (borderRadius == null) {
51
+ return 0f;
52
+ }
53
+
54
+ float vertical = borderRadius.getVertical();
55
+ float horizontal = borderRadius.getHorizontal();
56
+ return (vertical + horizontal) / 2f;
57
+ }
58
+ }
@@ -0,0 +1,190 @@
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.ft.sdk.reactnative.sessionreplay.utils;
7
+
8
+ import android.graphics.Canvas;
9
+ import android.graphics.Color;
10
+ import android.graphics.ColorFilter;
11
+ import android.graphics.PixelFormat;
12
+ import android.graphics.drawable.Drawable;
13
+ import android.graphics.drawable.InsetDrawable;
14
+ import android.graphics.drawable.LayerDrawable;
15
+
16
+ import com.ft.sdk.reactnative.sessionreplay.extensions.ComputedBorderRadiusExt;
17
+ import com.ft.sdk.reactnative.sessionreplay.mappers.Pair;
18
+ import com.ft.sdk.reactnative.sessionreplay.utils.ColorUtils;
19
+ import com.facebook.react.common.annotations.UnstableReactNativeAPI;
20
+ import com.facebook.react.uimanager.Spacing;
21
+ import com.facebook.react.uimanager.drawable.CSSBackgroundDrawable;
22
+ import com.facebook.react.uimanager.style.ComputedBorderRadius;
23
+ import com.ft.sdk.sessionreplay.model.ShapeBorder;
24
+ import com.ft.sdk.sessionreplay.model.ShapeStyle;
25
+
26
+ public class ReactViewBackgroundDrawableUtils extends DrawableUtils {
27
+ private static final String CSS_BACKGROUND_COLOR_FIELD_NAME = "mColor";
28
+ private static final String CSS_COMPUTED_BORDER_RADIUS_FIELD_NAME = "mComputedBorderRadius";
29
+ private static final String COMPUTED_BORDER_RADIUS_FIELD_NAME = "computedBorderRadius";
30
+ private static final String BACKGROUND_COLOR_FIELD_NAME = "backgroundColor";
31
+ private final ReflectionUtils reflectionUtils;
32
+
33
+
34
+ public ReactViewBackgroundDrawableUtils() {
35
+ this(new ReflectionUtils());
36
+ }
37
+
38
+ public ReactViewBackgroundDrawableUtils(ReflectionUtils reflectionUtils) {
39
+ this.reflectionUtils = reflectionUtils;
40
+ }
41
+
42
+ public static class BackgroundDrawableWrapper extends Drawable {
43
+ public final String backgroundColor;
44
+ public final float cornerRadius;
45
+
46
+ public BackgroundDrawableWrapper(String backgroundColor, float cornerRadius) {
47
+ this.backgroundColor = backgroundColor;
48
+ this.cornerRadius = cornerRadius;
49
+ }
50
+
51
+ @Override
52
+ public void draw(Canvas canvas) {
53
+ }
54
+
55
+ @Override
56
+ public void setAlpha(int alpha) {
57
+ }
58
+
59
+ @Override
60
+ public void setColorFilter(ColorFilter colorFilter) {
61
+ }
62
+
63
+ @Override
64
+ public int getOpacity() {
65
+ return PixelFormat.OPAQUE;
66
+ }
67
+ }
68
+
69
+ @UnstableReactNativeAPI
70
+ @Override
71
+ public Pair<ShapeStyle, ShapeBorder> resolveShapeAndBorder(
72
+ Drawable drawable,
73
+ float opacity,
74
+ float pixelDensity
75
+ ) {
76
+ if (drawable instanceof BackgroundDrawableWrapper) {
77
+ BackgroundDrawableWrapper wrapper = (BackgroundDrawableWrapper) drawable;
78
+ return new Pair<>(
79
+ new ShapeStyle(
80
+ wrapper.backgroundColor,
81
+ opacity,
82
+ wrapper.cornerRadius
83
+ ),
84
+ null
85
+ );
86
+ } else if (drawable instanceof CSSBackgroundDrawable) {
87
+ CSSBackgroundDrawable cssDrawable = (CSSBackgroundDrawable) drawable;
88
+ ShapeBorder borderProps = resolveBorder(cssDrawable, pixelDensity);
89
+ Integer backgroundColor = getCSSBackgroundColor(cssDrawable);
90
+ String colorHexString;
91
+ if (backgroundColor != null) {
92
+ colorHexString = ColorUtils.formatAsRgba(backgroundColor);
93
+ } else {
94
+ return new Pair<>(null, borderProps);
95
+ }
96
+ return new Pair<>(
97
+ new ShapeStyle(
98
+ colorHexString,
99
+ opacity,
100
+ getCSSComputedBorderRadius(cssDrawable) != null ? ComputedBorderRadiusExt.getAverage(getCSSComputedBorderRadius(cssDrawable)) : 0f
101
+ ),
102
+ borderProps
103
+ );
104
+ }
105
+ return new Pair<>(null, null);
106
+ }
107
+
108
+ @UnstableReactNativeAPI
109
+ @Override
110
+ public Drawable getReactBackgroundFromDrawable(Drawable drawable) {
111
+ if (drawable instanceof CSSBackgroundDrawable) {
112
+ return drawable;
113
+ } else if (drawable instanceof InsetDrawable) {
114
+ return getReactBackgroundFromDrawable(((InsetDrawable) drawable).getDrawable());
115
+ } else if (drawable instanceof LayerDrawable) {
116
+ return getDrawableFromLayerDrawable((LayerDrawable) drawable);
117
+ } else {
118
+ return null;
119
+ }
120
+ }
121
+
122
+ @UnstableReactNativeAPI
123
+ private Drawable getDrawableFromLayerDrawable(LayerDrawable layerDrawable) {
124
+ for (int layerNumber = 0; layerNumber < layerDrawable.getNumberOfLayers(); layerNumber++) {
125
+ Drawable layer = layerDrawable.getDrawable(layerNumber);
126
+ if (layer instanceof CSSBackgroundDrawable) {
127
+ return layer;
128
+ } else if (layer != null) {
129
+ if (layer.getClass().getName().equals("com.facebook.react.uimanager.drawable.BackgroundDrawable")) {
130
+ Integer backgroundColor = getBackgroundColor(layer);
131
+ if (backgroundColor == null) backgroundColor = Color.TRANSPARENT;
132
+ ComputedBorderRadius borderRadius = getComputedBorderRadius(layer);
133
+ float cornerRadius = borderRadius != null ? ComputedBorderRadiusExt.getAverage(borderRadius) : 0f;
134
+ return new BackgroundDrawableWrapper(
135
+ ColorUtils.formatAsRgba(backgroundColor),
136
+ cornerRadius
137
+ );
138
+ }
139
+ }
140
+ }
141
+ return null;
142
+ }
143
+
144
+ @UnstableReactNativeAPI
145
+ private ComputedBorderRadius getCSSComputedBorderRadius(CSSBackgroundDrawable drawable) {
146
+ Object value = reflectionUtils.getDeclaredField(
147
+ drawable,
148
+ CSS_COMPUTED_BORDER_RADIUS_FIELD_NAME
149
+ );
150
+ return value instanceof ComputedBorderRadius ? (ComputedBorderRadius) value : null;
151
+ }
152
+
153
+ private ComputedBorderRadius getComputedBorderRadius(Object drawable) {
154
+ Object value = reflectionUtils.getDeclaredField(
155
+ drawable,
156
+ COMPUTED_BORDER_RADIUS_FIELD_NAME
157
+ );
158
+ return value instanceof ComputedBorderRadius ? (ComputedBorderRadius) value : null;
159
+ }
160
+
161
+ @UnstableReactNativeAPI
162
+ private Integer getCSSBackgroundColor(CSSBackgroundDrawable backgroundDrawable) {
163
+ Object value = reflectionUtils.getDeclaredField(
164
+ backgroundDrawable,
165
+ CSS_BACKGROUND_COLOR_FIELD_NAME
166
+ );
167
+ return value instanceof Integer ? (Integer) value : null;
168
+ }
169
+
170
+ private Integer getBackgroundColor(Object backgroundDrawable) {
171
+ Object value = reflectionUtils.getDeclaredField(
172
+ backgroundDrawable,
173
+ BACKGROUND_COLOR_FIELD_NAME
174
+ );
175
+ return value instanceof Integer ? (Integer) value : null;
176
+ }
177
+
178
+ @UnstableReactNativeAPI
179
+ private ShapeBorder resolveBorder(
180
+ CSSBackgroundDrawable backgroundDrawable,
181
+ float pixelDensity
182
+ ) {
183
+ long borderWidth = (long) (backgroundDrawable.getFullBorderWidth() / pixelDensity);
184
+ String borderColor = ColorUtils.formatAsRgba(backgroundDrawable.getBorderColor(Spacing.ALL));
185
+ return new ShapeBorder(
186
+ borderColor,
187
+ borderWidth
188
+ );
189
+ }
190
+ }