Skip to content

Commit da8c265

Browse files
committed
Simplify URL loading in ContentpassLayer
1 parent f7a937d commit da8c265

1 file changed

Lines changed: 3 additions & 15 deletions

File tree

packages/react-native-contentpass-ui/src/components/ContentpassLayer.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ import { useMemo } from 'react';
66

77
const MESSAGE_PROTOCOL = 'contentpass-first-layer';
88

9-
const buildGlueCodeJs = (firstLayerUrl: string) => `
9+
const GLUE_CODE_JS = `
1010
(function () {
11-
try {
12-
if (!window.location.href || window.location.href === 'about:blank') {
13-
var encodedUrl = '${encodeURIComponent(firstLayerUrl)}';
14-
var decodedUrl = decodeURIComponent(encodedUrl);
15-
window.location.href = decodedUrl;
16-
}
17-
} catch (e) {}
18-
1911
const originalPostMessage = window.postMessage;
2012
window.postMessage = function (data) {
2113
try {
@@ -78,10 +70,6 @@ export default function ContentpassLayer({
7870
});
7971
}, [baseUrl, planId, propertyId, purposesList, vendorCount]);
8072

81-
const glueCodeJs = useMemo(() => {
82-
return buildGlueCodeJs(firstLayerUrl);
83-
}, [firstLayerUrl]);
84-
8573
function handleMessage(event: WebViewMessageEvent) {
8674
let msg: any;
8775
try {
@@ -153,13 +141,13 @@ export default function ContentpassLayer({
153141
return (
154142
<View style={styles.container}>
155143
<WebView
156-
source={{ html: '' }}
144+
source={{ uri: firstLayerUrl }}
157145
style={styles.webview}
158146
originWhitelist={['*']}
159147
startInLoadingState
160148
javaScriptEnabled
161149
domStorageEnabled
162-
injectedJavaScript={glueCodeJs}
150+
injectedJavaScript={GLUE_CODE_JS}
163151
onMessage={(event) => {
164152
handleMessage(event);
165153
}}

0 commit comments

Comments
 (0)