Solve Problem/React Native
[React Native] WebView 사용법
안다희
2020. 5. 11. 13:52
728x90
1. 라이브러리
https://github.com/react-native-community/react-native-webview
react-native-community/react-native-webview
React Native Cross-Platform WebView. Contribute to react-native-community/react-native-webview development by creating an account on GitHub.
github.com
2. 설치
https://github.com/react-native-community/react-native-webview/blob/master/docs/Getting-Started.md
react-native-community/react-native-webview
React Native Cross-Platform WebView. Contribute to react-native-community/react-native-webview development by creating an account on GitHub.
github.com
yarn add react-native-webview
rn 0.60 이상이므로 pod install만! (android는 할 필요 x)
pod install
3. Usage
import React, {useState} from 'react';
import {ActivityIndicator} from 'react-native';
import {WebView} from 'react-native-webview';
export default ({route}) => {
const {uri, title} = route.params;
const [loading, setLoading] = useState(true);
return (
<>
{loading && (
<ActivityIndicator color={theme.mint} style={{marginTop: 20}} />
)}
<WebView
source={{uri}}
onLoadEnd={() => setLoading(false)}
renderLoading={() => <ActivityIndicator color="blue" />}
/>
</>
);
};