Skip to content

Commit 69dec50

Browse files
committed
Handle ready event in ContentpassLayer
1 parent 7838d8f commit 69dec50

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { StyleSheet, Text, View } from 'react-native';
22
import { WebView, type WebViewMessageEvent } from 'react-native-webview';
33
import type { ContentpassLayerEvents } from './ContentpassLayerEvents';
44
import buildFirstLayerUrl from './buildFirstLayerUrl';
5-
import { useMemo } from 'react';
5+
import { useMemo, useState } from 'react';
66

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

@@ -70,6 +70,8 @@ export default function ContentpassLayer({
7070
});
7171
}, [baseUrl, planId, propertyId, purposesList, vendorCount]);
7272

73+
const [ready, setReady] = useState(false);
74+
7375
function handleMessage(event: WebViewMessageEvent) {
7476
let msg: any;
7577
try {
@@ -92,8 +94,12 @@ export default function ContentpassLayer({
9294
console.debug('WebView message', msg);
9395

9496
switch (msg.action) {
97+
case 'FIRST_LAYER_READY':
98+
setReady(true);
99+
break;
95100
case 'ENABLE_SCROLL_ON_PROPERTY':
96-
// Ignore this message
101+
case 'DISABLE_SCROLL_ON_PROPERTY':
102+
// ignore these messages
97103
break;
98104
case 'GO_TO':
99105
switch (msg.payload?.options?.page) {
@@ -142,7 +148,7 @@ export default function ContentpassLayer({
142148
<View style={styles.container}>
143149
<WebView
144150
source={{ uri: firstLayerUrl }}
145-
style={styles.webview}
151+
style={[styles.webview, !ready && { opacity: 0 }]}
146152
originWhitelist={['*']}
147153
startInLoadingState
148154
javaScriptEnabled

0 commit comments

Comments
 (0)