Skip to content

Commit

Permalink
use setActive method on webview
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 committed Nov 25, 2024
1 parent 71cb10f commit 901d918
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/components/DappBrowser/BrowserTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ const FreezableWebViewComponent = ({
try {
// validate message and parse data
const parsedData = typeof data === 'string' ? JSON.parse(data) : data;
parsedData?.jsEnabled && console.log(parsedData);
if (!parsedData || (!parsedData.topic && !parsedData.payload)) return;

if (parsedData.topic === 'websiteMetadata') {
Expand Down Expand Up @@ -258,7 +257,6 @@ const FreezableWebViewComponent = ({
(event: WebViewEvent) => {
if (event.nativeEvent.loading) return;
const { origin } = new URL(event.nativeEvent.url);
console.log('======> handleOnLoad', origin);

if (typeof webViewRef !== 'function' && webViewRef?.current) {
if (!webViewRef?.current) {
Expand Down Expand Up @@ -348,39 +346,28 @@ const FreezableWebViewComponent = ({
if (webViewRef?.current) {
if (isActiveTab) {
webViewRef.current.injectJavaScript(unfreezeWebsite);
webViewRef.current.setActive(true);
} else {
webViewRef.current.injectJavaScript(freezeWebsite);
webViewRef.current.setActive(false);
}
}
}, [isActiveTab, webViewRef]);

console.log(
'======> rendered tab ',
JSON.stringify(
{
tabId,
tabUrl,
isActiveTab,
javaScriptEnabled: isActiveTab,
},
null,
2
)
);

return (
<TabWebView
onContentProcessDidTerminate={handleOnContentProcessDidTerminate}
onLoad={handleOnLoad}
onLoadProgress={handleOnLoadProgress}
onMessage={handleOnMessage}
onNavigationStateChange={handleNavigationStateChange}
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
ref={webViewRef}
source={{ uri: tabUrl }}
javaScriptEnabled={isActiveTab}
onOpenWindow={handleOnOpenWindow}
/>
<Freeze freeze={!isActiveTab}>
<TabWebView
onContentProcessDidTerminate={handleOnContentProcessDidTerminate}
onLoad={handleOnLoad}
onLoadProgress={handleOnLoadProgress}
onMessage={handleOnMessage}
onNavigationStateChange={handleNavigationStateChange}
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
ref={webViewRef}
source={{ uri: tabUrl }}
onOpenWindow={handleOnOpenWindow}
/>
</Freeze>
);
};

Expand Down

0 comments on commit 901d918

Please sign in to comment.