🖥️프론트엔드/React Native
리액트 네이티브 - WebView 자바스크립트 조작 & WebView와 앱 메시지 전달
Janger
2022. 10. 21. 01:21
728x90
import * as React from 'react';
import { WebView } from 'react-native-webview';
import { StyleSheet } from 'react-native';
import Constants from 'expo-constants';
export default function App() {
return (
<WebView
style={styles.container}
source={{ uri: 'https://expo.dev' }}
javaScriptEnabled={true}
injectedJavaScript={"document.body.innerHTML = \"abc\";window.ReactNativeWebView.postMessage(document.body.innerHTML)"}
onMessage={(event)=>{console.log(event.nativeEvent.data)}}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: Constants.statusBarHeight,
},
});
참고:
https://docs.expo.dev/versions/latest/sdk/webview/
WebView - Expo Documentation
Expo is an open-source platform for making universal native apps for Android, iOS, and the web with JavaScript and React.
docs.expo.dev
Communicating between React Native and the WebView
Our current WorkSimple app in production is a Cordova hybrid app which means that our UI is web based. We are putting in a lot of effort…
medium.com
https://stackoverflow.com/questions/68451589/react-native-webview-onmessage-is-not-triggered
React Native WebView onMessage() is not triggered
I have a static site hosted on S3 with CloudFront distro on top of it. <WebView ref={webViewRef} scrollEnabled={false} source={{ uri: Config.REMOTE_URL }} // CloudFront URL
stackoverflow.com
728x90