ERROR: Youtube link inside html text inside react native app
ERROR: Youtube link inside html text inside react native app
我的一些 html 代码在我的应用程序中呈现时遇到问题。
我正在获取它并将 html 代码保存在 this.state.text_ 中:
return fetch('https://www.rallyssimo.it/wp-json/wp/v2/posts/'+_links)
.then(response => response.json())
.then(responseJson => {
this.setState(
{
text_: responseJson.content.rendered,
},
function() {}
);
})
.catch(error => {
console.error(error);
});
如果我将其打印在 <Text>
标签中,它会正确显示(显然是 html 标签)。
但是当我尝试使用 react-native-html-render 库渲染它时,如果有一个 youtube 视频的标签,我得到一个错误:invariant violation: WebView has been removed from react native... etc..."
.
<HTML html={this.state.text_} />
我没有在我的代码中使用 WebView,所以我认为它用在了 react-native-html-render 库中。
我还尝试使用 react-native-webview 库来呈现 html 代码
<WebView
source={{ html: this.state.text_ }}
/>
但是我得到了一个白屏
目前您对此无能为力,webView 已从 react-native
中删除,而 react-native-html-render
库尚未更新。修复后的PR已经合并到master中,后续会在npm上测试发布
这是一个未解决的问题:https://github.com/archriss/react-native-render-html/issues/265
作为等待 pkg 更新时的临时修复,您可以
- 将 pkg 版本更改为带有修复程序的 PR
"react-native-render-html": "^4.1.2"
到
"react-native-render-html": "git+https://github.com/chr314/react-native-render-html.git"
手动安装
npm install --save react-native-webview react-native link react-native-webview
然后在插件文件夹中,转到 src/HTMLRenderers.js
,删除 {..} 中的 WebView 'react-native';
并添加这一行
import {WebView} from 'react-native-webview';
我的一些 html 代码在我的应用程序中呈现时遇到问题。
我正在获取它并将 html 代码保存在 this.state.text_ 中:
return fetch('https://www.rallyssimo.it/wp-json/wp/v2/posts/'+_links)
.then(response => response.json())
.then(responseJson => {
this.setState(
{
text_: responseJson.content.rendered,
},
function() {}
);
})
.catch(error => {
console.error(error);
});
如果我将其打印在 <Text>
标签中,它会正确显示(显然是 html 标签)。
但是当我尝试使用 react-native-html-render 库渲染它时,如果有一个 youtube 视频的标签,我得到一个错误:invariant violation: WebView has been removed from react native... etc..."
.
<HTML html={this.state.text_} />
我没有在我的代码中使用 WebView,所以我认为它用在了 react-native-html-render 库中。
我还尝试使用 react-native-webview 库来呈现 html 代码
<WebView
source={{ html: this.state.text_ }}
/>
但是我得到了一个白屏
目前您对此无能为力,webView 已从 react-native
中删除,而 react-native-html-render
库尚未更新。修复后的PR已经合并到master中,后续会在npm上测试发布
这是一个未解决的问题:https://github.com/archriss/react-native-render-html/issues/265
作为等待 pkg 更新时的临时修复,您可以
- 将 pkg 版本更改为带有修复程序的 PR
"react-native-render-html": "^4.1.2"
到
"react-native-render-html": "git+https://github.com/chr314/react-native-render-html.git"
手动安装
npm install --save react-native-webview react-native link react-native-webview
然后在插件文件夹中,转到 src/HTMLRenderers.js
,删除 {..} 中的 WebView 'react-native';
并添加这一行
import {WebView} from 'react-native-webview';