diff --git a/src/screens/WebviewScreen/WebviewScreen.tsx b/src/screens/WebviewScreen/WebviewScreen.tsx index b11cbb2b1..bd9013af4 100644 --- a/src/screens/WebviewScreen/WebviewScreen.tsx +++ b/src/screens/WebviewScreen/WebviewScreen.tsx @@ -2,6 +2,7 @@ import React, { useRef, useState } from 'react'; import WebView, { WebViewNavigation } from 'react-native-webview'; import { ProgressBar } from 'react-native-paper'; +import { useBackHandler } from '@hooks'; import { useTheme } from '@hooks/persisted'; import { WebviewScreenProps } from '@navigators/types'; import { getUserAgent } from '@hooks/persisted/useUserAgent'; @@ -27,6 +28,14 @@ const WebviewScreen = ({ route, navigation }: WebviewScreenProps) => { setCanGoForward(e.canGoForward); }; + useBackHandler(() => { + if (canGoBack) { + webViewRef.current?.goBack(); + return true; + } + return false; + }); + return ( <> { visible={progress !== 1} /> ; navigation: WebviewScreenProps['navigation']; } @@ -28,64 +29,108 @@ const Appbar: React.FC = ({ webView, navigation, }) => { - const [visible, setVisible] = useState(false); + const { top } = useSafeAreaInsets(); + const [menuVisible, setMenuVisible] = useState(false); return ( - - + navigation.goBack()} + theme={{ colors: { ...theme } }} /> - - webView.current?.goBack()} - /> - webView.current?.goForward()} - /> - setVisible(false)} - anchor={ - setVisible(true)} - /> - } - > - webView.current?.reload()} - /> - Share.share({ message: currentUrl })} - /> - WebBrowser.openBrowserAsync(currentUrl)} - /> - { - webView.current?.clearCache(true); - showToast(getString('webview.dataDeleted')); + + + + {title} + + + + webView.current?.goBack()} + theme={{ colors: { ...theme } }} + /> + + webView.current?.goForward()} + theme={{ colors: { ...theme } }} /> - - + + setMenuVisible(false)} + anchor={ + setMenuVisible(true)} + theme={{ colors: { ...theme } }} + /> + } + style={{ backgroundColor: theme.surface2 }} + contentStyle={{ backgroundColor: theme.surface2 }} + > + { + setMenuVisible(false); + webView.current?.reload(); + }} + /> + { + setMenuVisible(false); + Share.share({ message: currentUrl }); + }} + /> + { + setMenuVisible(false); + Linking.openURL(currentUrl); + }} + /> + { + setMenuVisible(false); + webView.current?.clearCache?.(true); + webView.current?.reload(); + showToast(getString('webview.dataDeleted')); + }} + /> + + + ); };