Skip to content

Commit bbbbb80

Browse files
committed
installled @capacitor/app And handheld native back button.
1 parent 4b624d4 commit bbbbb80

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
"build:github": "vite build --mode github",
3333
"lint": "eslint .",
3434
"preview": "vite preview",
35-
"android:assets:generate": "npx @capacitor/assets generate --android --assetPath public/logo --iconBackgroundColor \"#eeeeee\" --iconBackgroundColorDark \"#222222\"",
35+
"android:assets:generate": "npx @capacitor/assets generate --android --assetPath public/logo --iconBackgroundColor \"#eeeeee\" --iconBackgroundColorDark \"#222222\"",
3636
"android:sync": "npx cap sync android",
3737
"android:open": "npx cap open android"
3838
},
3939
"dependencies": {
4040
"@capacitor/android": "^8.0.1",
41+
"@capacitor/app": "^8.0.0",
4142
"@capacitor/assets": "^3.0.5",
4243
"@capacitor/cli": "^8.0.1",
4344
"@capacitor/core": "^8.0.1",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useEffect } from 'react'
2+
import { App } from '@capacitor/app'
3+
import { useRouter } from '@tanstack/react-router'
4+
5+
export function NativeBackHandler() {
6+
const router = useRouter()
7+
8+
useEffect(() => {
9+
const sub = App.addListener('backButton', () => {
10+
if (router.history.canGoBack()) {
11+
router.history.back()
12+
} else {
13+
App.exitApp()
14+
}
15+
})
16+
17+
return () => {
18+
sub.then(s => s.remove())
19+
}
20+
}, [router])
21+
22+
return null
23+
}

frontend/src/routes/__root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useApplyFont} from '@/hook/use-apply-font.hook'
33
import { useApplyColorTheme} from '@/hook/use-color-theme.hook'
44
import { Outlet, createRootRoute } from '@tanstack/react-router'
55
import { useApplyTheme } from '@/hook/use-dark-or-light-theme.hook'
6+
import { NativeBackHandler } from '@/provider/native-back.provider'
67

78
export const Route = createRootRoute({
89
component: RootComponent,
@@ -14,6 +15,7 @@ function RootComponent() {
1415
useApplyFont()
1516
return (
1617
<React.Fragment>
18+
<NativeBackHandler/>
1719
<Outlet />
1820
</React.Fragment>
1921
)

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)