Skip to content

Commit

Permalink
fix: android freeze crash (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm authored Oct 21, 2022
1 parent 382b6a6 commit 824c121
Showing 1 changed file with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,35 +22,40 @@ const WebContent: FC<WebTab> = ({ id, url }) => {
const showHome =
(id === 'home' && webHandler === 'tabbedWebview') || url === '';

return (
<>
<Freeze freeze={!showHome}>
<DiscoverHome
onItemSelect={(dapp) => {
openMatchDApp({ id: dapp._id, dapp });
}}
onItemSelectHistory={openMatchDApp}
/>
</Freeze>
<Freeze freeze={showHome}>
<WebView
src={url}
onWebViewRef={(ref) => {
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
/>
</Freeze>
</>
const discoverHome = useMemo(
() => (
<DiscoverHome
onItemSelect={(dapp) => {
openMatchDApp({ id: dapp._id, dapp });
}}
onItemSelectHistory={openMatchDApp}
/>
),
[openMatchDApp],
);

const webview = useMemo(
() => (
<WebView
src={url || 'about:blank'}
onWebViewRef={(ref) => {
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';
Expand Down

0 comments on commit 824c121

Please sign in to comment.