diff --git a/src/app/features/scene/cameraState.test.ts b/src/app/features/scene/cameraState.test.ts index c2f20d3d..6bbb9f02 100644 --- a/src/app/features/scene/cameraState.test.ts +++ b/src/app/features/scene/cameraState.test.ts @@ -45,6 +45,15 @@ describe('the viewer camera', () => { expect(getCamera()).toEqual({ mode: 'offset', speedDegPerS: 1, offsetM: -30 }); }); + it('a reduced-motion visit starts still with the default speed and offset kept, which apply once a moving mode is chosen (ruling ridge-reduced-motion-starts-still)', () => { + reduced.matches = true; + expect(getCamera()).toEqual({ mode: 'still', speedDegPerS: 0.6, offsetM: 200 }); + expect(effectiveMode()).toBe('still'); + setCamera({ mode: 'both' }); + expect(getCamera()).toEqual({ mode: 'both', speedDegPerS: 0.6, offsetM: 200 }); + expect(effectiveMode()).toBe('both'); + }); + it('keeps each change per viewer, and tells listeners only of a change', () => { const cb = vi.fn(); subscribe(cb); diff --git a/src/app/features/scene/view/SceneView.css.ts b/src/app/features/scene/view/SceneView.css.ts index e9be61af..26699f00 100644 --- a/src/app/features/scene/view/SceneView.css.ts +++ b/src/app/features/scene/view/SceneView.css.ts @@ -26,6 +26,9 @@ export const Surface = style({ selectors: { '&:active': { cursor: 'grabbing' } }, }); +/** How much of the rail and the panel is left while a finger is down: they step out of the way of the turn (ruling ridge-view-phone-one-finger). */ +export const TURNING_CHROME_OPACITY = 0.12; + /** The rail and the panel, top left. It takes no pointer itself, so a drag over its gaps turns the view; its plates do. It fades while a finger is down. */ export const Chrome = style({ position: 'absolute', @@ -36,7 +39,7 @@ export const Chrome = style({ gap: config.space.S200, pointerEvents: 'none', transition: 'opacity 150ms', - selectors: { [`${Root}[data-turning="true"] &`]: { opacity: 0.12 } }, + selectors: { [`${Root}[data-turning="true"] &`]: { opacity: TURNING_CHROME_OPACITY } }, }); const Plate = style({ diff --git a/src/app/features/scene/view/SceneView.test.tsx b/src/app/features/scene/view/SceneView.test.tsx index 2828e3e4..b776e05e 100644 --- a/src/app/features/scene/view/SceneView.test.tsx +++ b/src/app/features/scene/view/SceneView.test.tsx @@ -1,6 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { PhoneHit } from '../../../styles/PhoneHit.css'; import SceneView, { Rail, SUBMENUS } from './SceneView'; +import { TURNING_CHROME_OPACITY } from './SceneView.css'; // The hooks are held still (TimeSubmenu.test.tsx): the element tree is read, a function component is expanded by calling it. const held = vi.hoisted(() => ({ @@ -8,12 +9,14 @@ const held = vi.hoisted(() => ({ submenu: undefined as unknown, closed: 0, picked: [] as unknown[], + turning: [] as boolean[], + turner: [] as Array<[string, ...unknown[]]>, })); vi.mock('react', async (importOriginal) => { const actual = await importOriginal(); const useState = (init: unknown) => [ typeof init === 'function' ? (init as () => unknown)() : init, - () => undefined, + (v: unknown) => typeof v === 'boolean' && held.turning.push(v), ]; const useRef = (init: unknown) => ({ current: init }); const useMemo = (fn: () => unknown) => fn(); @@ -39,6 +42,16 @@ vi.mock('../sceneView', () => ({ }, setSubmenu: (s: unknown) => held.picked.push(s), })); +vi.mock('./turning', () => ({ + pxPerDegreeOf: () => 20, + createTurner: () => ({ + down: (x: number) => held.turner.push(['down', x]), + move: (x: number) => held.turner.push(['move', x]), + up: () => held.turner.push(['up']), + wheel: (dx: number) => held.turner.push(['wheel', dx]), + key: () => false, + }), +})); vi.mock('focus-trap-react', () => ({ default: ({ children }: { children: unknown }) => children })); type El = { type?: unknown; ref?: unknown; key?: unknown; props?: Record }; @@ -57,6 +70,8 @@ beforeEach(() => { held.submenu = undefined; held.closed = 0; held.picked.length = 0; + held.turning.length = 0; + held.turner.length = 0; vi.stubGlobal('window', { innerWidth: 1280, innerHeight: 720, @@ -160,3 +175,52 @@ describe('the view', () => { expect(held.closed).toBe(1); }); }); + +describe('one finger on the phone (ruling ridge-view-phone-one-finger)', () => { + const surface = () => + walk(SceneView()).find((e) => typeof e.props?.onPointerDown === 'function') as El; + const on = (name: string, evt: Record) => + (surface().props?.[name] as (e: unknown) => void)({ + currentTarget: { setPointerCapture: () => undefined }, + pointerId: 1, + pointerType: 'touch', + isPrimary: true, + button: 0, + clientX: 0, + clientY: 0, + ...evt, + }); + + it('the rail and the panel fade while a finger is down and come back when it lifts', () => { + expect(TURNING_CHROME_OPACITY).toBeGreaterThan(0); + expect(TURNING_CHROME_OPACITY).toBeLessThan(0.5); + on('onPointerDown', { clientX: 100 }); + on('onPointerUp', {}); + on('onPointerDown', { clientX: 100 }); + on('onPointerCancel', {}); + expect(held.turning).toEqual([true, false, true, false]); + }); + + it('only horizontal movement turns: the vertical is never given to the turner', () => { + on('onPointerDown', { clientX: 100, clientY: 50 }); + on('onPointerMove', { clientX: 140, clientY: 900 }); + on('onPointerMove', { clientX: 140, clientY: -900 }); + expect(held.turner).toEqual([['down', 100], ['move', 140], ['move', 140]]); + held.turner.length = 0; + on('onWheel', { deltaX: 2, deltaY: 90 }); + expect(held.turner).toEqual([]); // a mostly vertical wheel is not a turn either + }); + + it('a second finger (not the primary pointer) starts nothing', () => { + on('onPointerDown', { isPrimary: false, clientX: 100 }); + expect(held.turner).toEqual([]); + expect(held.turning).toEqual([]); + }); + + it('a mouse turns only with its main button', () => { + on('onPointerDown', { pointerType: 'mouse', button: 2, clientX: 100 }); + expect(held.turner).toEqual([]); + on('onPointerDown', { pointerType: 'mouse', button: 0, clientX: 100 }); + expect(held.turner).toEqual([['down', 100]]); + }); +});