@datadog/mobile-react-native-webview 2.4.4 → 2.5.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.
- package/DatadogSDKReactNativeWebView.podspec +46 -0
- package/android/build.gradle +249 -0
- package/android/detekt.yml +572 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/newarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +35 -0
- package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewManager.kt +112 -0
- package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +36 -0
- package/android/src/test/kotlin/com/datadog/reactnative/tools/unit/GenericAssert.kt +18 -0
- package/android/src/test/kotlin/com/datadog/reactnative/webview/DatadogWebViewTest.kt +126 -0
- package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
- package/ios/DatadogSDKReactNativeWebView.xcodeproj/project.pbxproj +272 -0
- package/ios/DatadogSDKReactNativeWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/Sources/DatadogSDKReactNativeWebView.h +12 -0
- package/ios/Sources/RCTDatadogWebView.h +21 -0
- package/ios/Sources/RCTDatadogWebView.mm +53 -0
- package/ios/Sources/RCTDatadogWebViewManager.h +10 -0
- package/ios/Sources/RCTDatadogWebViewManager.mm +84 -0
- package/ios/Sources/RCTDatadogWebViewTracking.swift +67 -0
- package/lib/commonjs/ext-specs/NativeDdLogs.js +19 -0
- package/lib/commonjs/ext-specs/NativeDdLogs.js.map +1 -0
- package/lib/commonjs/ext-specs/NativeDdSdk.js.map +1 -0
- package/lib/commonjs/index.js +40 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeDdWebView.js +16 -0
- package/lib/commonjs/specs/NativeDdWebView.js.map +1 -0
- package/lib/commonjs/utils/env-utils.js +17 -0
- package/lib/commonjs/utils/env-utils.js.map +1 -0
- package/lib/commonjs/utils/webview-js-utils.js +124 -0
- package/lib/commonjs/utils/webview-js-utils.js.map +1 -0
- package/lib/module/ext-specs/NativeDdLogs.js +17 -0
- package/lib/module/ext-specs/NativeDdLogs.js.map +1 -0
- package/lib/module/ext-specs/NativeDdSdk.js.map +1 -0
- package/lib/module/index.js +39 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeDdWebView.js +11 -0
- package/lib/module/specs/NativeDdWebView.js.map +1 -0
- package/lib/module/utils/env-utils.js +10 -0
- package/lib/module/utils/env-utils.js.map +1 -0
- package/lib/module/utils/webview-js-utils.js +115 -0
- package/lib/module/utils/webview-js-utils.js.map +1 -0
- package/lib/typescript/ext-specs/NativeDdLogs.d.ts +16 -0
- package/lib/typescript/ext-specs/NativeDdLogs.d.ts.map +1 -0
- package/lib/typescript/ext-specs/NativeDdSdk.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +20 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdWebView.d.ts +4 -0
- package/lib/typescript/specs/NativeDdWebView.d.ts.map +1 -0
- package/lib/typescript/utils/env-utils.d.ts +2 -0
- package/lib/typescript/utils/env-utils.d.ts.map +1 -0
- package/lib/typescript/utils/webview-js-utils.d.ts +34 -0
- package/lib/typescript/utils/webview-js-utils.d.ts.map +1 -0
- package/package.json +22 -4
- package/src/__tests__/WebviewDatadog.test.tsx +39 -43
- package/src/__tests__/WebviewDatadogInjectedJS.test.tsx +200 -1
- package/src/__tests__/WebviewDatadogPerformance.test.tsx +12 -0
- package/src/__tests__/__utils__/string-utils.ts +13 -0
- package/src/__tests__/webview-js-utils.test.ts +51 -0
- package/src/ext-specs/NativeDdLogs.ts +25 -0
- package/src/{NativeDdSdk.ts → ext-specs/NativeDdSdk.ts} +1 -0
- package/src/index.tsx +70 -13
- package/src/specs/NativeDdWebView.ts +16 -0
- package/src/utils/env-utils.ts +9 -0
- package/src/utils/webview-js-utils.ts +150 -0
- package/lib/commonjs/NativeDdSdk.js.map +0 -1
- package/lib/commonjs/__utils__/formatAllowedHosts.js +0 -65
- package/lib/commonjs/__utils__/formatAllowedHosts.js.map +0 -1
- package/lib/commonjs/__utils__/getInjectedJavaScriptBeforeContentLoaded.js +0 -32
- package/lib/commonjs/__utils__/getInjectedJavaScriptBeforeContentLoaded.js.map +0 -1
- package/lib/module/NativeDdSdk.js.map +0 -1
- package/lib/module/__utils__/formatAllowedHosts.js +0 -58
- package/lib/module/__utils__/formatAllowedHosts.js.map +0 -1
- package/lib/module/__utils__/getInjectedJavaScriptBeforeContentLoaded.js +0 -24
- package/lib/module/__utils__/getInjectedJavaScriptBeforeContentLoaded.js.map +0 -1
- package/lib/typescript/NativeDdSdk.d.ts.map +0 -1
- package/lib/typescript/__utils__/formatAllowedHosts.d.ts +0 -2
- package/lib/typescript/__utils__/formatAllowedHosts.d.ts.map +0 -1
- package/lib/typescript/__utils__/getInjectedJavaScriptBeforeContentLoaded.d.ts +0 -3
- package/lib/typescript/__utils__/getInjectedJavaScriptBeforeContentLoaded.d.ts.map +0 -1
- package/src/__tests__/formatAllowedHosts.test.ts +0 -40
- package/src/__tests__/getInjectedJavaScriptBeforeContentLoaded.test.ts +0 -86
- package/src/__utils__/formatAllowedHosts.ts +0 -70
- package/src/__utils__/getInjectedJavaScriptBeforeContentLoaded.ts +0 -29
- /package/lib/commonjs/{NativeDdSdk.js → ext-specs/NativeDdSdk.js} +0 -0
- /package/lib/module/{NativeDdSdk.js → ext-specs/NativeDdSdk.js} +0 -0
- /package/lib/typescript/{NativeDdSdk.d.ts → ext-specs/NativeDdSdk.d.ts} +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
#import <Foundation/Foundation.h>
|
|
8
|
+
#import <DatadogSDKReactNative/DatadogSDKReactNative-umbrella.h>
|
|
9
|
+
#import "RCTDatadogWebViewManager.h"
|
|
10
|
+
#import "RCTDatadogWebView.h"
|
|
11
|
+
#import "DatadogSDKReactNativeWebView-Swift.h"
|
|
12
|
+
|
|
13
|
+
@interface RCTDatadogWebViewManager () <RNCWebViewDelegate, RCTDatadogWebViewDelegate>
|
|
14
|
+
@property (nonatomic, strong) NSMutableSet *allowedHosts;
|
|
15
|
+
@property (nonatomic, strong) RCTDatadogWebViewTracking* webViewTracking;
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
@implementation RCTDatadogWebViewManager { }
|
|
19
|
+
|
|
20
|
+
// The module is exported to React Native with the name defined here.
|
|
21
|
+
RCT_EXPORT_MODULE(DdReactNativeWebView)
|
|
22
|
+
|
|
23
|
+
// Allowed Hosts (REQUIRED)
|
|
24
|
+
RCT_CUSTOM_VIEW_PROPERTY(allowedHosts, NSArray, RCTDatadogWebView)
|
|
25
|
+
{
|
|
26
|
+
NSArray* allowedHosts = [RCTConvert NSArray:json];
|
|
27
|
+
[self setupDatadogWebView:allowedHosts view:view];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// MARK: - Initialization
|
|
31
|
+
- (instancetype)init
|
|
32
|
+
{
|
|
33
|
+
self = [super init];
|
|
34
|
+
if (self) {
|
|
35
|
+
self.allowedHosts = [[NSMutableSet alloc] init];
|
|
36
|
+
self.webViewTracking = [[RCTDatadogWebViewTracking alloc] init];
|
|
37
|
+
}
|
|
38
|
+
return self;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// MARK: - View Manager
|
|
42
|
+
- (UIView *)view
|
|
43
|
+
{
|
|
44
|
+
RCTDatadogWebView *rctWebView = [RCTDatadogWebView new];
|
|
45
|
+
rctWebView.delegate = self;
|
|
46
|
+
rctWebView.ddWebViewDelegate = self;
|
|
47
|
+
rctWebView.javaScriptEnabled = true;
|
|
48
|
+
return rctWebView;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// MARK: - Datadog Setup
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Setups the Datadog WebView by setting the allowed hosts and enabling tracking.
|
|
55
|
+
*
|
|
56
|
+
* @param allowedHosts The list of allowed hosts
|
|
57
|
+
* @param view The RCTDatadogWebView as returned by the ViewManager
|
|
58
|
+
*/
|
|
59
|
+
- (void)setupDatadogWebView:(NSArray *)allowedHosts view:(RCTDatadogWebView*)view {
|
|
60
|
+
[self.allowedHosts removeAllObjects];
|
|
61
|
+
for (NSObject* obj in allowedHosts) {
|
|
62
|
+
if (![obj isKindOfClass:[NSString class]]) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
[self.allowedHosts addObject:obj];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[self.webViewTracking enableWithWebView:view allowedHosts:self.allowedHosts];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// MARK: - RCTDatadogWebViewDelegate
|
|
72
|
+
- (void)didCreateWebView:(RCTDatadogWebView *)webView {
|
|
73
|
+
if (self.allowedHosts.count == 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
[self.webViewTracking enableWithWebView:webView allowedHosts:self.allowedHosts];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// MARK: - WKWebViewDelegate
|
|
80
|
+
- (BOOL)webView:(nonnull RNCWebViewImpl *)webView shouldStartLoadForRequest:(nonnull NSMutableDictionary<NSString *,id> *)request withCallback:(nonnull RCTDirectEventBlock)callback {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@end
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
import WebKit
|
|
8
|
+
import DatadogWebViewTracking
|
|
9
|
+
import DatadogSDKReactNative
|
|
10
|
+
import DatadogCore
|
|
11
|
+
|
|
12
|
+
@objc public class RCTDatadogWebViewTracking: NSObject {
|
|
13
|
+
var webView: RCTDatadogWebView? = nil
|
|
14
|
+
var allowedHosts: Set<String> = Set()
|
|
15
|
+
var coreListener: OnCoreInitializedListener?
|
|
16
|
+
|
|
17
|
+
public override init() {
|
|
18
|
+
super.init()
|
|
19
|
+
self.coreListener = { [weak self] (core: DatadogCoreProtocol) in
|
|
20
|
+
guard let strongSelf = self, let webView = strongSelf.webView else {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
strongSelf.enableWebViewTracking(
|
|
24
|
+
webView: webView,
|
|
25
|
+
allowedHosts: strongSelf.allowedHosts,
|
|
26
|
+
core: core
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Enables tracking on the given WebView.
|
|
33
|
+
|
|
34
|
+
- Parameter webView: The WebView to enable tracking on.
|
|
35
|
+
- Parameter allowedHosts: The allowed hosts.
|
|
36
|
+
- Note: If the SDK core is not available immediately, this method will register a listener and
|
|
37
|
+
enable tracking only when the core will be initialized.
|
|
38
|
+
*/
|
|
39
|
+
@objc public func enable(webView: RCTDatadogWebView, allowedHosts: Set<String>) {
|
|
40
|
+
self.webView = webView
|
|
41
|
+
self.allowedHosts = allowedHosts
|
|
42
|
+
|
|
43
|
+
guard !webView.isTrackingEnabled else { return }
|
|
44
|
+
|
|
45
|
+
if let core = DatadogSDKWrapper.shared.getCoreInstance() {
|
|
46
|
+
enableWebViewTracking(webView: webView, allowedHosts: allowedHosts, core: core)
|
|
47
|
+
} else if let coreListener = self.coreListener {
|
|
48
|
+
DatadogSDKWrapper.shared.addOnCoreInitializedListener(listener: coreListener)
|
|
49
|
+
} else {
|
|
50
|
+
// TODO: Report initialization problem
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private func enableWebViewTracking(
|
|
55
|
+
webView: RCTDatadogWebView,
|
|
56
|
+
allowedHosts: Set<String>,
|
|
57
|
+
core: DatadogCoreProtocol
|
|
58
|
+
) {
|
|
59
|
+
guard let wkWebView = webView.getWKWebView() else {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
DispatchQueue.main.async {
|
|
63
|
+
WebViewTracking.enable(webView: wkWebView, hosts: allowedHosts, in: core)
|
|
64
|
+
self.webView?.isTrackingEnabled = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
/*
|
|
9
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
10
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
11
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
12
|
+
*/
|
|
13
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
14
|
+
/**
|
|
15
|
+
* Do not import this Spec directly, use DdNativeLogsType instead.
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line import/no-default-export
|
|
18
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.get('DdLogs');
|
|
19
|
+
//# sourceMappingURL=NativeDdLogs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["ext-specs/NativeDdLogs.ts"],"mappings":";;;;;;AAQA,IAAAA,YAAA,GAAAC,OAAA;AARA;AACA;AACA;AACA;AACA;AAEA;AAIA;AACA;AACA;AAWA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACeC,gCAAmB,CAACC,GAAG,CAAO,QAAQ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","NativeDdSdk","exports","TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["ext-specs/NativeDdSdk.ts"],"mappings":";;;;;;AAOA,IAAAA,YAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;;AAMO,MAAMC,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAGE,gCAAmB,CAACC,GAAG,CAC9C,OACJ,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -6,9 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = exports.WebView = void 0;
|
|
7
7
|
var _reactNativeWebview = require("react-native-webview");
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var _NativeDdLogs = _interopRequireDefault(require("./ext-specs/NativeDdLogs"));
|
|
10
|
+
var _NativeDdSdk = require("./ext-specs/NativeDdSdk");
|
|
11
|
+
var _NativeDdWebView = require("./specs/NativeDdWebView");
|
|
12
|
+
var _envUtils = require("./utils/env-utils");
|
|
13
|
+
var _webviewJsUtils = require("./utils/webview-js-utils");
|
|
11
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
18
|
/*
|
|
@@ -20,17 +24,46 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
20
24
|
const WebViewComponent = (props, ref) => {
|
|
21
25
|
const userDefinedOnMessage = props.onMessage;
|
|
22
26
|
const onMessage = (0, _react.useCallback)(event => {
|
|
27
|
+
const handleDatadogMessage = ddMessage => {
|
|
28
|
+
if (ddMessage.type === 'ERROR' && ddMessage.message != null && (props.logUserCodeErrors ?? false)) {
|
|
29
|
+
_NativeDdLogs.default?.error(ddMessage.message, {});
|
|
30
|
+
} else if (ddMessage.type === 'NATIVE_EVENT' && ddMessage.message != null) {
|
|
31
|
+
_NativeDdSdk.NativeDdSdk?.consumeWebviewEvent(ddMessage.message);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
23
34
|
const message = event.nativeEvent.data;
|
|
24
|
-
if (message
|
|
25
|
-
|
|
26
|
-
}
|
|
35
|
+
if (message == null) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const jsonMsg = JSON.parse(message);
|
|
40
|
+
if (jsonMsg && jsonMsg.source === 'DATADOG') {
|
|
41
|
+
handleDatadogMessage(jsonMsg);
|
|
42
|
+
} else {
|
|
43
|
+
userDefinedOnMessage?.(event);
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
27
46
|
userDefinedOnMessage?.(event);
|
|
28
47
|
}
|
|
29
|
-
}, [userDefinedOnMessage]);
|
|
48
|
+
}, [userDefinedOnMessage, props.logUserCodeErrors]);
|
|
49
|
+
const getInjectedJavascriptBeforeContentLoaded = () => {
|
|
50
|
+
if ((0, _envUtils.isNewArchitecture)()) {
|
|
51
|
+
return (0, _webviewJsUtils.getWebViewEventBridgingJS)(props.allowedHosts, props.injectedJavaScriptBeforeContentLoaded);
|
|
52
|
+
} else {
|
|
53
|
+
return (0, _webviewJsUtils.wrapJsCodeInTryAndCatch)(props.injectedJavaScriptBeforeContentLoaded);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
30
56
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeWebview.WebView, {
|
|
31
57
|
...props,
|
|
32
58
|
onMessage: onMessage,
|
|
33
|
-
|
|
59
|
+
nativeConfig: {
|
|
60
|
+
component: _NativeDdWebView.NativeDdWebView,
|
|
61
|
+
props: {
|
|
62
|
+
allowedHosts: props.allowedHosts
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
injectedJavaScript: (0, _webviewJsUtils.wrapJsCodeInTryAndCatch)(props.injectedJavaScript),
|
|
66
|
+
injectedJavaScriptBeforeContentLoaded: getInjectedJavascriptBeforeContentLoaded(),
|
|
34
67
|
ref: ref
|
|
35
68
|
});
|
|
36
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeWebview","require","_react","_interopRequireWildcard","
|
|
1
|
+
{"version":3,"names":["_reactNativeWebview","require","_react","_interopRequireWildcard","_NativeDdLogs","_interopRequireDefault","_NativeDdSdk","_NativeDdWebView","_envUtils","_webviewJsUtils","_jsxRuntime","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","WebViewComponent","props","ref","userDefinedOnMessage","onMessage","useCallback","event","handleDatadogMessage","ddMessage","type","message","logUserCodeErrors","NativeDdLogs","error","NativeDdSdk","consumeWebviewEvent","nativeEvent","data","jsonMsg","JSON","parse","source","err","getInjectedJavascriptBeforeContentLoaded","isNewArchitecture","getWebViewEventBridgingJS","allowedHosts","injectedJavaScriptBeforeContentLoaded","wrapJsCodeInTryAndCatch","jsx","WebView","nativeConfig","component","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MAAM;QACHf,oBAAoB,GAAGG,KAAK,CAAC;MACjC;IACJ,CAAC,CAAC,OAAOgB,GAAG,EAAE;MACVnB,oBAAoB,GAAGG,KAAK,CAAC;IACjC;EACJ,CAAC,EACD,CAACH,oBAAoB,EAAEF,KAAK,CAACU,iBAAiB,CAClD,CAAC;EAED,MAAMY,wCAAwC,GAAGA,CAAA,KAA0B;IACvE,IAAI,IAAAC,2BAAiB,EAAC,CAAC,EAAE;MACrB,OAAO,IAAAC,yCAAyB,EAC5BxB,KAAK,CAACyB,YAAY,EAClBzB,KAAK,CAAC0B,qCACV,CAAC;IACL,CAAC,MAAM;MACH,OAAO,IAAAC,uCAAuB,EAC1B3B,KAAK,CAAC0B,qCACV,CAAC;IACL;EACJ,CAAC;EAED,oBACI,IAAAhD,WAAA,CAAAkD,GAAA,EAAC5D,mBAAA,CAAA6D,OAAS;IAAA,GACF7B,KAAK;IACTG,SAAS,EAAEA,SAAU;IACrB2B,YAAY,EAAE;MACVC,SAAS,EAAEC,gCAAe;MAC1BhC,KAAK,EAAE;QACHyB,YAAY,EAAEzB,KAAK,CAACyB;MACxB;IACJ,CAAE;IACFQ,kBAAkB,EAAE,IAAAN,uCAAuB,EACvC3B,KAAK,CAACiC,kBACV,CAAE;IACFP,qCAAqC,EAAEJ,wCAAwC,CAAC,CAAE;IAClFrB,GAAG,EAAEA;EAAI,CACZ,CAAC;AAEV,CAAC;AAEM,MAAM4B,OAAO,GAAAK,OAAA,CAAAL,OAAA,gBAAG,IAAAM,iBAAU,EAACpC,gBAAgB,CAAC;AAAC,IAAAqC,QAAA,GAAAF,OAAA,CAAArD,OAAA,GAErCgD,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NativeDdWebView = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _envUtils = require("../utils/env-utils");
|
|
9
|
+
/*
|
|
10
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
11
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
12
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const NativeDdWebView = exports.NativeDdWebView = !(0, _envUtils.isNewArchitecture)() ? (0, _reactNative.requireNativeComponent)('DdReactNativeWebView') : undefined;
|
|
16
|
+
//# sourceMappingURL=NativeDdWebView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_envUtils","NativeDdWebView","exports","isNewArchitecture","requireNativeComponent","undefined"],"sourceRoot":"../../../src","sources":["specs/NativeDdWebView.ts"],"mappings":";;;;;;AAOA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AATA;AACA;AACA;AACA;AACA;;AAOA,MAAME,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,CAAC,IAAAE,2BAAiB,EAAC,CAAC,GACtC,IAAAC,mCAAsB,EAA2B,sBAAsB,CAAC,GACxEC,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isNewArchitecture = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
9
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
10
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const isNewArchitecture = () => {
|
|
14
|
+
return global?.nativeFabricUIManager !== undefined;
|
|
15
|
+
};
|
|
16
|
+
exports.isNewArchitecture = isNewArchitecture;
|
|
17
|
+
//# sourceMappingURL=env-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isNewArchitecture","global","nativeFabricUIManager","undefined","exports"],"sourceRoot":"../../../src","sources":["utils/env-utils.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,iBAAiB,GAAGA,CAAA,KAAe;EAC5C,OAAQC,MAAM,EAAUC,qBAAqB,KAAKC,SAAS;AAC/D,CAAC;AAACC,OAAA,CAAAJ,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.wrapJsCodeInTryAndCatch = exports.getWebViewEventBridgingJS = exports.DATADOG_MESSAGE_PREFIX = void 0;
|
|
7
|
+
var _NativeDdSdk = require("../ext-specs/NativeDdSdk");
|
|
8
|
+
/*
|
|
9
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
10
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
11
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const DATADOG_MESSAGE_PREFIX = exports.DATADOG_MESSAGE_PREFIX = '[DATADOG]';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal Datadog Message Type
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal Datadog Message Format.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wraps the given JS Code in a try and catch block.
|
|
26
|
+
* @param javascriptCode The JS Code to wrap in a try and catch block.
|
|
27
|
+
* @returns the wrapped JS code.
|
|
28
|
+
*/
|
|
29
|
+
const wrapJsCodeInTryAndCatch = javascriptCode => javascriptCode ? `
|
|
30
|
+
try{
|
|
31
|
+
${javascriptCode}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
35
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
36
|
+
source: 'DATADOG',
|
|
37
|
+
type: 'ERROR',
|
|
38
|
+
message: errorMsg
|
|
39
|
+
}));
|
|
40
|
+
true;
|
|
41
|
+
}` : undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Legacy JS code for bridging the WebView events to DataDog native SDKs for consumption.
|
|
45
|
+
* @param allowedHosts The list of allowed hosts.
|
|
46
|
+
* @param customJavaScriptCode Custom user JS code to inject along with the Datadog bridging logic.
|
|
47
|
+
* @returns The JS code block as a string.
|
|
48
|
+
*/
|
|
49
|
+
exports.wrapJsCodeInTryAndCatch = wrapJsCodeInTryAndCatch;
|
|
50
|
+
const getWebViewEventBridgingJS = (allowedHosts, customJavaScriptCode) => `
|
|
51
|
+
window.DatadogEventBridge = {
|
|
52
|
+
send(msg) {
|
|
53
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
54
|
+
source: 'DATADOG',
|
|
55
|
+
type: 'NATIVE_EVENT',
|
|
56
|
+
message: msg
|
|
57
|
+
}));
|
|
58
|
+
true;
|
|
59
|
+
},
|
|
60
|
+
getAllowedWebViewHosts() {
|
|
61
|
+
return ${formatAllowedHosts(allowedHosts)}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
try{
|
|
65
|
+
${customJavaScriptCode}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
69
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
70
|
+
source: 'DATADOG',
|
|
71
|
+
type: 'ERROR',
|
|
72
|
+
message: errorMsg
|
|
73
|
+
}));
|
|
74
|
+
true;
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
exports.getWebViewEventBridgingJS = getWebViewEventBridgingJS;
|
|
78
|
+
function formatAllowedHosts(allowedHosts) {
|
|
79
|
+
try {
|
|
80
|
+
return `'${JSON.stringify(allowedHosts)}'`;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
if (_NativeDdSdk.NativeDdSdk) {
|
|
83
|
+
_NativeDdSdk.NativeDdSdk.telemetryError(getErrorMessage(e), getErrorStackTrace(e), 'AllowedHostsError');
|
|
84
|
+
}
|
|
85
|
+
return "'[]'";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const getErrorMessage = error => {
|
|
89
|
+
const EMPTY_MESSAGE = 'Unknown Error';
|
|
90
|
+
let message = EMPTY_MESSAGE;
|
|
91
|
+
if (error === undefined || error === null) {
|
|
92
|
+
message = EMPTY_MESSAGE;
|
|
93
|
+
} else if (typeof error === 'object' && 'message' in error) {
|
|
94
|
+
message = String(error.message);
|
|
95
|
+
} else {
|
|
96
|
+
message = String(error);
|
|
97
|
+
}
|
|
98
|
+
return message;
|
|
99
|
+
};
|
|
100
|
+
const getErrorStackTrace = error => {
|
|
101
|
+
const EMPTY_STACK_TRACE = '';
|
|
102
|
+
let stack = EMPTY_STACK_TRACE;
|
|
103
|
+
try {
|
|
104
|
+
if (error === undefined || error === null) {
|
|
105
|
+
stack = EMPTY_STACK_TRACE;
|
|
106
|
+
} else if (typeof error === 'string') {
|
|
107
|
+
stack = EMPTY_STACK_TRACE;
|
|
108
|
+
} else if (typeof error === 'object') {
|
|
109
|
+
if ('stacktrace' in error) {
|
|
110
|
+
stack = String(error.stacktrace);
|
|
111
|
+
} else if ('stack' in error) {
|
|
112
|
+
stack = String(error.stack);
|
|
113
|
+
} else if ('componentStack' in error) {
|
|
114
|
+
stack = String(error.componentStack);
|
|
115
|
+
} else if ('sourceURL' in error && 'line' in error && 'column' in error) {
|
|
116
|
+
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
// Do nothing
|
|
121
|
+
}
|
|
122
|
+
return stack;
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=webview-js-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_NativeDdSdk","require","DATADOG_MESSAGE_PREFIX","exports","wrapJsCodeInTryAndCatch","javascriptCode","undefined","getWebViewEventBridgingJS","allowedHosts","customJavaScriptCode","formatAllowedHosts","JSON","stringify","e","NativeDdSdk","telemetryError","getErrorMessage","getErrorStackTrace","error","EMPTY_MESSAGE","message","String","EMPTY_STACK_TRACE","stack","stacktrace","componentStack","sourceURL","line","column"],"sourceRoot":"../../../src","sources":["utils/webview-js-utils.ts"],"mappings":";;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA;AALA;AACA;AACA;AACA;AACA;;AAGO,MAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,WAAW;;AAEjD;AACA;AACA;;AAWA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACO,MAAME,uBAAuB,GAChCC,cAAuB,IAEvBA,cAAc,GACR;AACV;AACA,QAAQA,cAAc;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GACIC,SAAS;;AAEnB;AACA;AACA;AACA;AACA;AACA;AALAH,OAAA,CAAAC,uBAAA,GAAAA,uBAAA;AAMO,MAAMG,yBAAyB,GAAGA,CACrCC,YAAuB,EACvBC,oBAA6B,KAE7B;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiBC,kBAAkB,CAACF,YAAY,CAAC;AACjD;AACA;AACA;AACA,QAAQC,oBAAoB;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AAACN,OAAA,CAAAI,yBAAA,GAAAA,yBAAA;AAEJ,SAASG,kBAAkBA,CAACF,YAAuB,EAAU;EACzD,IAAI;IACA,OAAO,IAAIG,IAAI,CAACC,SAAS,CAACJ,Y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CAAC,MAAM,IAAI,gBAAgB,IAAIL,KAAK,EAAE;QAClCK,KAAK,GAAGF,MAAM,CAACH,KAAK,CAACO,cAAc,CAAC;MACxC,CAAC,MAAM,IACH,WAAW,IAAIP,KAAK,IACpB,MAAM,IAAIA,KAAK,IACf,QAAQ,IAAIA,KAAK,EACnB;QACEK,KAAK,GAAG,MAAML,KAAK,CAACQ,SAAS,IAAIR,KAAK,CAACS,IAAI,IAAIT,KAAK,CAACU,MAAM,EAAE;MACjE;IACJ;EACJ,CAAC,CAAC,OAAOf,CAAC,EAAE;IACR;EAAA;EAEJ,OAAOU,KAAK;AAChB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
8
|
+
|
|
9
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Do not import this Spec directly, use DdNativeLogsType instead.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line import/no-default-export
|
|
16
|
+
export default TurboModuleRegistry.get('DdLogs');
|
|
17
|
+
//# sourceMappingURL=NativeDdLogs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["ext-specs/NativeDdLogs.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,SAASA,mBAAmB,QAAQ,cAAc;;AAElD;AACA;AACA;;AAWA;AACA,eAAeA,mBAAmB,CAACC,GAAG,CAAO,QAAQ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","NativeDdSdk","get"],"sourceRoot":"../../../src","sources":["ext-specs/NativeDdSdk.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAGA,SAASA,mBAAmB,QAAQ,cAAc;;AAElD;AACA;AACA;AACA;;AAMA,OAAO,MAAMC,WAAW,GAAGD,mBAAmB,CAACE,GAAG,CAC9C,OACJ,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -6,23 +6,55 @@
|
|
|
6
6
|
|
|
7
7
|
import { WebView as RNWebView } from 'react-native-webview';
|
|
8
8
|
import React, { forwardRef, useCallback } from 'react';
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
9
|
+
import NativeDdLogs from './ext-specs/NativeDdLogs';
|
|
10
|
+
import { NativeDdSdk } from './ext-specs/NativeDdSdk';
|
|
11
|
+
import { NativeDdWebView } from './specs/NativeDdWebView';
|
|
12
|
+
import { isNewArchitecture } from './utils/env-utils';
|
|
13
|
+
import { getWebViewEventBridgingJS, wrapJsCodeInTryAndCatch } from './utils/webview-js-utils';
|
|
11
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
15
|
const WebViewComponent = (props, ref) => {
|
|
13
16
|
const userDefinedOnMessage = props.onMessage;
|
|
14
17
|
const onMessage = useCallback(event => {
|
|
18
|
+
const handleDatadogMessage = ddMessage => {
|
|
19
|
+
if (ddMessage.type === 'ERROR' && ddMessage.message != null && (props.logUserCodeErrors ?? false)) {
|
|
20
|
+
NativeDdLogs?.error(ddMessage.message, {});
|
|
21
|
+
} else if (ddMessage.type === 'NATIVE_EVENT' && ddMessage.message != null) {
|
|
22
|
+
NativeDdSdk?.consumeWebviewEvent(ddMessage.message);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
15
25
|
const message = event.nativeEvent.data;
|
|
16
|
-
if (message
|
|
17
|
-
|
|
18
|
-
}
|
|
26
|
+
if (message == null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const jsonMsg = JSON.parse(message);
|
|
31
|
+
if (jsonMsg && jsonMsg.source === 'DATADOG') {
|
|
32
|
+
handleDatadogMessage(jsonMsg);
|
|
33
|
+
} else {
|
|
34
|
+
userDefinedOnMessage?.(event);
|
|
35
|
+
}
|
|
36
|
+
} catch (err) {
|
|
19
37
|
userDefinedOnMessage?.(event);
|
|
20
38
|
}
|
|
21
|
-
}, [userDefinedOnMessage]);
|
|
39
|
+
}, [userDefinedOnMessage, props.logUserCodeErrors]);
|
|
40
|
+
const getInjectedJavascriptBeforeContentLoaded = () => {
|
|
41
|
+
if (isNewArchitecture()) {
|
|
42
|
+
return getWebViewEventBridgingJS(props.allowedHosts, props.injectedJavaScriptBeforeContentLoaded);
|
|
43
|
+
} else {
|
|
44
|
+
return wrapJsCodeInTryAndCatch(props.injectedJavaScriptBeforeContentLoaded);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
22
47
|
return /*#__PURE__*/_jsx(RNWebView, {
|
|
23
48
|
...props,
|
|
24
49
|
onMessage: onMessage,
|
|
25
|
-
|
|
50
|
+
nativeConfig: {
|
|
51
|
+
component: NativeDdWebView,
|
|
52
|
+
props: {
|
|
53
|
+
allowedHosts: props.allowedHosts
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
injectedJavaScript: wrapJsCodeInTryAndCatch(props.injectedJavaScript),
|
|
57
|
+
injectedJavaScriptBeforeContentLoaded: getInjectedJavascriptBeforeContentLoaded(),
|
|
26
58
|
ref: ref
|
|
27
59
|
});
|
|
28
60
|
};
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["WebView","RNWebView","React","forwardRef","useCallback","NativeDdSdk","
|
|
1
|
+
{"version":3,"names":["WebView","RNWebView","React","forwardRef","useCallback","NativeDdLogs","NativeDdSdk","NativeDdWebView","isNewArchitecture","getWebViewEventBridgingJS","wrapJsCodeInTryAndCatch","jsx","_jsx","WebViewComponent","props","ref","userDefinedOnMessage","onMessage","event","handleDatadogMessage","ddMessage","type","message","logUserCodeErrors","error","consumeWebviewEvent","nativeEvent","data","jsonMsg","JSON","parse","source","err","getInjectedJavascriptBeforeContentLoaded","allowedHosts","injectedJavaScriptBeforeContentLoaded","nativeConfig","component","injectedJavaScript"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,IAAIC,SAAS,QAAQ,sBAAsB;AAC3D,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,QAAQ,OAAO;AAEtD,OAAOC,YAAY,MAAM,0BAA0B;AACnD,SAASC,WAAW,QAAQ,yBAAyB;AACrD,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,iBAAiB,QAAQ,mBAAmB;AACrD,SACIC,yBAAyB,EACzBC,uBAAuB,QACpB,0BAA0B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAkBlC,MAAMC,gBAAgB,GAAGA,CAACC,KAAY,EAAEC,GAAgC,KAAK;EACzE,MAAMC,oBAAoB,GAAGF,KAAK,CAACG,SAAS;EAE5C,MAAMA,SAAS,GAAGb,WAAW,CACxBc,KAA0B,IAAK;IAC5B,MAAMC,oBAAoB,GAAIC,SAA+B,IAAK;MAC9D,IACIA,SAAS,CAACC,IAAI,KAAK,OAAO,IAC1BD,SAAS,CAACE,OAAO,IAAI,IAAI,KACxBR,KAAK,CAACS,iBAAiB,IAAI,KAAK,CAAC,EACpC;QACElB,YAAY,EAAEmB,KAAK,CAACJ,SAAS,CAACE,OAAO,EAAE,CAAC,CAAC,CAAC;MAC9C,CAAC,MAAM,IACHF,SAAS,CAACC,IAAI,KAAK,cAAc,IACjCD,SAAS,CAACE,OAAO,IAAI,IAAI,EAC3B;QACEhB,WAAW,EAAEmB,mBAAmB,CAACL,SAAS,CAACE,OAAO,CAAC;MACvD;IACJ,CAAC;IAED,MAAMA,OAAO,GAAGJ,KAAK,CAACQ,WAAW,CAACC,IAAI;IACtC,IAAIL,OAAO,IAAI,IAAI,EAAE;MACjB;IACJ;IAEA,IAAI;MACA,MAAMM,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACR,OAAO,CAAC;MACnC,IAAIM,OAAO,IAAIA,OAAO,CAACG,MAAM,KAAK,SAAS,EAAE;QACzCZ,oBAAoB,CAACS,OAAO,CAAC;MACjC,CAAC,MAAM;QACHZ,oBAAoB,GAAGE,KAAK,CAAC;MACjC;IACJ,CAAC,CAAC,OAAOc,GAAG,EAAE;MACVhB,oBAAoB,GAAGE,KAAK,CAAC;IACjC;EACJ,CAAC,EACD,CAACF,oBAAoB,EAAEF,KAAK,CAACS,iBAAiB,CAClD,CAAC;EAED,MAAMU,wCAAwC,GAAGA,CAAA,KAA0B;IACvE,IAAIzB,iBAAiB,CAAC,CAAC,EAAE;MACrB,OAAOC,yBAAyB,CAC5BK,KAAK,CAACoB,YAAY,EAClBpB,KAAK,CAACqB,qCACV,CAAC;IACL,CAAC,MAAM;MACH,OAAOzB,uBAAuB,CAC1BI,KAAK,CAACqB,qCACV,CAAC;IACL;EACJ,CAAC;EAED,oBACIvB,IAAA,CAACX,SAAS;IAAA,GACFa,KAAK;IACTG,SAAS,EAAEA,SAAU;IACrBmB,YAAY,EAAE;MACVC,SAAS,EAAE9B,eAAe;MAC1BO,KAAK,EAAE;QACHoB,YAAY,EAAEpB,KAAK,CAACoB;MACxB;IACJ,CAAE;IACFI,kBAAkB,EAAE5B,uBAAuB,CACvCI,KAAK,CAACwB,kBACV,CAAE;IACFH,qCAAqC,EAAEF,wCAAwC,CAAC,CAAE;IAClFlB,GAAG,EAAEA;EAAI,CACZ,CAAC;AAEV,CAAC;AAED,OAAO,MAAMf,OAAO,gBAAGG,UAAU,CAACU,gBAAgB,CAAC;AAEnD,eAAeb,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import { requireNativeComponent } from 'react-native';
|
|
8
|
+
import { isNewArchitecture } from '../utils/env-utils';
|
|
9
|
+
const NativeDdWebView = !isNewArchitecture() ? requireNativeComponent('DdReactNativeWebView') : undefined;
|
|
10
|
+
export { NativeDdWebView };
|
|
11
|
+
//# sourceMappingURL=NativeDdWebView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["requireNativeComponent","isNewArchitecture","NativeDdWebView","undefined"],"sourceRoot":"../../../src","sources":["specs/NativeDdWebView.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAGA,SAASA,sBAAsB,QAAQ,cAAc;AAErD,SAASC,iBAAiB,QAAQ,oBAAoB;AAEtD,MAAMC,eAAe,GAAG,CAACD,iBAAiB,CAAC,CAAC,GACtCD,sBAAsB,CAA2B,sBAAsB,CAAC,GACxEG,SAAS;AAEf,SAASD,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export const isNewArchitecture = () => {
|
|
8
|
+
return global?.nativeFabricUIManager !== undefined;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=env-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isNewArchitecture","global","nativeFabricUIManager","undefined"],"sourceRoot":"../../../src","sources":["utils/env-utils.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,iBAAiB,GAAGA,CAAA,KAAe;EAC5C,OAAQC,MAAM,EAAUC,qBAAqB,KAAKC,SAAS;AAC/D,CAAC","ignoreList":[]}
|