feat(native): the app's own swipe back, and a way back closes the sheet on top first

WebKit's swipe from the left edge slid away a screenshot of the whole page,
closed no sheet and took every drag near the edge from the UI. Binaries from
this one turn it off and report an edgeBack feature, and the UI draws its own:
the page follows the finger, a release past a third or a flick slides it off
and goes back, anything else springs it home, with a light detent.

Open sheets now register in one overlay stack, so a way back closes the one on
top first, through its own close path (unsaved changes still ask): the edge
swipe on iOS and Android's back gesture alike.
This commit is contained in:
Maurice
2026-11-06 13:10:39 +01:00
parent f92aea80a7
commit d859e23879
11 changed files with 352 additions and 6 deletions
+13
View File
@@ -3,6 +3,7 @@ import { Keyboard } from '@capacitor/keyboard';
import { SplashScreen } from '@capacitor/splash-screen';
import { StatusBar, Style } from '@capacitor/status-bar';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { closeTopOverlay } from '../mobile/overlayStack';
import { isEffectivelyOffline } from '../sync/networkMode';
import { checkAppUpdate } from './capabilities';
import { startNativeApp } from './nativeApp';
@@ -17,6 +18,7 @@ vi.mock('./platform', () => ({ isNativeApp: vi.fn(), isNativeIos: vi.fn() }));
vi.mock('./offlineShell', () => ({ keepOfflineShellFresh: vi.fn() }));
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn() }));
vi.mock('./capabilities', () => ({ checkAppUpdate: vi.fn(async () => false) }));
vi.mock('../mobile/overlayStack', () => ({ closeTopOverlay: vi.fn(() => false) }));
function backButtonHandler(): (event: { canGoBack: boolean }) => void {
const call = vi.mocked(App.addListener).mock.calls.find(([name]) => name === 'backButton');
@@ -46,6 +48,17 @@ describe('startNativeApp', () => {
expect(StatusBar.setStyle).not.toHaveBeenCalled();
});
it("Android's back gesture closes an open sheet before it leaves the page", () => {
const back = vi.spyOn(window.history, 'back').mockImplementation(() => {});
vi.mocked(closeTopOverlay).mockReturnValueOnce(true);
startNativeApp();
backButtonHandler()({ canGoBack: true });
expect(back).not.toHaveBeenCalled();
backButtonHandler()({ canGoBack: true });
expect(back).toHaveBeenCalledTimes(1);
back.mockRestore();
});
it('asks the binary what it can do and the server which binary it needs', () => {
startNativeApp();
expect(checkAppUpdate).toHaveBeenCalledWith(expect.any(Function));