mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
feat(mobile): page through the days like a native pager
The day swipe only rubber-banded the current day, then cut to the next one after a fixed slide and a synchronous re-render of the whole planner. The previous, current and next day now sit side by side in a horizontal scroll-snap strip, so the finger drags the neighbour in, and momentum, edge bounce and axis locking are the browser's own. The day changes once the strip comes to rest, with a light haptic tick in the app. The pager is one building block, MDayPager, used by the plan timeline and the road trip stages alike. Each page renders its own day through the timeline and stage hooks, which now take the day as a parameter, and keeps its state when it slides into the middle.
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import { Haptics, NotificationType } from '@capacitor/haptics';
|
||||
import { Haptics, ImpactStyle, NotificationType } from '@capacitor/haptics';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { toastHaptic } from './haptics';
|
||||
import { tickHaptic, toastHaptic } from './haptics';
|
||||
import { isNativeApp } from './platform';
|
||||
|
||||
vi.mock('@capacitor/haptics', () => ({
|
||||
Haptics: { notification: vi.fn() },
|
||||
Haptics: { notification: vi.fn(), impact: vi.fn() },
|
||||
ImpactStyle: { Light: 'LIGHT' },
|
||||
NotificationType: { Success: 'SUCCESS', Warning: 'WARNING', Error: 'ERROR' },
|
||||
}));
|
||||
vi.mock('./platform', () => ({ isNativeApp: vi.fn() }));
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(Haptics.notification).mockReset().mockResolvedValue();
|
||||
vi.mocked(Haptics.impact).mockReset().mockResolvedValue();
|
||||
vi.mocked(isNativeApp).mockReturnValue(true);
|
||||
});
|
||||
|
||||
@@ -42,3 +44,16 @@ describe('toastHaptic', () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
});
|
||||
|
||||
describe('tickHaptic', () => {
|
||||
it('gives a light detent in the app', () => {
|
||||
tickHaptic();
|
||||
expect(Haptics.impact).toHaveBeenCalledWith({ style: ImpactStyle.Light });
|
||||
});
|
||||
|
||||
it('stays still in a browser', () => {
|
||||
vi.mocked(isNativeApp).mockReturnValue(false);
|
||||
tickHaptic();
|
||||
expect(Haptics.impact).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Haptics, NotificationType } from '@capacitor/haptics';
|
||||
import { Haptics, ImpactStyle, NotificationType } from '@capacitor/haptics';
|
||||
import { isNativeApp } from './platform';
|
||||
import { reportNativeFailure } from './reportFailure';
|
||||
|
||||
@@ -18,3 +18,12 @@ export function toastHaptic(type: string): void {
|
||||
if (!feedback || !isNativeApp()) return;
|
||||
Haptics.notification({ type: feedback }).catch(reportNativeFailure);
|
||||
}
|
||||
|
||||
/**
|
||||
* The light detent a native pager or picker gives when it lands on a new page:
|
||||
* a swiped-to day, a sheet snapping to a stop. Does nothing in a browser.
|
||||
*/
|
||||
export function tickHaptic(): void {
|
||||
if (!isNativeApp()) return;
|
||||
Haptics.impact({ style: ImpactStyle.Light }).catch(reportNativeFailure);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user