Develop/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" />}
      />
    </>
  );
};

 

 

Buy Me A Coffee!

https://www.buymeacoffee.com/daheeahn

 

daheeahn is app developer

Hey 👋 I just created a page here. You can now buy me a coffee!

www.buymeacoffee.com

 

출처: https://mingos-habitat.tistory.com/34 [밍고의서식지:티스토리]