react-native - React Native)如何使用 React Native Expo 显示网站?
问题描述
我正在尝试使用 React Native Web 构建一个网站,并且一直在尝试使用 Expo 显示我的网站。我的期望是,当我单击“在网络浏览器中运行”时,我将能够看到它(它应该打开一个带有介绍文本的空白页面),但它只会返回到 Expo 页面。我究竟做错了什么?
解决方案
您可以使用 WebView 在 React Native Expo 应用程序上显示网页。
首先,通过这个命令安装 react-native-webview。
expo install react-native-webview
然后你可以添加这个 WebView,如下所示。
import * as React from 'react';
import { WebView } from 'react-native-webview';
export default function App() {
return (
<WebView
style={styles.container}
source={{ uri: 'https://expo.dev' }}
/>
);
}
您还可以像这样插入自定义 Web (html) 页面:
import * as React from 'react';
import { WebView } from 'react-native-webview';
export default function App() {
return (
<WebView
style={styles.container}
originWhitelist={['*']}
source={{ html: '<h1><center>Hello world</center></h1>' }}
/>
);
}
要了解更多信息,您可以阅读此 doc expo webview
推荐阅读
- javascript - 是否可以通过选定的 JS 用户强制其他人离开 Twilio VIdeo 房间?
- html - Apps 脚本:将 HTML 文本复制到 doc 并保持格式
- python - Spyder 4.0.1(python 3.7) 无法从 Qt 设计器自动生成的模块导入类 Ui_MainWindow
- javascript - SlickGrid 没有 renderComplete 事件。是否有一个事件会在所有渲染完成后触发
- android - 在 Kotlin 和 RX observable 中手动创建对象的 observable
- reactjs - ReactJS 在 XHR 回调上更新状态
- python - 生成器表达式和任何/全部的意外结果
- firebase - Firebase 服务工作,但 Firebase 部署得到部署错误
- reactjs - 发布请求后重置 redux 存储中数据的正确方法是什么?
- google-apps-script - 来自不同电子表格的数据验证范围与 onEdit 触发器