-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
54 lines (46 loc) · 1.34 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, {createRef, useEffect} from 'react';
import SplashScreen from 'react-native-splash-screen';
import WebView from 'react-native-webview';
const App = () => {
const uri = 'https://sullog-client.vercel.app/';
let webViewRef = createRef<WebView>();
useEffect(() => {
SplashScreen.hide();
}, []);
const debugging = `
const consoleLog = (type, log) => window.ReactNativeWebView.postMessage(JSON.stringify({'type': 'Console', 'data': {'type': type, 'log': log}}));
console = {
log: (log) => consoleLog('log', log),
debug: (log) => consoleLog('debug', log),
info: (log) => consoleLog('info', log),
warn: (log) => consoleLog('warn', log),
error: (log) => consoleLog('error', log),
};
`;
const onMessage = (payload: {nativeEvent: {data: string}}) => {
let dataPayload;
try {
dataPayload = JSON.parse(payload.nativeEvent.data);
} catch (e) {}
if (dataPayload) {
if (dataPayload.type === 'Console') {
console.info(`[Console] ${JSON.stringify(dataPayload.data)}`);
} else {
console.log(dataPayload);
}
}
};
return (
<WebView
ref={webViewRef}
source={{
uri,
}}
injectedJavaScript={debugging}
onMessage={onMessage}
thirdPartyCookiesEnabled
sharedCookiesEnabled
/>
);
};
export default App;