-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1928 from oasisprotocol/ml/android-back-button
Fix physical back button behavior on Android
- Loading branch information
Showing
9 changed files
with
132 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix physical back button behavior on Android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createContext, FC, PropsWithChildren, useEffect } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
import { Capacitor, type PluginListenerHandle } from '@capacitor/core' | ||
import { App } from '@capacitor/app' | ||
|
||
const IonicContext = createContext<undefined>(undefined) | ||
|
||
let backButtonListenerHandle: PluginListenerHandle | undefined | ||
|
||
const IonicContextProvider: FC<PropsWithChildren> = ({ children }) => { | ||
const navigate = useNavigate() | ||
|
||
useEffect(() => { | ||
/** | ||
* The back button refers to the physical back button on an Android device and should not be confused | ||
* with either the browser back button or ion-back-button. | ||
*/ | ||
backButtonListenerHandle = App.addListener('backButton', ({ canGoBack }) => { | ||
if (!canGoBack) { | ||
App.exitApp() | ||
} else { | ||
navigate(-1) | ||
} | ||
}) | ||
|
||
return () => { | ||
if (backButtonListenerHandle) { | ||
backButtonListenerHandle.remove() | ||
backButtonListenerHandle = undefined | ||
} | ||
} | ||
}, [navigate]) | ||
|
||
return <IonicContext.Provider value={undefined}>{children}</IonicContext.Provider> | ||
} | ||
|
||
export const IonicProvider: FC<PropsWithChildren> = ({ children }) => { | ||
if (Capacitor.isNativePlatform()) { | ||
return <IonicContextProvider>{children}</IonicContextProvider> | ||
} | ||
|
||
return children | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1158,6 +1158,11 @@ | |
resolved "https://registry.yarnpkg.com/@capacitor/android/-/android-5.0.4.tgz#aa6497782bae0851553682126a6051157fe932b5" | ||
integrity sha512-WtXmjRQ0bCtFkwBID/jVEPbqnh0uR9wTSgkW7QNzogDuA0iyJJI2nxDfT9knUmg6mne/CnfTXg093zzdc13C0w== | ||
|
||
"@capacitor/[email protected]": | ||
version "5.0.5" | ||
resolved "https://registry.yarnpkg.com/@capacitor/app/-/app-5.0.5.tgz#b80cc5f1444ad9dec51df22cdef1a35c4690eb83" | ||
integrity sha512-CedAa0aSQu8yNWqgZXWQfcjIg6uzPNdJQPW5CTyT6dA/U7KuJ10YVA6MhoryCUVthnMJqVj9lYqqxyFsSXjzqw== | ||
|
||
"@capacitor/[email protected]": | ||
version "5.0.4" | ||
resolved "https://registry.yarnpkg.com/@capacitor/cli/-/cli-5.0.4.tgz#f8d31f32262e457b2a8e31f76295c15b5c6f57b8" | ||
|