备注:我是 的作者react-native-render-html。此问题出于教育目的,符合 StackOverflow 政策。
我在组件RenderHtml中渲染组件,WebDisplay如下所示:
import * as React from 'react';
import {ScrollView, StyleSheet, Text, useWindowDimensions} from 'react-native';
import RenderHtml from 'react-native-render-html';
const html = '<div>Hello world!</div>';
function WebDisplay({html}) {
const {width: contentWidth} = useWindowDimensions();
const tagsStyles = {
a: {
textDecorationLine: 'none',
},
};
return (
<RenderHtml
contentWidth={contentWidth}
source={{html}}
tagsStyles={tagsStyles}
/>
);
}
export default function App() {
const [isToastVisible, setIsToastVisible] = React.useState(false);
React.useEffect(function flipToast() {
const timeout = setTimeout(() => …Run Code Online (Sandbox Code Playgroud) 今天我尝试使用这个库在我的 React Native 应用程序中渲染原始 html。这是我的代码:
\nimport HTML from "react-native-render-html";\nconst htmlContent = `\n<div class="page" title="Page 5">\n<div class="layoutArea">\n<div class="column">\n<p><span style="font-size: 11.000000pt; font-family: 'TimesNewRomanPSMT';">Châ\xcc\x81t X (C</span><span style="font-size: 7.000000pt; font-family: 'TimesNewRomanPSMT'; vertical-align: -1.000000pt;">x</span><span style="font-size: 11.000000pt; font-family: 'TimesNewRomanPSMT';">H</span><span style="font-size: 7.000000pt; font-family: 'TimesNewRomanPSMT'; vertical-align: -1.000000pt;">y</span><span style="font-size: 11.000000pt; font-family: 'TimesNewRomanPSMT';">O</span><span style="font-size: 7.000000pt; font-family: 'TimesNewRomanPSMT'; vertical-align: -1.000000pt;">4</span><span style="font-size: 11.000000pt; font-family: 'TimesNewRomanPSMT';">N</span><span style="font-size: 7.000000pt; font-family: 'TimesNewRomanPSMT'; vertical-align: -1.000000pt;">2</span><span style="font-size: 11.000000pt; font-family: 'TimesNewRomanPSMT';">) la\xcc\x80 muô\xcc\x81i amoni cu\xcc\x89a axit cacboxylic \xc4\x91a ch\xc6\xb0\xcc\x81c; châ\xcc\x81t Y (C</span><span style="font-size: 7.000000pt; font-family: 'TimesNewRomanPSMT'; vertical-align: …Run Code Online (Sandbox Code Playgroud) 当在 中启用屏幕react-native-screens,并且有一个屏幕呈现一个<HTML />通过iframeHTML 元素传递的组件时,应用程序会在按下后退按钮返回主屏幕时崩溃。完整再现这里。
07-29 17:41:49.173 6901 6901 F crashpad: dlopen: dlopen failed: library "libandroidicu.so" not found: needed by /system/lib/libharfbuzz_ng.so in namespace (default)
--------- beginning of crash
07-29 17:41:49.176 6410 6441 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c in tid 6441 (RenderThread), pid 6410 (com.newmednav)
07-29 17:41:49.340 6904 6904 F DEBUG : *** *** *** *** …Run Code Online (Sandbox Code Playgroud) 我正在使用 4.2.2 版本react-native-render-html。鉴于以下片段:
# App.js
import React from 'react';
import HTML from 'react-native-render-html';
export default function App() {
return (
<HTML html='<a href="https://duckduckgo.com/">A Link To Press</a>' />
);
}
Run Code Online (Sandbox Code Playgroud)
我希望当我按下链接时网络浏览器会打开,但什么也没有发生。
我正在使用react-native-render-html 来渲染html。该renderers方法允许我提供自定义函数来呈现特定标签。不过,我想使用源代码中的原始内部 HTML 将子组件替换为我的自定义组件。
考虑。我向组件提供了以下 html 片段<HTML />:
<a> <b> <c meta="xyz"> Some text </c> <b> </a>
Run Code Online (Sandbox Code Playgroud)
我有一个自定义渲染器,它返回一个接受 html 字符串的组件,并用它做了一些魔法:
const renderers = {
c: () => (
<Custom html={/** how do I get "<c meta="xyz"> Some text </c>"? */} />
)
}
Run Code Online (Sandbox Code Playgroud)