설치
yarn add react-native-webview
npm i react-native-webview사용법
import WebView from 'react-native-webview';
import { Platform, StatusBar, SafeAreaView } from 'react-native';
const os = Platform.OS;
const barStyle = os === 'ios' ? 'dark-content' : 'light-content';
export default function() {
return (
<>
<StatusBar barStyle={barStyle} />
<SafeAreaView style={{ flex: 1 }}>
<WebView
source={{uri: 'https://google.com'}}
allowsInlineMediaPlayback={true}
style={{ flex: 1 }}
/>
</SafeAreaView>
</>
);
}<StatusBar />는 상단바의 디자인을 위해서 추가<SafeAreaView />가 없으면 iOS에서 상단바 영역까지 컨텐츠가 나온다.allowsInlineMediaPlayback속성의true값은 화면에 영상이 있을 경우 iOS에서 영상이 전체화면으로 켜지는 것을 방지해준다. (default:false)모두
style을flex: 1준 이유는 웹뷰를 전체 화면으로 보기 위함이다.