@truewatchtech/react-native-mobile 0.3.15-alpha.1 → 0.4.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FTMobileReactNativeSDK.podspec +2 -1
- package/android/build.gradle +21 -3
- package/android/src/main/java/com/ft/sdk/reactnative/FTSessionReplayImpl.java +60 -0
- package/android/src/main/java/com/ft/sdk/reactnative/FTTraceImpl.java +1 -1
- package/android/src/main/java/com/ft/sdk/reactnative/extensions/ReactDrawablesExt.java +155 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/NoopTextPropertiesResolver.java +23 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/ReactNativeSessionReplayExtensionSupport.java +57 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/ShadowNodeWrapper.java +84 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/TextPropertiesResolver.java +20 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/DefaultMapper.java +78 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/Pair.java +11 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactEditTextMapper.java +136 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactNativeImageViewMapper.java +117 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactTextMapper.java +57 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactViewGroupMapper.java +22 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/mappers/ReactViewModalMapper.java +21 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/resources/ReactDrawableCopier.java +35 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/DrawableUtils.java +34 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/ReflectionUtils.java +43 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/FabricTextViewUtils.java +69 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/LegacyTextViewUtils.java +97 -0
- package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/TextViewUtils.java +184 -0
- package/android/src/main/java/com/ft/sdk/reactnative/utils/ColorUtils.java +24 -0
- package/android/src/newarch/java/com/ft/sdk/reactnative/FTSessionReplayModule.java +30 -0
- package/android/src/oldarch/java/com/ft/sdk/reactnative/FTSessionReplayModule.java +25 -0
- package/android/src/rn69/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +100 -0
- package/android/src/rn75/java/com/ft/sdk/reactnative/sessionreplay/extensions/LengthPercentageExt.java +27 -0
- package/android/src/rn75/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +116 -0
- package/android/src/rn76/java/com/ft/sdk/reactnative/sessionreplay/extensions/LengthPercentageExt.java +38 -0
- package/android/src/rn76/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +117 -0
- package/android/src/rn79/java/com/ft/sdk/reactnative/sessionreplay/extensions/LengthPercentageExt.java +38 -0
- package/android/src/rn79/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +132 -0
- package/android/src/rn80/java/com/ft/sdk/reactnative/sessionreplay/extensions/ComputedBorderRadiusExt.java +58 -0
- package/android/src/rn80/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +190 -0
- package/android/src/rnlegacy/java/com/ft/sdk/reactnative/sessionreplay/utils/ReactViewBackgroundDrawableUtils.java +120 -0
- package/android/src/rnpost74/java/com/ft/sdk/reactnative/FTMobilePackage.java +3 -4
- package/android/src/rnpre74/java/com/ft/sdk/reactnative/FTMobilePackage.java +1 -0
- package/ios/FTMobileReactNative.m +3 -2
- package/ios/FTRCTTextViewRecorder.h +33 -0
- package/ios/FTRCTTextViewRecorder.m +120 -0
- package/ios/FTReactNativeLog.m +1 -1
- package/ios/FTReactNativeRUM.h +0 -1
- package/ios/FTReactNativeSessionReplay.h +6 -0
- package/ios/FTReactNativeSessionReplay.mm +44 -0
- package/ios/FTReactNativeTrace.h +0 -2
- package/ios/FTReactNativeTrace.m +0 -2
- package/ios/FtMobileAgent.xcodeproj/project.pbxproj +6 -0
- package/lib/commonjs/ft_logger.js.map +1 -1
- package/lib/commonjs/ft_mobile_agent.js.map +1 -1
- package/lib/commonjs/ft_rum.js.map +1 -1
- package/lib/commonjs/ft_session_replay.js +34 -0
- package/lib/commonjs/ft_session_replay.js.map +1 -0
- package/lib/commonjs/ft_tracing.js.map +1 -1
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/ft_logger.js.map +1 -1
- package/lib/module/ft_mobile_agent.js.map +1 -1
- package/lib/module/ft_rum.js.map +1 -1
- package/lib/module/ft_session_replay.js +29 -0
- package/lib/module/ft_session_replay.js.map +1 -0
- package/lib/module/ft_tracing.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/ft_session_replay.d.ts +27 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/ft_logger.tsx +0 -1
- package/src/ft_mobile_agent.tsx +0 -1
- package/src/ft_rum.tsx +1 -3
- package/src/ft_session_replay.tsx +34 -0
- package/src/ft_tracing.tsx +0 -1
- package/src/index.tsx +3 -1
- package/src/version.ts +1 -1
package/android/src/main/java/com/ft/sdk/reactnative/sessionreplay/utils/text/TextViewUtils.java
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
package com.ft.sdk.reactnative.sessionreplay.utils.text;
|
|
2
|
+
|
|
3
|
+
import android.view.Gravity;
|
|
4
|
+
import android.widget.TextView;
|
|
5
|
+
|
|
6
|
+
import com.ft.sdk.reactnative.BuildConfig;
|
|
7
|
+
import com.ft.sdk.reactnative.sessionreplay.mappers.Pair;
|
|
8
|
+
import com.ft.sdk.reactnative.sessionreplay.utils.DrawableUtils;
|
|
9
|
+
import com.ft.sdk.reactnative.sessionreplay.utils.ReactViewBackgroundDrawableUtils;
|
|
10
|
+
import com.ft.sdk.reactnative.sessionreplay.utils.ReflectionUtils;
|
|
11
|
+
import com.facebook.react.bridge.ReactContext;
|
|
12
|
+
import com.ft.sdk.sessionreplay.model.Alignment;
|
|
13
|
+
import com.ft.sdk.sessionreplay.model.ShapeBorder;
|
|
14
|
+
import com.ft.sdk.sessionreplay.model.ShapeStyle;
|
|
15
|
+
import com.ft.sdk.sessionreplay.model.TextPosition;
|
|
16
|
+
import com.ft.sdk.sessionreplay.model.TextStyle;
|
|
17
|
+
import com.ft.sdk.sessionreplay.model.TextWireframe;
|
|
18
|
+
import com.ft.sdk.sessionreplay.model.Vertical;
|
|
19
|
+
import com.ft.sdk.sessionreplay.model.Wireframe;
|
|
20
|
+
import com.ft.sdk.sessionreplay.recorder.MappingContext;
|
|
21
|
+
import com.ft.sdk.sessionreplay.utils.InternalLogger;
|
|
22
|
+
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.List;
|
|
25
|
+
|
|
26
|
+
public abstract class TextViewUtils {
|
|
27
|
+
protected final ReactContext reactContext;
|
|
28
|
+
protected final DrawableUtils drawableUtils;
|
|
29
|
+
|
|
30
|
+
public TextViewUtils(ReactContext reactContext, DrawableUtils drawableUtils) {
|
|
31
|
+
this.reactContext = reactContext;
|
|
32
|
+
this.drawableUtils = drawableUtils;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public List<Wireframe> mapTextViewToWireframes(
|
|
36
|
+
List<Wireframe> wireframes,
|
|
37
|
+
TextView view,
|
|
38
|
+
MappingContext mappingContext
|
|
39
|
+
) {
|
|
40
|
+
List<Wireframe> result = new ArrayList<>();
|
|
41
|
+
float pixelDensity = mappingContext.getSystemInformation().getScreenDensity();
|
|
42
|
+
for (Wireframe originalWireframe : wireframes) {
|
|
43
|
+
if (!(originalWireframe instanceof TextWireframe)) {
|
|
44
|
+
result.add(originalWireframe);
|
|
45
|
+
} else {
|
|
46
|
+
result.add(addReactNativeProperties(
|
|
47
|
+
(TextWireframe) originalWireframe,
|
|
48
|
+
view,
|
|
49
|
+
pixelDensity
|
|
50
|
+
));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public TextWireframe addReactNativeProperties(
|
|
57
|
+
TextWireframe originalWireframe,
|
|
58
|
+
TextView view,
|
|
59
|
+
float pixelDensity
|
|
60
|
+
) {
|
|
61
|
+
Pair<ShapeStyle, ShapeBorder> shapeAndBorder = resolveShapeStyleAndBorder(view, pixelDensity);
|
|
62
|
+
ShapeStyle shapeStyle = shapeAndBorder != null ? shapeAndBorder.first : originalWireframe.getShapeStyle();
|
|
63
|
+
ShapeBorder border = shapeAndBorder != null ? shapeAndBorder.second : originalWireframe.getBorder();
|
|
64
|
+
|
|
65
|
+
Pair<TextStyle, TextPosition> textStyleAndPosition = resolveTextStyleAndPosition(originalWireframe, view, pixelDensity);
|
|
66
|
+
TextStyle textStyle = textStyleAndPosition != null ? textStyleAndPosition.first : originalWireframe.getTextStyle();
|
|
67
|
+
TextPosition textPosition = textStyleAndPosition != null ? textStyleAndPosition.second : originalWireframe.getTextPosition();
|
|
68
|
+
|
|
69
|
+
// nothing changed, return the original wireframe
|
|
70
|
+
if (shapeStyle == originalWireframe.getShapeStyle()
|
|
71
|
+
&& border == originalWireframe.getBorder()
|
|
72
|
+
&& textStyle == originalWireframe.getTextStyle()
|
|
73
|
+
&& textPosition == originalWireframe.getTextPosition()) {
|
|
74
|
+
return originalWireframe;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return new TextWireframe(
|
|
78
|
+
originalWireframe.getId(),
|
|
79
|
+
originalWireframe.getX(),
|
|
80
|
+
originalWireframe.getY(),
|
|
81
|
+
originalWireframe.getWidth(),
|
|
82
|
+
originalWireframe.getHeight(),
|
|
83
|
+
originalWireframe.getClip(),
|
|
84
|
+
shapeStyle,
|
|
85
|
+
border,
|
|
86
|
+
originalWireframe.getText(),
|
|
87
|
+
textStyle,
|
|
88
|
+
textPosition
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected Pair<TextStyle, TextPosition> resolveTextStyleAndPosition(
|
|
93
|
+
TextWireframe originalWireframe,
|
|
94
|
+
TextView view,
|
|
95
|
+
float pixelDensity
|
|
96
|
+
) {
|
|
97
|
+
if (!reactContext.hasActiveReactInstance()) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
TextStyle textStyle = resolveTextStyle(originalWireframe, pixelDensity, view);
|
|
101
|
+
if (textStyle == null) return null;
|
|
102
|
+
Alignment alignment = resolveTextAlignment(view, originalWireframe);
|
|
103
|
+
TextPosition textPosition = new TextPosition(
|
|
104
|
+
originalWireframe.getTextPosition() != null ? originalWireframe.getTextPosition().getPadding()
|
|
105
|
+
: null, alignment
|
|
106
|
+
);
|
|
107
|
+
return new Pair<>(textStyle, textPosition);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected Pair<ShapeStyle, ShapeBorder> resolveShapeStyleAndBorder(
|
|
111
|
+
TextView view,
|
|
112
|
+
float pixelDensity
|
|
113
|
+
) {
|
|
114
|
+
android.graphics.drawable.Drawable backgroundDrawable = drawableUtils.getReactBackgroundFromDrawable(view.getBackground());
|
|
115
|
+
if (backgroundDrawable == null) return null;
|
|
116
|
+
float opacity = view.getAlpha();
|
|
117
|
+
return drawableUtils.resolveShapeAndBorder(backgroundDrawable, opacity, pixelDensity);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected Alignment resolveTextAlignment(
|
|
121
|
+
TextView view,
|
|
122
|
+
TextWireframe textWireframe
|
|
123
|
+
) {
|
|
124
|
+
int gravity = view.getGravity();
|
|
125
|
+
com.ft.sdk.sessionreplay.model.Horizontal horizontal = textWireframe.getTextPosition() != null && textWireframe.getTextPosition().getAlignment() != null ? textWireframe.getTextPosition().getAlignment().getHorizontal() : null;
|
|
126
|
+
Vertical vertical;
|
|
127
|
+
switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
|
|
128
|
+
case Gravity.TOP:
|
|
129
|
+
vertical = Vertical.TOP;
|
|
130
|
+
break;
|
|
131
|
+
case Gravity.CENTER_VERTICAL:
|
|
132
|
+
case Gravity.CENTER:
|
|
133
|
+
vertical = Vertical.CENTER;
|
|
134
|
+
break;
|
|
135
|
+
case Gravity.BOTTOM:
|
|
136
|
+
vertical = Vertical.BOTTOM;
|
|
137
|
+
break;
|
|
138
|
+
default:
|
|
139
|
+
vertical = Vertical.TOP;
|
|
140
|
+
}
|
|
141
|
+
return new Alignment(horizontal, vertical);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
protected String resolveFontFamily(String typefaceName) {
|
|
145
|
+
switch (typefaceName) {
|
|
146
|
+
case ROBOTO_TYPEFACE_NAME:
|
|
147
|
+
return SANS_SERIF_FAMILY_NAME;
|
|
148
|
+
case MONOSPACE_FAMILY_NAME:
|
|
149
|
+
return MONOSPACE_FAMILY_NAME;
|
|
150
|
+
case SERIF_FAMILY_NAME:
|
|
151
|
+
return SERIF_FAMILY_NAME;
|
|
152
|
+
default:
|
|
153
|
+
return SANS_SERIF_FAMILY_NAME;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
protected abstract TextStyle resolveTextStyle(
|
|
158
|
+
TextWireframe textWireframe,
|
|
159
|
+
float pixelsDensity,
|
|
160
|
+
TextView view
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
public static final String TEXT_ATTRIBUTES_FIELD_NAME = "mTextAttributes";
|
|
164
|
+
public static final String FONT_FAMILY_FIELD_NAME = "mFontFamily";
|
|
165
|
+
public static final String COLOR_FIELD_NAME = "mColor";
|
|
166
|
+
public static final String IS_COLOR_SET_FIELD_NAME = "mIsColorSet";
|
|
167
|
+
public static final String SPANNED_FIELD_NAME = "mSpanned";
|
|
168
|
+
private static final String ROBOTO_TYPEFACE_NAME = "roboto";
|
|
169
|
+
private static final String SERIF_FAMILY_NAME = "serif";
|
|
170
|
+
private static final String SANS_SERIF_FAMILY_NAME = "roboto, sans-serif";
|
|
171
|
+
public static final String MONOSPACE_FAMILY_NAME = "monospace";
|
|
172
|
+
public static final String RESOLVE_UIMANAGERMODULE_ERROR = "Unable to resolve UIManagerModule";
|
|
173
|
+
public static final String RESOLVE_FABRICFIELD_ERROR = "Unable to resolve field from fabric view";
|
|
174
|
+
public static final String NULL_FABRICFIELD_ERROR = "Null value found when trying to resolve field from fabric view";
|
|
175
|
+
|
|
176
|
+
public static TextViewUtils create(ReactContext reactContext, InternalLogger logger) {
|
|
177
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
178
|
+
return new FabricTextViewUtils(reactContext, logger, new ReactViewBackgroundDrawableUtils());
|
|
179
|
+
} else {
|
|
180
|
+
return new LegacyTextViewUtils(reactContext, logger, new ReflectionUtils(), new ReactViewBackgroundDrawableUtils());
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
|
|
7
|
+
package com.ft.sdk.reactnative.utils;
|
|
8
|
+
|
|
9
|
+
public class ColorUtils {
|
|
10
|
+
private static final int HEX_COLOR_INCLUDING_ALPHA_LENGTH = 8;
|
|
11
|
+
|
|
12
|
+
public static String formatAsRgba(int backgroundColor) {
|
|
13
|
+
String colorHexString = Integer.toHexString(backgroundColor);
|
|
14
|
+
return "#" + convertArgbToRgba(colorHexString);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
private static String convertArgbToRgba(String hexString) {
|
|
18
|
+
if (hexString.length() == HEX_COLOR_INCLUDING_ALPHA_LENGTH) {
|
|
19
|
+
return hexString.substring(2, 8) + hexString.substring(0, 2);
|
|
20
|
+
} else {
|
|
21
|
+
return hexString;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package com.ft.sdk.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
8
|
+
import com.facebook.react.bridge.Promise;
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
10
|
+
|
|
11
|
+
@ReactModule(name = FTSessionReplayModule.NAME)
|
|
12
|
+
public class FTSessionReplayModule extends NativeFTSessionReplaySpec {
|
|
13
|
+
public static final String NAME = FTSessionReplayImpl.NAME;
|
|
14
|
+
private final FTSessionReplayImpl impl = new FTSessionReplayImpl();
|
|
15
|
+
|
|
16
|
+
public FTSessionReplayModule(ReactApplicationContext reactContext) {
|
|
17
|
+
super(reactContext);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Override
|
|
21
|
+
public String getName() {
|
|
22
|
+
return NAME;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
@ReactMethod
|
|
27
|
+
public void sessionReplayConfig(ReadableMap context, Promise promise) {
|
|
28
|
+
impl.sessionReplayConfig(context, promise, getReactApplicationContext());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.ft.sdk.reactnative;
|
|
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.ReactMethod;
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
8
|
+
|
|
9
|
+
public class FTSessionReplayModule extends ReactContextBaseJavaModule {
|
|
10
|
+
private final FTSessionReplayImpl impl = new FTSessionReplayImpl();
|
|
11
|
+
|
|
12
|
+
public FTSessionReplayModule(ReactApplicationContext reactContext) {
|
|
13
|
+
super(reactContext);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
public String getName() {
|
|
18
|
+
return FTSessionReplayImpl.NAME;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@ReactMethod
|
|
22
|
+
public void sessionReplayConfig(ReadableMap context, Promise promise) {
|
|
23
|
+
impl.sessionReplayConfig(context, promise, getReactApplicationContext());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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.mappers.Pair;
|
|
13
|
+
import com.ft.sdk.reactnative.utils.ColorUtils;
|
|
14
|
+
import com.facebook.react.uimanager.Spacing;
|
|
15
|
+
import com.facebook.react.views.view.ReactViewBackgroundDrawable;
|
|
16
|
+
import com.ft.sdk.sessionreplay.model.ShapeBorder;
|
|
17
|
+
import com.ft.sdk.sessionreplay.model.ShapeStyle;
|
|
18
|
+
|
|
19
|
+
public class ReactViewBackgroundDrawableUtils extends DrawableUtils {
|
|
20
|
+
|
|
21
|
+
private static final String COLOR_FIELD_NAME = "mColor";
|
|
22
|
+
|
|
23
|
+
public ReactViewBackgroundDrawableUtils() {
|
|
24
|
+
super();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public Pair<ShapeStyle, ShapeBorder> resolveShapeAndBorder(
|
|
29
|
+
Drawable drawable,
|
|
30
|
+
float opacity,
|
|
31
|
+
float pixelDensity) {
|
|
32
|
+
if (!(drawable instanceof ReactViewBackgroundDrawable)) {
|
|
33
|
+
return new Pair<>(null, null);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ReactViewBackgroundDrawable backgroundDrawable = (ReactViewBackgroundDrawable) drawable;
|
|
37
|
+
ShapeBorder borderProps = resolveBorder(backgroundDrawable, pixelDensity);
|
|
38
|
+
long cornerRadius = (long) (backgroundDrawable.getFullBorderWidth() / pixelDensity);
|
|
39
|
+
|
|
40
|
+
Integer backgroundColor = getBackgroundColor(backgroundDrawable);
|
|
41
|
+
String colorHexString = null;
|
|
42
|
+
if (backgroundColor != null) {
|
|
43
|
+
colorHexString = ColorUtils.formatAsRgba(backgroundColor);
|
|
44
|
+
} else {
|
|
45
|
+
return new Pair<>(null, borderProps);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
ShapeStyle shapeStyle = new ShapeStyle(
|
|
49
|
+
colorHexString,
|
|
50
|
+
opacity,
|
|
51
|
+
cornerRadius
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return new Pair<>(shapeStyle, borderProps);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
public Drawable getReactBackgroundFromDrawable(Drawable drawable) {
|
|
59
|
+
if (drawable instanceof ReactViewBackgroundDrawable) {
|
|
60
|
+
return drawable;
|
|
61
|
+
} else if (drawable instanceof InsetDrawable) {
|
|
62
|
+
return getReactBackgroundFromDrawable(((InsetDrawable) drawable).getDrawable());
|
|
63
|
+
} else if (drawable instanceof LayerDrawable) {
|
|
64
|
+
return getDrawableFromLayerDrawable((LayerDrawable) drawable);
|
|
65
|
+
} else {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private Drawable getDrawableFromLayerDrawable(LayerDrawable layerDrawable) {
|
|
71
|
+
for (int layerNumber = 0; layerNumber < layerDrawable.getNumberOfLayers(); layerNumber++) {
|
|
72
|
+
Drawable layer = layerDrawable.getDrawable(layerNumber);
|
|
73
|
+
if (layer instanceof ReactViewBackgroundDrawable) {
|
|
74
|
+
return layer;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private ShapeBorder resolveBorder(
|
|
81
|
+
ReactViewBackgroundDrawable backgroundDrawable,
|
|
82
|
+
float pixelDensity) {
|
|
83
|
+
long borderWidth = (long) (backgroundDrawable.getFullBorderWidth() / pixelDensity);
|
|
84
|
+
String borderColor = ColorUtils.formatAsRgba(backgroundDrawable.getBorderColor(Spacing.ALL));
|
|
85
|
+
|
|
86
|
+
return new ShapeBorder(
|
|
87
|
+
borderColor,
|
|
88
|
+
borderWidth
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private Integer getBackgroundColor(ReactViewBackgroundDrawable backgroundDrawable) {
|
|
93
|
+
Object result = reflectionUtils.getDeclaredField(backgroundDrawable, COLOR_FIELD_NAME);
|
|
94
|
+
if (result instanceof Integer) {
|
|
95
|
+
return (Integer) result;
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
@@ -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.ft.sdk.reactnative.sessionreplay.extensions;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.uimanager.LengthPercentage;
|
|
9
|
+
|
|
10
|
+
public final class LengthPercentageExt {
|
|
11
|
+
|
|
12
|
+
private LengthPercentageExt() {
|
|
13
|
+
// Utility class, prevent instantiation
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gets the radius value from a LengthPercentage, or returns 0f if the LengthPercentage is null.
|
|
18
|
+
*
|
|
19
|
+
* @param lengthPercentage the LengthPercentage to resolve, can be null
|
|
20
|
+
* @param width the width to resolve against
|
|
21
|
+
* @param height the height to resolve against
|
|
22
|
+
* @return the resolved radius value, or 0f if lengthPercentage is null
|
|
23
|
+
*/
|
|
24
|
+
public static float getRadius(LengthPercentage lengthPercentage, float width, float height) {
|
|
25
|
+
return lengthPercentage != null ? lengthPercentage.resolve(width, height) : 0f;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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.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.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
|
+
}
|