React Native - WebView



在本章中,我們將學習如何使用 WebView。它用於在移動應用中內嵌網頁。

使用 WebView

HomeContainer 將成為一個容器元件。

App.js

import React, { Component } from 'react'
import WebViewExample from './web_view_example.js'

const App = () => {
   return (
      <WebViewExample/>
   )
}
export default App;

讓我們在 src/components/home 資料夾中建立一個名為 WebViewExample.js 的新檔案。

web_view_example.js

import React, { Component } from 'react'
import { View, WebView, StyleSheet }

from 'react-native'
const WebViewExample = () => {
   return (
      <View style = {styles.container}>
         <WebView
         source = {{ uri:
         'https://www.google.com/?gws_rd=cr,ssl&ei=SICcV9_EFqqk6ASA3ZaABA#q=tutorialspoint' }}
         />
      </View>
   )
}
export default WebViewExample;

const styles = StyleSheet.create({
   container: {
      height: 350,
   }
})

以上程式將生成以下輸出。

React Native WebView
廣告