@datadog/mobile-react-native-webview 1.7.1 → 1.8.0-rc1
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/lib/commonjs/index.js
CHANGED
|
@@ -19,24 +19,33 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
19
19
|
|
|
20
20
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const WebViewComponent = (props, ref) => {
|
|
23
23
|
const userDefinedOnMessage = props.onMessage;
|
|
24
24
|
const onMessage = (0, _react.useCallback)(event => {
|
|
25
25
|
const message = event.nativeEvent.data;
|
|
26
26
|
|
|
27
27
|
if (message.startsWith(_getInjectedJavaScriptBeforeContentLoaded.DATADOG_MESSAGE_PREFIX)) {
|
|
28
|
-
|
|
28
|
+
NativeDdSdk === null || NativeDdSdk === void 0 ? void 0 : NativeDdSdk.consumeWebviewEvent(message.substring(_getInjectedJavaScriptBeforeContentLoaded.DATADOG_MESSAGE_PREFIX.length + 1));
|
|
29
29
|
} else {
|
|
30
30
|
userDefinedOnMessage === null || userDefinedOnMessage === void 0 ? void 0 : userDefinedOnMessage(event);
|
|
31
31
|
}
|
|
32
32
|
}, [userDefinedOnMessage]);
|
|
33
33
|
return /*#__PURE__*/_react.default.createElement(_reactNativeWebview.WebView, _extends({}, props, {
|
|
34
34
|
onMessage: onMessage,
|
|
35
|
-
injectedJavaScriptBeforeContentLoaded: (0, _getInjectedJavaScriptBeforeContentLoaded.getInjectedJavaScriptBeforeContentLoaded)(props.allowedHosts, props.injectedJavaScriptBeforeContentLoaded)
|
|
35
|
+
injectedJavaScriptBeforeContentLoaded: (0, _getInjectedJavaScriptBeforeContentLoaded.getInjectedJavaScriptBeforeContentLoaded)(props.allowedHosts, props.injectedJavaScriptBeforeContentLoaded),
|
|
36
|
+
ref: ref
|
|
36
37
|
}));
|
|
37
38
|
};
|
|
38
39
|
|
|
40
|
+
const WebView = /*#__PURE__*/(0, _react.forwardRef)(WebViewComponent);
|
|
39
41
|
exports.WebView = WebView;
|
|
40
42
|
var _default = WebView;
|
|
43
|
+
/**
|
|
44
|
+
* We have to redefine the spec for the Native SDK here to be able to use the new architecture.
|
|
45
|
+
* We don't declare it in a separate file so we don't end up with a duplicate definition of the native module.
|
|
46
|
+
*/
|
|
47
|
+
|
|
41
48
|
exports.default = _default;
|
|
49
|
+
|
|
50
|
+
const NativeDdSdk = _reactNative.TurboModuleRegistry.get('DdSdk');
|
|
42
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["WebViewComponent","props","ref","userDefinedOnMessage","onMessage","event","message","nativeEvent","data","startsWith","DATADOG_MESSAGE_PREFIX","NativeDdSdk","consumeWebviewEvent","substring","length","allowedHosts","injectedJavaScriptBeforeContentLoaded","WebView","TurboModuleRegistry","get"],"mappings":";;;;;;;AAMA;;AAEA;;AACA;;AAEA;;;;;;;;AAUA,MAAMA,gBAAgB,GAAG,CAACC,KAAD,EAAeC,GAAf,KAAoD;AACzE,QAAMC,oBAAoB,GAAGF,KAAK,CAACG,SAAnC;AACA,QAAMA,SAAS,GAAG,wBACbC,KAAD,IAAgC;AAC5B,UAAMC,OAAO,GAAGD,KAAK,CAACE,WAAN,CAAkBC,IAAlC;;AACA,QAAIF,OAAO,CAACG,UAAR,CAAmBC,gEAAnB,CAAJ,EAAgD;AAC5CC,MAAAA,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW,CAAEC,mBAAb,CACIN,OAAO,CAACO,SAAR,CAAkBH,iEAAuBI,MAAvB,GAAgC,CAAlD,CADJ;AAGH,KAJD,MAIO;AACHX,MAAAA,oBAAoB,SAApB,IAAAA,oBAAoB,WAApB,YAAAA,oBAAoB,CAAGE,KAAH,CAApB;AACH;AACJ,GAVa,EAWd,CAACF,oBAAD,CAXc,CAAlB;AAaA,sBACI,6BAAC,2BAAD,eACQF,KADR;AAEI,IAAA,SAAS,EAAEG,SAFf;AAGI,IAAA,qCAAqC,EAAE,wFACnCH,KAAK,CAACc,YAD6B,EAEnCd,KAAK,CAACe,qCAF6B,CAH3C;AAOI,IAAA,GAAG,EAAEd;AAPT,KADJ;AAWH,CA1BD;;AA4BO,MAAMe,OAAO,gBAAG,uBAAWjB,gBAAX,CAAhB;;eAEQiB,O;AAEf;AACA;AACA;AACA;;;;AAIA,MAAMN,WAAW,GAAGO,iCAAoBC,GAApB,CAAgD,OAAhD,CAApB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\nimport type { WebViewMessageEvent, WebViewProps } from 'react-native-webview';\nimport { WebView as RNWebView } from 'react-native-webview';\nimport type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\nimport React, { forwardRef, useCallback } from 'react';\n\nimport {\n DATADOG_MESSAGE_PREFIX,\n getInjectedJavaScriptBeforeContentLoaded\n} from './__utils__/getInjectedJavaScriptBeforeContentLoaded';\n\ntype Props = WebViewProps & {\n allowedHosts?: string[];\n injectedJavaScriptBeforeContentLoaded?: string;\n};\n\nconst WebViewComponent = (props: Props, ref: React.Ref<RNWebView<Props>>) => {\n const userDefinedOnMessage = props.onMessage;\n const onMessage = useCallback(\n (event: WebViewMessageEvent) => {\n const message = event.nativeEvent.data;\n if (message.startsWith(DATADOG_MESSAGE_PREFIX)) {\n NativeDdSdk?.consumeWebviewEvent(\n message.substring(DATADOG_MESSAGE_PREFIX.length + 1)\n );\n } else {\n userDefinedOnMessage?.(event);\n }\n },\n [userDefinedOnMessage]\n );\n return (\n <RNWebView\n {...props}\n onMessage={onMessage}\n injectedJavaScriptBeforeContentLoaded={getInjectedJavaScriptBeforeContentLoaded(\n props.allowedHosts,\n props.injectedJavaScriptBeforeContentLoaded\n )}\n ref={ref}\n />\n );\n};\n\nexport const WebView = forwardRef(WebViewComponent);\n\nexport default WebView;\n\n/**\n * We have to redefine the spec for the Native SDK here to be able to use the new architecture.\n * We don't declare it in a separate file so we don't end up with a duplicate definition of the native module.\n */\ninterface PartialNativeDdSdkSpec extends TurboModule {\n consumeWebviewEvent(message: string): Promise<void>;\n}\nconst NativeDdSdk = TurboModuleRegistry.get<PartialNativeDdSdkSpec>('DdSdk');\n"]}
|
package/lib/module/index.js
CHANGED
|
@@ -6,24 +6,34 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
6
6
|
* Copyright 2016-Present Datadog, Inc.
|
|
7
7
|
*/
|
|
8
8
|
import { WebView as RNWebView } from 'react-native-webview';
|
|
9
|
-
import {
|
|
10
|
-
import React, { useCallback } from 'react';
|
|
9
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
10
|
+
import React, { forwardRef, useCallback } from 'react';
|
|
11
11
|
import { DATADOG_MESSAGE_PREFIX, getInjectedJavaScriptBeforeContentLoaded } from './__utils__/getInjectedJavaScriptBeforeContentLoaded';
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
const WebViewComponent = (props, ref) => {
|
|
13
14
|
const userDefinedOnMessage = props.onMessage;
|
|
14
15
|
const onMessage = useCallback(event => {
|
|
15
16
|
const message = event.nativeEvent.data;
|
|
16
17
|
|
|
17
18
|
if (message.startsWith(DATADOG_MESSAGE_PREFIX)) {
|
|
18
|
-
|
|
19
|
+
NativeDdSdk === null || NativeDdSdk === void 0 ? void 0 : NativeDdSdk.consumeWebviewEvent(message.substring(DATADOG_MESSAGE_PREFIX.length + 1));
|
|
19
20
|
} else {
|
|
20
21
|
userDefinedOnMessage === null || userDefinedOnMessage === void 0 ? void 0 : userDefinedOnMessage(event);
|
|
21
22
|
}
|
|
22
23
|
}, [userDefinedOnMessage]);
|
|
23
24
|
return /*#__PURE__*/React.createElement(RNWebView, _extends({}, props, {
|
|
24
25
|
onMessage: onMessage,
|
|
25
|
-
injectedJavaScriptBeforeContentLoaded: getInjectedJavaScriptBeforeContentLoaded(props.allowedHosts, props.injectedJavaScriptBeforeContentLoaded)
|
|
26
|
+
injectedJavaScriptBeforeContentLoaded: getInjectedJavaScriptBeforeContentLoaded(props.allowedHosts, props.injectedJavaScriptBeforeContentLoaded),
|
|
27
|
+
ref: ref
|
|
26
28
|
}));
|
|
27
29
|
};
|
|
30
|
+
|
|
31
|
+
export const WebView = /*#__PURE__*/forwardRef(WebViewComponent);
|
|
28
32
|
export default WebView;
|
|
33
|
+
/**
|
|
34
|
+
* We have to redefine the spec for the Native SDK here to be able to use the new architecture.
|
|
35
|
+
* We don't declare it in a separate file so we don't end up with a duplicate definition of the native module.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const NativeDdSdk = TurboModuleRegistry.get('DdSdk');
|
|
29
39
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["WebView","RNWebView","
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["WebView","RNWebView","TurboModuleRegistry","React","forwardRef","useCallback","DATADOG_MESSAGE_PREFIX","getInjectedJavaScriptBeforeContentLoaded","WebViewComponent","props","ref","userDefinedOnMessage","onMessage","event","message","nativeEvent","data","startsWith","NativeDdSdk","consumeWebviewEvent","substring","length","allowedHosts","injectedJavaScriptBeforeContentLoaded","get"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,OAAO,IAAIC,SAApB,QAAqC,sBAArC;AAEA,SAASC,mBAAT,QAAoC,cAApC;AACA,OAAOC,KAAP,IAAgBC,UAAhB,EAA4BC,WAA5B,QAA+C,OAA/C;AAEA,SACIC,sBADJ,EAEIC,wCAFJ,QAGO,sDAHP;;AAUA,MAAMC,gBAAgB,GAAG,CAACC,KAAD,EAAeC,GAAf,KAAoD;AACzE,QAAMC,oBAAoB,GAAGF,KAAK,CAACG,SAAnC;AACA,QAAMA,SAAS,GAAGP,WAAW,CACxBQ,KAAD,IAAgC;AAC5B,UAAMC,OAAO,GAAGD,KAAK,CAACE,WAAN,CAAkBC,IAAlC;;AACA,QAAIF,OAAO,CAACG,UAAR,CAAmBX,sBAAnB,CAAJ,EAAgD;AAC5CY,MAAAA,WAAW,SAAX,IAAAA,WAAW,WAAX,YAAAA,WAAW,CAAEC,mBAAb,CACIL,OAAO,CAACM,SAAR,CAAkBd,sBAAsB,CAACe,MAAvB,GAAgC,CAAlD,CADJ;AAGH,KAJD,MAIO;AACHV,MAAAA,oBAAoB,SAApB,IAAAA,oBAAoB,WAApB,YAAAA,oBAAoB,CAAGE,KAAH,CAApB;AACH;AACJ,GAVwB,EAWzB,CAACF,oBAAD,CAXyB,CAA7B;AAaA,sBACI,oBAAC,SAAD,eACQF,KADR;AAEI,IAAA,SAAS,EAAEG,SAFf;AAGI,IAAA,qCAAqC,EAAEL,wCAAwC,CAC3EE,KAAK,CAACa,YADqE,EAE3Eb,KAAK,CAACc,qCAFqE,CAHnF;AAOI,IAAA,GAAG,EAAEb;AAPT,KADJ;AAWH,CA1BD;;AA4BA,OAAO,MAAMV,OAAO,gBAAGI,UAAU,CAACI,gBAAD,CAA1B;AAEP,eAAeR,OAAf;AAEA;AACA;AACA;AACA;;AAIA,MAAMkB,WAAW,GAAGhB,mBAAmB,CAACsB,GAApB,CAAgD,OAAhD,CAApB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\nimport type { WebViewMessageEvent, WebViewProps } from 'react-native-webview';\nimport { WebView as RNWebView } from 'react-native-webview';\nimport type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\nimport React, { forwardRef, useCallback } from 'react';\n\nimport {\n DATADOG_MESSAGE_PREFIX,\n getInjectedJavaScriptBeforeContentLoaded\n} from './__utils__/getInjectedJavaScriptBeforeContentLoaded';\n\ntype Props = WebViewProps & {\n allowedHosts?: string[];\n injectedJavaScriptBeforeContentLoaded?: string;\n};\n\nconst WebViewComponent = (props: Props, ref: React.Ref<RNWebView<Props>>) => {\n const userDefinedOnMessage = props.onMessage;\n const onMessage = useCallback(\n (event: WebViewMessageEvent) => {\n const message = event.nativeEvent.data;\n if (message.startsWith(DATADOG_MESSAGE_PREFIX)) {\n NativeDdSdk?.consumeWebviewEvent(\n message.substring(DATADOG_MESSAGE_PREFIX.length + 1)\n );\n } else {\n userDefinedOnMessage?.(event);\n }\n },\n [userDefinedOnMessage]\n );\n return (\n <RNWebView\n {...props}\n onMessage={onMessage}\n injectedJavaScriptBeforeContentLoaded={getInjectedJavaScriptBeforeContentLoaded(\n props.allowedHosts,\n props.injectedJavaScriptBeforeContentLoaded\n )}\n ref={ref}\n />\n );\n};\n\nexport const WebView = forwardRef(WebViewComponent);\n\nexport default WebView;\n\n/**\n * We have to redefine the spec for the Native SDK here to be able to use the new architecture.\n * We don't declare it in a separate file so we don't end up with a duplicate definition of the native module.\n */\ninterface PartialNativeDdSdkSpec extends TurboModule {\n consumeWebviewEvent(message: string): Promise<void>;\n}\nconst NativeDdSdk = TurboModuleRegistry.get<PartialNativeDdSdkSpec>('DdSdk');\n"]}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { WebViewProps } from 'react-native-webview';
|
|
2
|
+
import { WebView as RNWebView } from 'react-native-webview';
|
|
3
|
+
import React from 'react';
|
|
2
4
|
declare type Props = WebViewProps & {
|
|
3
5
|
allowedHosts?: string[];
|
|
4
6
|
injectedJavaScriptBeforeContentLoaded?: string;
|
|
5
7
|
};
|
|
6
|
-
export declare const WebView: (
|
|
8
|
+
export declare const WebView: React.ForwardRefExoticComponent<import("react-native-webview/lib/WebViewTypes").IOSWebViewProps & import("react-native-webview/lib/WebViewTypes").AndroidWebViewProps & import("react-native-webview/lib/WebViewTypes").WindowsWebViewProps & {
|
|
9
|
+
allowedHosts?: string[] | undefined;
|
|
10
|
+
injectedJavaScriptBeforeContentLoaded?: string | undefined;
|
|
11
|
+
} & React.RefAttributes<RNWebView<Props>>>;
|
|
7
12
|
export default WebView;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native-webview",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-rc1",
|
|
4
4
|
"description": "A client-side React Native module to interact with react-native-webview and Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"main": "lib/commonjs/index",
|
|
24
24
|
"files": [
|
|
25
|
-
"src",
|
|
26
|
-
"lib"
|
|
25
|
+
"src/**",
|
|
26
|
+
"lib/**"
|
|
27
27
|
],
|
|
28
28
|
"types": "lib/typescript/index.d.ts",
|
|
29
29
|
"react-native": "src/index",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"prepare": "rm -rf lib && yarn bob build"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@testing-library/react-native": "7.0.2"
|
|
41
|
+
"@testing-library/react-native": "7.0.2",
|
|
42
|
+
"react-native-builder-bob": "0.17.1"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"@datadog/mobile-react-native": ">=1.5.0",
|
|
@@ -70,5 +71,5 @@
|
|
|
70
71
|
]
|
|
71
72
|
]
|
|
72
73
|
},
|
|
73
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "4fd80f04ddfde8becbe3a76fb94f3122091f0107"
|
|
74
75
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
import { fireEvent, render } from '@testing-library/react-native';
|
|
7
|
+
import type { WebView as RNWebView } from 'react-native-webview';
|
|
7
8
|
import { NativeModules } from 'react-native';
|
|
8
9
|
import React from 'react';
|
|
9
10
|
|
|
@@ -51,4 +52,13 @@ describe('WebView', () => {
|
|
|
51
52
|
DdMessage
|
|
52
53
|
);
|
|
53
54
|
});
|
|
55
|
+
it('forwards ref to the actual RN Webview component', async () => {
|
|
56
|
+
const ref = React.createRef<RNWebView>();
|
|
57
|
+
|
|
58
|
+
const { findByTestId } = render(
|
|
59
|
+
<WebView testID="webView" allowedHosts={[]} ref={ref} />
|
|
60
|
+
);
|
|
61
|
+
await findByTestId('webView');
|
|
62
|
+
expect(ref.current?.injectJavaScript).toBeDefined();
|
|
63
|
+
});
|
|
54
64
|
});
|
package/src/index.tsx
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { WebViewMessageEvent, WebViewProps } from 'react-native-webview';
|
|
7
7
|
import { WebView as RNWebView } from 'react-native-webview';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
8
|
+
import type { TurboModule } from 'react-native';
|
|
9
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
10
|
+
import React, { forwardRef, useCallback } from 'react';
|
|
10
11
|
|
|
11
12
|
import {
|
|
12
13
|
DATADOG_MESSAGE_PREFIX,
|
|
@@ -18,13 +19,13 @@ type Props = WebViewProps & {
|
|
|
18
19
|
injectedJavaScriptBeforeContentLoaded?: string;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
const WebViewComponent = (props: Props, ref: React.Ref<RNWebView<Props>>) => {
|
|
22
23
|
const userDefinedOnMessage = props.onMessage;
|
|
23
24
|
const onMessage = useCallback(
|
|
24
25
|
(event: WebViewMessageEvent) => {
|
|
25
26
|
const message = event.nativeEvent.data;
|
|
26
27
|
if (message.startsWith(DATADOG_MESSAGE_PREFIX)) {
|
|
27
|
-
|
|
28
|
+
NativeDdSdk?.consumeWebviewEvent(
|
|
28
29
|
message.substring(DATADOG_MESSAGE_PREFIX.length + 1)
|
|
29
30
|
);
|
|
30
31
|
} else {
|
|
@@ -41,8 +42,20 @@ export const WebView = (props: Props) => {
|
|
|
41
42
|
props.allowedHosts,
|
|
42
43
|
props.injectedJavaScriptBeforeContentLoaded
|
|
43
44
|
)}
|
|
45
|
+
ref={ref}
|
|
44
46
|
/>
|
|
45
47
|
);
|
|
46
48
|
};
|
|
47
49
|
|
|
50
|
+
export const WebView = forwardRef(WebViewComponent);
|
|
51
|
+
|
|
48
52
|
export default WebView;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* We have to redefine the spec for the Native SDK here to be able to use the new architecture.
|
|
56
|
+
* We don't declare it in a separate file so we don't end up with a duplicate definition of the native module.
|
|
57
|
+
*/
|
|
58
|
+
interface PartialNativeDdSdkSpec extends TurboModule {
|
|
59
|
+
consumeWebviewEvent(message: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
const NativeDdSdk = TurboModuleRegistry.get<PartialNativeDdSdkSpec>('DdSdk');
|