Skip to content

Commit 53cf41a

Browse files
committed
refactor(core): the presentation resolver follows one touch model
resolvePresentation answers the surface and whether touch modes apply, the same on every touch device: no idiom or motion field, after #8076 dropped the platform idiom (one touch model). The fine-pointer test case checks its own context's pointer before its claim.
1 parent 0bb18a3 commit 53cf41a

3 files changed

Lines changed: 18 additions & 42 deletions

File tree

‎packages/core/src/gestures/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ caller's explicit value always wins over the touch default
364364
`usePresentation(presentation, {whenOmitted})` (`../utils/presentation.ts`;
365365
`readPresentation` at one moment): `surface` is the popover or the sheet;
366366
`touchModes` says whether its touch input modes apply (a finger, and not
367-
pinned to `'popover'`); `idiom` and `motion` follow those modes only. An
367+
pinned to `'popover'`), the same on every touch device. An
368368
omitted value means the component's default, `whenOmitted: 'popover'` or
369369
`'touch'` (the popover surface with touch input modes), so it stays
370370
distinguishable from an explicit `'popover'`, which pins the fine surface

‎packages/core/src/utils/presentation.test.ts‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* surface and input modes on an iPhone; an omitted value follows the
99
* component's default (`'popover'` or `'touch'`), distinguishable from an
1010
* explicit `'popover'`; `'adaptive'` and `'bottom-sheet'` keep their sheet
11-
* meaning with touch modes under a finger; the idiom and motion follow the
12-
* touch modes only; the surface equals useAdaptivePresentation's for every
11+
* meaning with touch modes under a finger, the same on every touch device;
12+
* the surface equals useAdaptivePresentation's for every
1313
* value on every device; live pointer changes; the server default and
1414
* hints; the one-moment read
1515
* @position Unit tests of packages/core/src/utils/presentation.ts
@@ -101,8 +101,6 @@ describe('presentation: a caller choice wins over touch defaults', () => {
101101
expect(resolve('popover', whenOmitted)).toEqual({
102102
surface: 'popover',
103103
touchModes: false,
104-
idiom: 'default',
105-
motion: 'theme',
106104
});
107105
}
108106
});
@@ -112,27 +110,22 @@ describe('presentation: a caller choice wins over touch defaults', () => {
112110
expect(resolve(undefined, 'touch')).toEqual({
113111
surface: 'popover',
114112
touchModes: true,
115-
idiom: 'ios',
116-
motion: 'uikit',
117113
});
118114
// Today's components: omitted is popover.
119115
expect(resolve(undefined)).toEqual(resolve('popover'));
120116
expect(resolve(undefined, 'popover')).toEqual(resolve('popover'));
121117
});
122118

123-
it('turns touch modes on under a finger only, and the UIKit idiom on iOS only', () => {
119+
it('turns touch modes on under a finger only, the same on every touch device', () => {
124120
setDevice(ANDROID);
125121
expect(resolve(undefined, 'touch')).toEqual({
126122
surface: 'popover',
127123
touchModes: true,
128-
idiom: 'default',
129-
motion: 'theme',
130124
});
131125
for (const desk of [DESKTOP, MAC_SAFARI]) {
132126
setDevice(desk);
133127
expect(resolve(undefined, 'touch')).toMatchObject({
134128
touchModes: false,
135-
idiom: 'default',
136129
});
137130
}
138131
});
@@ -142,8 +135,6 @@ describe('presentation: a caller choice wins over touch defaults', () => {
142135
expect(resolve('adaptive')).toEqual({
143136
surface: 'bottom-sheet',
144137
touchModes: true,
145-
idiom: 'ios',
146-
motion: 'uikit',
147138
});
148139
setDevice(IPAD);
149140
expect(resolve('adaptive')).toMatchObject({
@@ -181,9 +172,11 @@ describe('presentation: a caller choice wins over touch defaults', () => {
181172
);
182173
expect(result.current.touchModes).toBe(true);
183174
act(() => setDevice({coarse: false}));
184-
expect(result.current).toMatchObject({touchModes: false, idiom: 'default'});
175+
// A fine pointer in this context, checked before the claim.
176+
expect(window.matchMedia('(pointer: coarse)').matches).toBe(false);
177+
expect(result.current).toMatchObject({touchModes: false});
185178
act(() => setDevice({coarse: true}));
186-
expect(result.current).toMatchObject({touchModes: true, idiom: 'ios'});
179+
expect(result.current).toMatchObject({touchModes: true});
187180
});
188181

189182
it('renders the server default until hydrated, and honours a server hint', () => {
@@ -196,26 +189,24 @@ describe('presentation: a caller choice wins over touch defaults', () => {
196189
}) {
197190
const resolved = usePresentation(presentation, {
198191
whenOmitted: 'touch',
199-
serverDefault: hint === true ? {idiom: 'ios', isCompact: true} : {},
192+
serverDefault: hint === true ? {isTouch: true, isCompact: true} : {},
200193
});
201-
return `${resolved.surface}/${String(resolved.touchModes)}/${resolved.idiom}`;
194+
return `${resolved.surface}/${String(resolved.touchModes)}`;
202195
}
203-
expect(renderToString(createElement(Probe))).toContain(
204-
'popover/false/default',
205-
);
196+
expect(renderToString(createElement(Probe))).toContain('popover/false');
206197
expect(renderToString(createElement(Probe, {hint: true}))).toContain(
207-
'popover/true/ios',
198+
'popover/true',
208199
);
209200
expect(
210201
renderToString(
211202
createElement(Probe, {presentation: 'adaptive', hint: true}),
212203
),
213-
).toContain('bottom-sheet/true/ios');
204+
).toContain('bottom-sheet/true');
214205
expect(
215206
renderToString(
216207
createElement(Probe, {presentation: 'popover', hint: true}),
217208
),
218-
).toContain('popover/false/default');
209+
).toContain('popover/false');
219210
});
220211

221212
it('answers at one moment as the hook does, and as the server would with no window', () => {
@@ -232,8 +223,6 @@ describe('presentation: a caller choice wins over touch defaults', () => {
232223
).toEqual({
233224
surface: 'popover',
234225
touchModes: false,
235-
idiom: 'default',
236-
motion: 'theme',
237226
});
238227
});
239228
});

‎packages/core/src/utils/presentation.ts‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* (utils/touchPresentation.ts)
1010
* @output usePresentation and readPresentation (and the pure
1111
* resolvePresentation): the surface to render and whether the component's
12-
* touch input modes apply, with the idiom and motion those modes follow
12+
* touch input modes apply
1313
* @position Internal resolver for stable components that, under a finger,
1414
* present a different surface or switch how an open surface follows input
1515
* (architecture:public-component-api INV16)
@@ -28,9 +28,8 @@
2828
* a released component's default is a functional default change
2929
* (`spec:AST-017` FR3) whose Changeset names `presentation="popover"`.
3030
*
31-
* `idiom` is `ios` only where touch modes apply and the touch idiom is iOS,
32-
* so a UIKit-only mode checks `idiom === 'ios'` alone; `motion` follows it.
33-
* Touch styling (press paint, the iOS idiom's looks, the text-size floor)
31+
* One touch model on every touch device: the modes depend on the pointer,
32+
* never on the platform. Touch styling (press paint, the text-size floor)
3433
* and touch-only behavior that a component's own record defines (a row
3534
* swipe, a slider's thumb) do not read this: they keep the touch
3635
* presentation.
@@ -50,8 +49,6 @@ import type {AdaptivePresentation} from '../hooks/useAdaptivePresentation';
5049
import {
5150
readTouchPresentation,
5251
useTouchPresentation,
53-
type MotionPresentation,
54-
type TouchIdiom,
5552
type TouchPresentation,
5653
} from './touchPresentation';
5754

@@ -66,10 +63,6 @@ export interface ResolvedPresentation {
6663
* not pinned to `'popover'`.
6764
*/
6865
readonly touchModes: boolean;
69-
/** The idiom those modes follow: `default` whenever they do not apply. */
70-
readonly idiom: TouchIdiom;
71-
/** UIKit's motion with touch modes in the iOS idiom, the theme's otherwise. */
72-
readonly motion: MotionPresentation;
7366
}
7467

7568
export interface PresentationOptions {
@@ -100,13 +93,7 @@ export function resolvePresentation(
10093
? 'bottom-sheet'
10194
: 'popover';
10295
const touchModes = request !== 'popover' && touch.isTouch;
103-
const idiom = touchModes ? touch.idiom : 'default';
104-
return {
105-
surface,
106-
touchModes,
107-
idiom,
108-
motion: idiom === 'ios' ? 'uikit' : 'theme',
109-
};
96+
return {surface, touchModes};
11097
}
11198

11299
/**

0 commit comments

Comments
 (0)