Skip to content

Commit

Permalink
OnBackPress
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsumon4u committed Jul 9, 2022
1 parent bf17354 commit 5c509e8
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions screens/WebViewScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import React, { useEffect } from 'react';
import { StyleSheet, Alert } from 'react-native';
import React, { useRef, useEffect } from 'react';
import { StyleSheet, Alert, BackHandler } from 'react-native';
import { Text, View } from '../components/Themed';
import { WebView } from 'react-native-webview';
import CustomActivityIndicator from '../components/ActivityIndicator';

export default function WebViewScreen({navigation, route: {params}}) {
const webRef = useRef();

const onBackPress = () => {
webRef.current.goBack();
return true;
};

useEffect(() => {
BackHandler.addEventListener("hardwareBackPress", onBackPress);

// getSendingSettings().then((res) => {
// setData(storage.sending_settings, res.data);
// }).catch((err) => {
// console.log(err);
// });

return () => {
BackHandler.removeEventListener("hardwareBackPress", onBackPress);
};
}, []);

const displayError = (e) => {
Alert.alert(
"Error",
Expand All @@ -26,6 +47,7 @@ export default function WebViewScreen({navigation, route: {params}}) {

return (
<WebView
ref={webRef}
style={styles.container}
sharedCookiesEnabled={true}
source={{ uri: `${params.server}/dashboard` }}
Expand Down

0 comments on commit 5c509e8

Please sign in to comment.