From a36994eb3ed9f4a83f82e0ed0d9d0b2662dfb233 Mon Sep 17 00:00:00 2001 From: tony chen Date: Fri, 3 Dec 2021 17:26:13 +0800 Subject: [PATCH] fix: update rn rich text height on load again (#10807) --- .../__tests__/__snapshots__/richText.spec.tsx.snap | 2 ++ .../taro-components-rn/src/components/RichText/index.tsx | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/packages/taro-components-rn/__tests__/__snapshots__/richText.spec.tsx.snap b/packages/taro-components-rn/__tests__/__snapshots__/richText.spec.tsx.snap index a9160fc20bfd..5dcc5fa19f04 100644 --- a/packages/taro-components-rn/__tests__/__snapshots__/richText.spec.tsx.snap +++ b/packages/taro-components-rn/__tests__/__snapshots__/richText.spec.tsx.snap @@ -28,6 +28,7 @@ exports[`RichText RichText render 1`] = ` document.body.style.padding = 0; document.body.style.margin = 0; window.ReactNativeWebView.postMessage(document.body.scrollHeight); + true; " injectedJavaScriptBeforeContentLoadedForMainFrameOnly={true} injectedJavaScriptForMainFrameOnly={true} @@ -35,6 +36,7 @@ exports[`RichText RichText render 1`] = ` messagingEnabled={true} onContentProcessDidTerminate={[Function]} onHttpError={[Function]} + onLoadEnd={[Function]} onLoadingError={[Function]} onLoadingFinish={[Function]} onLoadingProgress={[Function]} diff --git a/packages/taro-components-rn/src/components/RichText/index.tsx b/packages/taro-components-rn/src/components/RichText/index.tsx index f0835bb5ea53..542cb75aeb9a 100644 --- a/packages/taro-components-rn/src/components/RichText/index.tsx +++ b/packages/taro-components-rn/src/components/RichText/index.tsx @@ -21,6 +21,8 @@ class _RichText extends React.Component { webViewHeight: 0 } + private webview = React.createRef() + renderChildrens = (arr: Array = []): JSX.Element[] | undefined => { if (arr.length === 0) return return arr.map((list) => { @@ -76,6 +78,7 @@ class _RichText extends React.Component { width: '100%', }, style)}> ' + html }} scalesPageToFit={false} onMessage={this.onWebViewMessage} @@ -85,7 +88,9 @@ class _RichText extends React.Component { document.body.style.padding = 0; document.body.style.margin = 0; window.ReactNativeWebView.postMessage(document.body.scrollHeight); + true; `} + onLoadEnd={() => this.webview.current?.injectJavaScript('window.ReactNativeWebView.postMessage(document.body.scrollHeight);')} // android style={{ backgroundColor: 'transparent' }}