Skip to content

Commit

Permalink
Fix android backHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwong committed Jul 18, 2022
1 parent 113eb17 commit de95daf
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/App/WebViewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const WebViewContainer = ({
const [localWalletConnector, setLocalWalletConnector] =
useState<WalletConnect | null>(null)

const [canGoBack, SetCanGoBack] = useState(false)
const [canGoBack, setCanGoBack] = useState(false)
const [, setScanning] = useState(false)
const [, setError] = useState('')
const [ledgers, setLedgers] = useState<DeviceInterface[]>([])
Expand Down Expand Up @@ -585,8 +585,8 @@ export const WebViewContainer = ({
}
}

const onBackPress = () => {
if (webviewInstance && webviewInstance.current && canGoBack) {
const onBackPress = useCallback(() => {
if (webviewInstance.current && canGoBack) {
// @ts-ignore
webviewInstance.current?.goBack()
return true
Expand All @@ -612,7 +612,7 @@ export const WebViewContainer = ({
return true
}
}
}
}, [webviewInstance.current, canGoBack])

const handleAppStateChange = useCallback(
async (nextAppState: string): Promise<void> => {
Expand Down Expand Up @@ -726,7 +726,7 @@ export const WebViewContainer = ({
onBackPress
)
}
}, [canGoBack, onBackPress])
}, [onBackPress])

useEffect(() => {
AppState.addEventListener('change', handleAppStateChange)
Expand All @@ -753,12 +753,11 @@ export const WebViewContainer = ({
startInLoadingState={true}
scrollEnabled={false}
contentInsetAdjustmentBehavior="scrollableAxes"
onLoadProgress={(event) =>
setCanGoBack(event.nativeEvent.canGoBack)
}
onMessage={async (message) => {
const { nativeEvent } = message
if (nativeEvent.data === 'navigationStateChange') {
SetCanGoBack(nativeEvent.canGoBack)
return
}
const req = nativeEvent.data && JSON.parse(nativeEvent.data)
await WebViewListener(req)
}}
Expand Down

0 comments on commit de95daf

Please sign in to comment.