From 824c121a99e2c4c29ae8d972f3537daee9c654a7 Mon Sep 17 00:00:00 2001 From: Sunny Luo Date: Fri, 21 Oct 2022 14:58:58 +0800 Subject: [PATCH] fix: android freeze crash (#1813) --- .../Explorer/Content/WebContent.native.tsx | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/packages/kit/src/views/Discover/Explorer/Content/WebContent.native.tsx b/packages/kit/src/views/Discover/Explorer/Content/WebContent.native.tsx index 64b00639d14..1f9b584d4bc 100644 --- a/packages/kit/src/views/Discover/Explorer/Content/WebContent.native.tsx +++ b/packages/kit/src/views/Discover/Explorer/Content/WebContent.native.tsx @@ -1,6 +1,5 @@ -import { FC, useState } from 'react'; +import { FC, useMemo, useState } from 'react'; -import { Freeze } from 'react-freeze'; import { WebViewNavigation } from 'react-native-webview/lib/WebViewTypes'; import WebView from '@onekeyhq/kit/src/components/WebView'; @@ -23,35 +22,40 @@ const WebContent: FC = ({ id, url }) => { const showHome = (id === 'home' && webHandler === 'tabbedWebview') || url === ''; - return ( - <> - - { - openMatchDApp({ id: dapp._id, dapp }); - }} - onItemSelectHistory={openMatchDApp} - /> - - - { - const { dispatch } = backgroundApiProxy; - if (ref && ref.innerRef) { - webviewRefs[id] = ref; - dispatch(setWebTabData({ id, refReady: true })); - } else { - delete webviewRefs[id]; - dispatch(setWebTabData({ id, refReady: false })); - } - }} - onNavigationStateChange={setNavigationStateChangeEvent} - allowpopups - /> - - + const discoverHome = useMemo( + () => ( + { + openMatchDApp({ id: dapp._id, dapp }); + }} + onItemSelectHistory={openMatchDApp} + /> + ), + [openMatchDApp], ); + + const webview = useMemo( + () => ( + { + const { dispatch } = backgroundApiProxy; + if (ref && ref.innerRef) { + webviewRefs[id] = ref; + dispatch(setWebTabData({ id, refReady: true })); + } else { + delete webviewRefs[id]; + dispatch(setWebTabData({ id, refReady: false })); + } + }} + onNavigationStateChange={setNavigationStateChangeEvent} + allowpopups + /> + ), + [id, url], + ); + + return showHome ? discoverHome : webview; }; WebContent.displayName = 'WebContent';