Skip to content

Commit

Permalink
move webview specific callbacks to TopBar
Browse files Browse the repository at this point in the history
  • Loading branch information
chabroA committed Jul 11, 2022
1 parent 4bb456d commit 62b87e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,17 @@ export type Props = {
onReload: Function,
onClose?: Function,
onHelp?: Function,
onOpenDevTools: Function,
onGoBack: Function,
onGoForward: Function,
config?: TopBarConfig,
webview: WebviewTag,
};

const WebPlatformTopBar = ({
manifest,
onReload,
onHelp,
onClose,
onOpenDevTools,
onGoBack,
onGoForward,
config = {},
webview,
}: Props) => {
const { name, icon } = manifest;

Expand All @@ -146,6 +142,24 @@ const WebPlatformTopBar = ({
dispatch(openPlatformAppInfoDrawer({ manifest }));
}, [manifest, dispatch]);

const onOpenDevTools = useCallback(() => {
if (webview) {
webview.openDevTools();
}
}, [webview]);

const onGoBack = useCallback(() => {
if (webview) {
webview.goBack();
}
}, [webview]);

const onGoForward = useCallback(() => {
if (webview) {
webview.goForward();
}
}, [webview]);

return (
<Container>
{shouldDisplayName && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,40 +532,14 @@ const WebPlatformPlayer = ({ manifest, onClose, inputs, config }: Props) => {
};
}, [handleLoad, handleNewWindow]);

const handleOpenDevTools = useCallback(() => {
const webview = targetRef.current;

if (webview) {
webview.openDevTools();
}
}, []);

const handleGoBack = useCallback(() => {
const webview = targetRef.current;

if (webview) {
webview.goBack();
}
}, []);

const handleGoForward = useCallback(() => {
const webview = targetRef.current;

if (webview) {
webview.goForward();
}
}, []);

return (
<Container>
<TrackPage category="Platform" name="App" appId={manifest.id} params={inputs} />
<TopBar
manifest={manifest}
onReload={handleReload}
onClose={onClose}
onOpenDevTools={handleOpenDevTools}
onGoBack={handleGoBack}
onGoForward={handleGoForward}
webview={targetRef.current}
config={config?.topBarConfig}
/>

Expand Down

0 comments on commit 62b87e1

Please sign in to comment.