1- import { StyleSheet , Text , View } from 'react-native' ;
1+ import { ActivityIndicator , StyleSheet , Text , View } from 'react-native' ;
22import { WebView , type WebViewMessageEvent } from 'react-native-webview' ;
33import type { ContentpassLayerEvents } from './ContentpassLayerEvents' ;
44import buildFirstLayerUrl from './buildFirstLayerUrl' ;
55import { useMemo , useState } from 'react' ;
66
77const MESSAGE_PROTOCOL = 'contentpass-first-layer' ;
88
9- const DISABLE_ANIMATIONS_JS = `
9+ const EARLY_INJECT_JS = `
1010 (function () {
1111 var style = document.createElement('style');
1212 style.textContent = '*, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; } main, .backdrop { visibility: visible !important; transform: none !important; }';
1313 (document.head || document.documentElement).appendChild(style);
1414
15- true;
16- })();
17- ` ;
18-
19- const GLUE_CODE_JS = `
20- (function () {
21- const originalPostMessage = window.postMessage;
15+ var originalPostMessage = window.postMessage;
2216 window.postMessage = function (data) {
2317 try {
2418 window.ReactNativeWebView.postMessage(
@@ -37,7 +31,7 @@ const GLUE_CODE_JS = `
3731const styles = StyleSheet . create ( {
3832 container : {
3933 flex : 1 ,
40- backgroundColor : 'transparent ' ,
34+ backgroundColor : '#fff ' ,
4135 } ,
4236 webview : {
4337 flex : 1 ,
@@ -53,6 +47,11 @@ const styles = StyleSheet.create({
5347 fontSize : 14 ,
5448 textAlign : 'center' ,
5549 } ,
50+ loading : {
51+ ...StyleSheet . absoluteFillObject ,
52+ alignItems : 'center' ,
53+ justifyContent : 'center' ,
54+ } ,
5655} ) ;
5756
5857export default function ContentpassLayer ( {
@@ -163,8 +162,7 @@ export default function ContentpassLayer({
163162 javaScriptEnabled
164163 domStorageEnabled
165164 automaticallyAdjustContentInsets = { false }
166- injectedJavaScriptBeforeContentLoaded = { DISABLE_ANIMATIONS_JS }
167- injectedJavaScript = { GLUE_CODE_JS }
165+ injectedJavaScriptBeforeContentLoaded = { EARLY_INJECT_JS }
168166 onMessage = { ( event ) => {
169167 handleMessage ( event ) ;
170168 } }
@@ -195,6 +193,11 @@ export default function ContentpassLayer({
195193 </ View >
196194 ) }
197195 />
196+ { ! ready && (
197+ < View style = { styles . loading } >
198+ < ActivityIndicator size = "large" />
199+ </ View >
200+ ) }
198201 </ View >
199202 ) ;
200203}
0 commit comments