Skip to content

Commit f8153e0

Browse files
committed
feat(lab): PageControl scrubs, windows and fades like UIPageControl
1 parent 8018ed2 commit f8153e0

11 files changed

Lines changed: 1617 additions & 169 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[docs] The motion role table lists the page control's roles a theme can retune: `pageControl.windowSlide`, `pageControl.windowSlideDelayMs`, `pageControl.tapFadeOutMs`, `pageControl.fadeOutMs`, `pageControl.fadeOutCurve`, `pageControl.switchMs` and `pageControl.switchCurve`.
6+
7+
@vjeux
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[experimental] `uikit.pageControl`, read through `@astryxdesign/core/motion/experimental`, gains UIPageControl's scrub (start distance, switch point), its held state (delay, dimmed indicators), its window of ten slots with shrinking edge indicators and the spring and delay it slides on, its fades and its jog past the window's edge, each with its source. The table is registered: the slide's spring and delay and the fades' durations and curves are motion roles a theme can retune.
6+
7+
@vjeux

‎packages/cli/assets/docs/motion.doc.mjs‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,48 @@ const calmTheme = defineTheme({
190190
'duration',
191191
'350ms',
192192
],
193+
[
194+
'pageControl.fadeOutCurve',
195+
'--motion-page-control-fade-out-curve',
196+
'curve',
197+
'cubic-bezier(0, 0, 0.58, 1)',
198+
],
199+
[
200+
'pageControl.fadeOutMs',
201+
'--motion-page-control-fade-out-ms',
202+
'duration',
203+
'250ms',
204+
],
205+
[
206+
'pageControl.switchCurve',
207+
'--motion-page-control-switch-curve',
208+
'curve',
209+
'cubic-bezier(0.42, 0, 0.58, 1)',
210+
],
211+
[
212+
'pageControl.switchMs',
213+
'--motion-page-control-switch-ms',
214+
'duration',
215+
'15.625ms',
216+
],
217+
[
218+
'pageControl.tapFadeOutMs',
219+
'--motion-page-control-tap-fade-out-ms',
220+
'duration',
221+
'125ms',
222+
],
223+
[
224+
'pageControl.windowSlide',
225+
'--motion-page-control-window-slide',
226+
'spring',
227+
'0.15s 0',
228+
],
229+
[
230+
'pageControl.windowSlideDelayMs',
231+
'--motion-page-control-window-slide-delay-ms',
232+
'duration',
233+
'50ms',
234+
],
193235
['scroll.bounce', '--motion-scroll-bounce', 'spring', '0.5s 0'],
194236
[
195237
'scroll.paging.snap',

‎packages/cli/test/__golden__/no-icon-set/docs-topics.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"touch-motion",
202202
"best-practices"
203203
],
204-
"skeleton": "a86303e70a6cb63931e8e29c3b470b94f8edcc0b15576a907680a376213faddc",
204+
"skeleton": "7f3e41e04a81e8a94af59e755d943a5de167c9bf57ac8b0ba562c9a80ebe6d5d",
205205
"mentions": []
206206
},
207207
"principles": {

‎packages/core/src/motion/uikit/pageControl.ts‎

Lines changed: 140 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@
44
* @file pageControl.ts
55
* @input Nothing; data only
66
* @output Exports `pageControl`: UIPageControl's measured geometry, its
7-
* default indicator alphas and its tap rule
7+
* default indicator alphas, its tap and scrub rules, its window of
8+
* indicators, its fades and its jog past the window's edge
89
* @position The page-control domain of the UIKit constants table
910
* (motion/uikit); read by the lab PageControl
1011
*
1112
* Every value was read from a stock UIPageControl (default style, default
1213
* tint) on the iOS 26.2 simulator, iPhone 17 Pro: its frames,
1314
* `intrinsicContentSize`, `size(forNumberOfPages:)`, the indicator images'
14-
* rendered pixels, and `valueChanged` under HID touches. Geometry is in
15-
* points.
15+
* rendered pixels and animations, and `valueChanged` under HID touches, over
16+
* a mid-grey background. Geometry is in points.
1617
*
1718
* Every leaf carries one or more `@source`; uikit.test.ts enforces it.
1819
*
1920
* SYNC: When modified, update:
2021
* - /packages/lab/src/PageControl/pageControlModel.ts
22+
* - /packages/cli/assets/docs/motion.doc.mjs (`pnpm generate:motion-roles`)
2123
* - /packages/core/src/motion/README.md (domain list)
2224
*/
2325

2426
/**
2527
* UIPageControl on iOS 26.
2628
* @experimental
2729
*/
30+
import {registerMotionTable} from '../roles';
31+
2832
export const pageControl = {
2933
/**
3034
* Diameter of one page indicator.
@@ -82,4 +86,137 @@ export const pageControl = {
8286
* touch, one page per tap (2026-10-23)
8387
*/
8488
tapStep: 1,
89+
/**
90+
* How far a finger travels from where it landed before the control
91+
* scrubs: from then on the page is the indicator under the finger.
92+
* Movement alone starts it; holding first changes nothing.
93+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, HID
94+
* drags across 5- and 50-page controls from a still touch and after an
95+
* 800 ms hold: the first page change at 16.3 and 16.7 pt (2026-10-24)
96+
*/
97+
scrubStartDistance: 16,
98+
/**
99+
* While scrubbing, the page switches at the midpoint between two
100+
* indicators' centres: one page per indicator pitch (9.67 + 8 pt), the
101+
* same going back.
102+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
103+
* 5-page control: changes at x 192.3, 210.3, 229.0 against midpoints
104+
* 192.3, 210.2, 227.8 between indicator centres (2026-10-24)
105+
*/
106+
scrubSwitchPoint: 0.5,
107+
/**
108+
* A finger held on the control turns it interactive after this many
109+
* milliseconds, moving or not: the platter shows and the other indicators
110+
* dim to `interactingOtherIndicatorAlpha`.
111+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, the
112+
* indicators' contentsMultiplyColor animations start 153–160 ms after
113+
* touch-down, interactionState 2 (2026-10-24)
114+
*/
115+
interactionDelayMs: 155,
116+
/**
117+
* Opacity of the indicators other than the current one while a finger is
118+
* on the control.
119+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, held
120+
* control: the other indicators' tint alpha 0.25 (2026-10-24)
121+
*/
122+
interactingOtherIndicatorAlpha: 0.25,
123+
/**
124+
* At most this many indicator slots show. Past it the row is a window
125+
* that moves only when the current page would land in a shrunk slot.
126+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
127+
* 50-page control at pages 0, 10, 25 and 49: ten slots on the 17.67 pt
128+
* pitch, centred on the control (2026-10-24)
129+
*/
130+
visibleSlots: 10,
131+
/**
132+
* Where pages continue past the window, its last two slots on that side
133+
* shrink to these diameters, outermost last; the slots beyond show
134+
* nothing.
135+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
136+
* 50-page control: edge indicators 7.33 and 4.31 pt (scale 0.7588 and
137+
* 0.4461) (2026-10-24)
138+
*/
139+
edgeIndicatorSizes: [7.33, 4.31],
140+
/**
141+
* When the window moves, every indicator slides to its new slot and
142+
* takes its new size on this spring.
143+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
144+
* 50-page control at page 10 tapped to 11: UIView spring dampingRatio 1,
145+
* response 0.15 (tracking), the strip sliding 17.67 pt in about 0.2 s
146+
* (2026-10-24)
147+
*/
148+
windowSlide: {response: 0.15, dampingRatio: 1},
149+
/**
150+
* The window starts to move this many milliseconds after the page changes;
151+
* the new current indicator lights first, in its shrunk slot.
152+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
153+
* 50-page control at page 10 tapped to 11: the strip starts to slide
154+
* about 50 ms after valueChanged (2026-10-24)
155+
*/
156+
windowSlideDelayMs: 50,
157+
/**
158+
* After a tap, the indicator that stops being current fades to the
159+
* other indicators' opacity over this many milliseconds, on `fadeOutCurve`.
160+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, taps:
161+
* contentsMultiplyColor CABasicAnimation 0.125 s (2026-10-24)
162+
*/
163+
tapFadeOutMs: 125,
164+
/**
165+
* After any other page change (scrubbing, or the app setting the page),
166+
* the indicator that stops being current fades over this many
167+
* milliseconds.
168+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro,
169+
* programmatic currentPage changes and scrubs: contentsMultiplyColor
170+
* CABasicAnimation 0.25 s (2026-10-24)
171+
*/
172+
fadeOutMs: 250,
173+
/**
174+
* The curve of both fades out.
175+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, the
176+
* fade's timing function control points (0, 0, 0.58, 1) (2026-10-24)
177+
*/
178+
fadeOutCurve: [0, 0, 0.58, 1],
179+
/**
180+
* Any other opacity change (the new current indicator lighting, the
181+
* others dimming while a finger is down and recovering at the lift, the
182+
* platter showing) takes this many milliseconds: a switch.
183+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro,
184+
* contentsMultiplyColor and opacity CABasicAnimations 0.015625 s
185+
* (2026-10-24)
186+
*/
187+
switchMs: 15.625,
188+
/**
189+
* The curve of those switches.
190+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, the
191+
* switch's timing function control points (0.42, 0, 0.58, 1)
192+
* (2026-10-24)
193+
*/
194+
switchCurve: [0.42, 0, 0.58, 1],
195+
/**
196+
* Past the window's edge while scrubbing, the control steps pages on its
197+
* own, faster the further the finger is past the edge of the control's
198+
* content: this many pages per second per point.
199+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
200+
* 50-page control scrubbed right at 40 pt/s: intervals from 266 ms 19 pt
201+
* past the content edge to 66 ms at 76 pt, least squares 0.173 pages/s
202+
* per pt; a run to the left settled at 10 pages/s 77 pt past it
203+
* (2026-10-24)
204+
*/
205+
jogRatePerPoint: 0.173,
206+
/**
207+
* The fastest the control steps pages past the window's edge, pages per
208+
* second.
209+
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro, a
210+
* 50-page control held 108 pt past the content edge: one page every
211+
* 61–71 ms (2026-10-24)
212+
*/
213+
jogMaxRate: 15,
85214
} as const;
215+
216+
// The window's slide (spring and delay) and the fades and switches (durations
217+
// and curves) are motion roles a theme may retune (motion/roles.ts). When a
218+
// held finger turns the control interactive decides who holds the touch, not
219+
// how anything moves.
220+
registerMotionTable('pageControl', pageControl, {
221+
exclude: ['interactionDelayMs'],
222+
});

‎packages/lab/src/PageControl/PageControl.doc.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const docs = {
1616
'paging',
1717
],
1818
description:
19-
'A row of page indicators under a paging view, as on iOS: one dot per page, the current one highlighted. A tap to either side of the current dot moves one page that way. Experimental: lands in lab first.',
19+
'A row of page indicators under a paging view, as on iOS: one dot per page, the current one highlighted. A tap to either side of the current dot moves one page that way. Under a finger on iOS, sliding the finger across the dots scrubs straight to the page under it, and with more than ten pages the row is a window whose edge dots shrink to show there is more; elsewhere (Android, a mouse) a long row is cropped to the control. Experimental: lands in lab first.',
2020
props: [
2121
{
2222
name: 'count',
@@ -34,7 +34,7 @@ export const docs = {
3434
name: 'onChange',
3535
type: '(page: number) => void',
3636
description:
37-
'Called with the page a tap, an arrow key, Home, End or an assistive technology asks for. Update the paging view and value together.',
37+
'Called with the page a tap, a scrub, an arrow key, Home, End or an assistive technology asks for; a scrub calls it once per page it passes. Update the paging view and value together.',
3838
required: true,
3939
},
4040
{
@@ -62,7 +62,7 @@ export const docs = {
6262
{
6363
guidance: true,
6464
description:
65-
'Keep pages few enough to count at a glance; past about ten the row stays a fixed width and scrolls.',
65+
'Keep pages few enough to count at a glance; past ten the row stays a fixed width, shows a window of them and scrolls as the page changes.',
6666
},
6767
{
6868
guidance: false,

‎packages/lab/src/PageControl/PageControl.test.tsx‎

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,41 @@
55
* @input vitest (jsdom), Testing Library, PageControl
66
* @output Proves the control's semantics (one named slider reading "Page N
77
* of M"), its keyboard (arrows mirrored in RTL, Home, End), its measured
8-
* geometry and alphas, the width cap, hidesForSinglePage, and a tap's step
9-
* to either side of the current indicator
8+
* geometry and alphas, the width cap and the window it renders, and
9+
* hidesForSinglePage
1010
* @position Testing; the real-touch proofs are
1111
* __tests__/PageControl.interaction.browser.spec.ts
1212
*/
1313

14-
import {describe, expect, it, vi} from 'vitest';
14+
import {afterEach, describe, expect, it, vi} from 'vitest';
1515
import {fireEvent, render, screen} from '@testing-library/react';
1616
import {PageControl} from './PageControl';
1717

18+
/** A finger on WebKit for iOS: a coarse pointer and -webkit-touch-callout. */
19+
function asIos() {
20+
vi.stubGlobal('CSS', {
21+
supports: (query: string) =>
22+
query.replace(/\s/g, '') === '(-webkit-touch-callout:none)',
23+
});
24+
vi.stubGlobal(
25+
'matchMedia',
26+
vi.fn((query: string) => ({
27+
matches: query.includes('pointer: coarse'),
28+
media: query,
29+
onchange: null,
30+
addListener: vi.fn(),
31+
removeListener: vi.fn(),
32+
addEventListener: vi.fn(),
33+
removeEventListener: vi.fn(),
34+
dispatchEvent: vi.fn(),
35+
})),
36+
);
37+
}
38+
39+
afterEach(() => {
40+
vi.unstubAllGlobals();
41+
});
42+
1843
function renderControl(
1944
props: Partial<React.ComponentProps<typeof PageControl>> = {},
2045
) {
@@ -90,8 +115,8 @@ describe('PageControl', () => {
90115
expect(slider.style.height).toBe('25.67px');
91116
expect(slider.style.width).toBe('108.35px');
92117
const indicators = Array.from(
93-
slider.firstElementChild?.children ?? [],
94-
) as HTMLElement[];
118+
slider.querySelectorAll<HTMLElement>('[data-page]'),
119+
);
95120
expect(indicators).toHaveLength(5);
96121
expect(indicators[0].style.width).toBe('9.67px');
97122
expect(indicators.map(i => i.style.opacity)).toEqual([
@@ -103,14 +128,64 @@ describe('PageControl', () => {
103128
]);
104129
});
105130

106-
it('never grows wider than 161.3 px; past that the row shifts to keep the current page in view', () => {
131+
it('never grows wider than 161.3 px; on iOS, with more than ten pages it renders the window around the current page', () => {
132+
asIos();
107133
renderControl({count: 50, value: 25});
108134
const slider = screen.getByRole('slider');
109135
expect(slider.style.width).toBe('161.3px');
110-
const strip = slider.firstElementChild as HTMLElement;
111-
expect(
112-
Number.parseFloat(strip.style.getPropertyValue('--_page-control-offset')),
113-
).toBeGreaterThan(0);
136+
// From page 0, page 25 sits in the window's last full slot: the window
137+
// starts at page 18 (pages 20–25 full); three slots on each side render
138+
// for the slide.
139+
const pages = Array.from(
140+
slider.querySelectorAll<HTMLElement>('[data-page]'),
141+
i => Number(i.dataset.page),
142+
);
143+
expect(pages[0]).toBe(15);
144+
expect(pages[pages.length - 1]).toBe(30);
145+
});
146+
147+
it('outside iOS (Android, a mouse), a long control is the full row of pages, cropped', () => {
148+
renderControl({count: 50, value: 25});
149+
const slider = screen.getByRole('slider');
150+
expect(slider.style.width).toBe('161.3px');
151+
const dots = Array.from(
152+
slider.querySelectorAll<HTMLElement>('[data-page]'),
153+
);
154+
expect(dots).toHaveLength(50);
155+
// No fades and no shrinking slots outside iOS.
156+
expect(dots.every(dot => dot.style.transition === 'none')).toBe(true);
157+
});
158+
159+
it("on iOS, a theme's --motion-page-control-… values reach the fades", () => {
160+
asIos();
161+
const onChange = vi.fn();
162+
const {rerender} = render(
163+
<div
164+
data-astryx-theme="page-control-test"
165+
style={
166+
{
167+
'--motion-page-control-fade-out-ms': '500ms',
168+
'--motion-page-control-fade-out-curve': 'cubic-bezier(0, 0, 1, 1)',
169+
} as React.CSSProperties
170+
}>
171+
<PageControl count={5} value={2} onChange={onChange} />
172+
</div>,
173+
);
174+
rerender(
175+
<div
176+
data-astryx-theme="page-control-test"
177+
style={
178+
{
179+
'--motion-page-control-fade-out-ms': '500ms',
180+
'--motion-page-control-fade-out-curve': 'cubic-bezier(0, 0, 1, 1)',
181+
} as React.CSSProperties
182+
}>
183+
<PageControl count={5} value={3} onChange={onChange} />
184+
</div>,
185+
);
186+
const slider = screen.getByRole('slider');
187+
const old = slider.querySelector<HTMLElement>('[data-page="2"]');
188+
expect(old?.style.transition).toBe('opacity 0.5s cubic-bezier(0, 0, 1, 1)');
114189
});
115190

116191
it('with hidesForSinglePage, renders nothing for one page', () => {

0 commit comments

Comments
 (0)