[英]How to show local html in React Native WebView without react-native-static-server or similar?
In React Native project, I have html document in src directory.在 React Native 项目中,我在 src 目录中有 html 文档。 (Assuming that it named "./src/green.html"). (假设它命名为“./src/green.html”)。
And In MyScreen, I have a WebView for showing this page.在 MyScreen 中,我有一个 WebView 用于显示此页面。
import WebView from 'react-native-webview';
import { Text, View, StyleSheet, Image } from 'react-native';
export default MyScreen (props) {
const source = require('./green.html');
const webviewSOurce = Image.resolveAssetSource(source);
return (
<View style>
<WebView
source={webSource}
originWhitelist={["*"]}
style={{
width:'100%',
minHeight:400
}}/>
</View>
)
}
But it shows the content of html file as a plain text, not html.但它将 html 文件的内容显示为纯文本,而不是 html。
<div id="main-div">
<h1>Hello World! I am alive!</h1>
</div>
I visited https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#loading-local-html-files , but I can't get a clear image and react-native-http-server causes some issues on my app.我访问了https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#loading-local-html-files ,但我无法获得清晰的图像和react-native-http-server 导致我的应用出现一些问题。
How can I deal it?我该如何处理? Is there any alternative ways to show local html page in WebView without react-native-static-server or react-native-http-server?有没有其他方法可以在没有 react-native-static-server 或 react-native-http-server 的情况下在 WebView 中显示本地 html 页面?
I am pretty bad at react, but stumbled across this a couple days ago trying to do the same thing.我的反应很糟糕,但几天前偶然发现了这个,试图做同样的事情。 It's kinda long, so i'll just put the url.有点长,我就放个网址吧。 https://aboutreact.com/load-local-html-file-url-using-react-native-webview/ https://aboutreact.com/load-local-html-file-url-using-react-native-webview/
The original react-native-static-server is probably causing problems because it is long abandoned by its creators, and broken for latest React Native versions.原始的react-native-static-server可能会导致问题,因为它已被其创建者长期遗弃,并且已被最新的 React Native 版本破坏。 Good news and shameless self-promo, I maintain and further develop its fork — check it out: @dr.pogodin/react-native-static-server .好消息和无耻的自我宣传,我维护并进一步开发它的分支——查看: @dr.pogodin/react-native-static-server 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.