fix(mobile): pop to home when leaving a host so the back chevron animates backward (#9723)
This commit is contained in:
parent
81e3c62f19
commit
cd4064689d
|
|
@ -4,16 +4,18 @@ import { leaveHostRoute } from './host-route-exit'
|
|||
|
||||
function makeRouter() {
|
||||
return {
|
||||
replace: vi.fn()
|
||||
dismissTo: vi.fn()
|
||||
}
|
||||
}
|
||||
|
||||
describe('leaveHostRoute', () => {
|
||||
it('returns to home instead of depending on route history', () => {
|
||||
// Why: dismissTo (not replace) is what makes the chevron animate back like swipe-back, so the
|
||||
// call shape is the behavior under test, not an implementation detail.
|
||||
it('dismisses to home instead of depending on route history', () => {
|
||||
const router = makeRouter()
|
||||
|
||||
leaveHostRoute(router)
|
||||
|
||||
expect(router.replace).toHaveBeenCalledWith('/')
|
||||
expect(router.dismissTo).toHaveBeenCalledWith('/')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
type HostRouteExitRouter = {
|
||||
replace: (href: '/') => void
|
||||
dismissTo: (href: '/') => void
|
||||
}
|
||||
|
||||
export function leaveHostRoute(router: HostRouteExitRouter): void {
|
||||
// Why: direct pairing can open /h/:hostId as the root route, and split-view
|
||||
// detail history is not the host/home screen the header is meant to exit to.
|
||||
router.replace('/')
|
||||
// Why: direct pairing can open /h/:hostId as the root route, and split-view detail history is
|
||||
// not the host/home screen the header is meant to exit to. dismissTo pops to home when it is on
|
||||
// the stack, so the chevron animates back like swipe-back, and replaces when it is not.
|
||||
router.dismissTo('/')
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue