@delacour/react-native-ui 0.7.0-alpha.20261104102945 → 0.7.0-alpha.20261104112157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/calendar/AGENTS.md +9 -4
- package/src/components/calendar/calendar-caption.tsx +9 -3
- package/src/components/calendar/calendar-day.tsx +18 -17
- package/src/components/calendar/calendar.context.tsx +1 -1
- package/src/components/calendar/calendar.render.test.tsx +23 -6
- package/src/components/calendar/calendar.tsx +2 -1
- package/src/components/calendar/calendar.variants.test.ts +52 -0
- package/src/components/calendar/calendar.variants.ts +34 -1
- package/src/components/text-animation/text-animation-clock.ts +27 -9
- package/src/components/text-animation/text-animation-rolling.tsx +7 -3
- package/src/components/text-animation/text-animation-rotating.tsx +36 -10
- package/src/components/text-animation/text-animation-typing.tsx +1 -1
- package/src/components/text-animation/text-animation-unit.tsx +15 -2
- package/src/components/text-animation/text-animation.render.test.tsx +13 -0
- package/src/components/text-animation/text-animation.tsx +7 -1
- package/src/components/text-animation/text-animation.variants.test.ts +33 -0
- package/src/components/text-animation/text-animation.variants.ts +35 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.7.0-alpha.
|
|
3
|
+
"version": "0.7.0-alpha.20261104112157",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -182,8 +182,8 @@
|
|
|
182
182
|
"expo-blur": ">=15",
|
|
183
183
|
"@maplibre/maplibre-react-native": "^11.5.0",
|
|
184
184
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
185
|
-
"@delacour/react-native-bottom-sheet": "0.7.0-alpha.
|
|
186
|
-
"@delacour/react-native-charts": "0.7.0-alpha.
|
|
185
|
+
"@delacour/react-native-bottom-sheet": "0.7.0-alpha.20261104112157",
|
|
186
|
+
"@delacour/react-native-charts": "0.7.0-alpha.20261104112157",
|
|
187
187
|
"@legendapp/list": ">=3.3",
|
|
188
188
|
"react-native-skia": ">=3.9.0",
|
|
189
189
|
"expo-linear-gradient": ">=15",
|
|
@@ -120,9 +120,14 @@ sheets.
|
|
|
120
120
|
|
|
121
121
|
## Accessibility
|
|
122
122
|
|
|
123
|
-
- Each day is a button labelled with the full date (`formatDate(…, { style: "full" })`)
|
|
124
|
-
"Today" / "Range start" / "Range end", with `selected` and
|
|
125
|
-
|
|
123
|
+
- Each day is a button labelled with the full date (`formatDate(…, { style: "full" })`) plus
|
|
124
|
+
"Today" / "Range start" / "Range end" (`resolveDayAccessibilityLabel`), with `selected` and
|
|
125
|
+
`disabled` state. The state words are in the label, not a hint, so they read with hints off.
|
|
126
|
+
- **A read-only day is not `disabled`** (`isUnavailable`): `select` ignores its tap and it skips
|
|
127
|
+
the fade and haptic, but a review screen's days never all read "dimmed".
|
|
128
|
+
- The grid is `role="grid"`, but it is not `accessible` and RN gives `grid` no iOS trait, so
|
|
129
|
+
VoiceOver never reads a label on it. **The enclosing `Field.Label` is read on the caption**
|
|
130
|
+
instead (`resolveCaptionLabel`): "Date of birth, October 2026".
|
|
126
131
|
- **Paging for screen readers lives on the caption**, as increment/decrement actions. An
|
|
127
132
|
adjustable grid would fold its child buttons into itself on both platforms and make the days
|
|
128
133
|
unreachable.
|
|
@@ -139,7 +144,7 @@ sheets.
|
|
|
139
144
|
## Field
|
|
140
145
|
|
|
141
146
|
`resolveCalendarAxes` is the nearest-wins chain: the calendar's own `isDisabled` / `isInvalid` /
|
|
142
|
-
`isReadOnly` / `size` / `variant`, else the `Field`'s. The field's label
|
|
147
|
+
`isReadOnly` / `size` / `variant`, else the `Field`'s. The caption reads the field's label. It does
|
|
143
148
|
not `registerPress` — there is no single focus target for a row tap to reach.
|
|
144
149
|
|
|
145
150
|
## Not here
|
|
@@ -6,7 +6,7 @@ import { Pressable } from "../pressable";
|
|
|
6
6
|
import { Text } from "../text";
|
|
7
7
|
import { useCalendarPart } from "./calendar.context";
|
|
8
8
|
import { formatMonthYear, formatYear } from "./calendar.date";
|
|
9
|
-
import { calendarVariants, resolveCaptionPage, resolvePartTestID } from "./calendar.variants";
|
|
9
|
+
import { calendarVariants, resolveCaptionLabel, resolveCaptionPage, resolvePartTestID } from "./calendar.variants";
|
|
10
10
|
|
|
11
11
|
export type CalendarCaptionProps = Omit<ViewProps, "children"> & {
|
|
12
12
|
className?: string;
|
|
@@ -30,6 +30,9 @@ const PAGE_ACTIONS = [
|
|
|
30
30
|
* swipe up or down on "October 2026" to move a month. As a plain label it takes the `adjustable`
|
|
31
31
|
* role outright; as a button the two actions sit beside its activation. Like the arrows, they do
|
|
32
32
|
* nothing on a disabled calendar or in the years view.
|
|
33
|
+
*
|
|
34
|
+
* **It also carries the field's name** — "Date of birth, October 2026" — since it is the one
|
|
35
|
+
* accessible heading the calendar has; a label on the grid is never read on iOS.
|
|
33
36
|
*/
|
|
34
37
|
export function CalendarCaption({ className, ...props }: CalendarCaptionProps): ReactElement {
|
|
35
38
|
const {
|
|
@@ -39,6 +42,7 @@ export function CalendarCaption({ className, ...props }: CalendarCaptionProps):
|
|
|
39
42
|
goNext,
|
|
40
43
|
goPrev,
|
|
41
44
|
isDisabled,
|
|
45
|
+
label: fieldLabel,
|
|
42
46
|
locale,
|
|
43
47
|
setView,
|
|
44
48
|
size,
|
|
@@ -57,6 +61,8 @@ export function CalendarCaption({ className, ...props }: CalendarCaptionProps):
|
|
|
57
61
|
? formatYear(visibleMonth.year, locale)
|
|
58
62
|
: `${formatYear(yearSpan.from, locale)} – ${formatYear(yearSpan.to, locale)}`;
|
|
59
63
|
|
|
64
|
+
const accessibilityLabel = resolveCaptionLabel(fieldLabel, text);
|
|
65
|
+
|
|
60
66
|
const handleAction = useCallback(
|
|
61
67
|
(event: AccessibilityActionEvent) => {
|
|
62
68
|
const direction = resolveCaptionPage({
|
|
@@ -82,7 +88,7 @@ export function CalendarCaption({ className, ...props }: CalendarCaptionProps):
|
|
|
82
88
|
return (
|
|
83
89
|
<View
|
|
84
90
|
accessibilityActions={PAGE_ACTIONS}
|
|
85
|
-
accessibilityLabel={
|
|
91
|
+
accessibilityLabel={accessibilityLabel}
|
|
86
92
|
accessibilityRole="adjustable"
|
|
87
93
|
accessible
|
|
88
94
|
className={slots.caption({ className })}
|
|
@@ -106,7 +112,7 @@ export function CalendarCaption({ className, ...props }: CalendarCaptionProps):
|
|
|
106
112
|
<Pressable
|
|
107
113
|
accessibilityActions={PAGE_ACTIONS}
|
|
108
114
|
accessibilityHint={hint}
|
|
109
|
-
accessibilityLabel={
|
|
115
|
+
accessibilityLabel={accessibilityLabel}
|
|
110
116
|
className={slots.caption({ className })}
|
|
111
117
|
disabled={isDisabled}
|
|
112
118
|
feedback="fade"
|
|
@@ -4,7 +4,13 @@ import { Pressable } from "../pressable";
|
|
|
4
4
|
import { Text } from "../text";
|
|
5
5
|
import { useCalendarPart } from "./calendar.context";
|
|
6
6
|
import { type CalendarDate, formatDate, isSameMonth, serialiseDate } from "./calendar.date";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
type CalendarDayState,
|
|
9
|
+
calendarVariants,
|
|
10
|
+
resolveDayAccessibilityLabel,
|
|
11
|
+
resolveDayState,
|
|
12
|
+
resolvePartTestID,
|
|
13
|
+
} from "./calendar.variants";
|
|
8
14
|
|
|
9
15
|
/** What a function child of `Calendar.Day` is handed. */
|
|
10
16
|
export type CalendarDayRenderProps = CalendarDayState & {
|
|
@@ -24,15 +30,6 @@ export type CalendarDayProps = {
|
|
|
24
30
|
className?: string;
|
|
25
31
|
};
|
|
26
32
|
|
|
27
|
-
/** The state words a screen reader adds after the date. */
|
|
28
|
-
function describeState(state: CalendarDayState): string | undefined {
|
|
29
|
-
const parts: string[] = [];
|
|
30
|
-
if (state.isToday) parts.push("Today");
|
|
31
|
-
if (state.rangeRole === "start") parts.push("Range start");
|
|
32
|
-
if (state.rangeRole === "end") parts.push("Range end");
|
|
33
|
-
return parts.length > 0 ? parts.join(", ") : undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
33
|
/**
|
|
37
34
|
* One day: its column share, the range band behind it, and the circle with the number.
|
|
38
35
|
*
|
|
@@ -43,8 +40,10 @@ function describeState(state: CalendarDayState): string | undefined {
|
|
|
43
40
|
* circle with nothing to join. An outside day with `showOutsideDays` off is an empty cell of the
|
|
44
41
|
* same height, so the grid's rows never move.
|
|
45
42
|
*
|
|
46
|
-
* Announced as a button with the full date
|
|
47
|
-
*
|
|
43
|
+
* Announced as a button labelled with the full date plus today and the range end it is —
|
|
44
|
+
* "Monday 5 October 2026, Today, Range start" — and `selected` and `disabled` as accessibility
|
|
45
|
+
* state. A read-only day is not announced disabled — `select` ignores its tap, and it neither
|
|
46
|
+
* fades nor plays a haptic.
|
|
48
47
|
*/
|
|
49
48
|
export function CalendarDay({ date, children, className }: CalendarDayProps): ReactElement {
|
|
50
49
|
const calendar = useCalendarPart("Calendar.Day");
|
|
@@ -85,13 +84,15 @@ export function CalendarDay({ date, children, className }: CalendarDayProps): Re
|
|
|
85
84
|
|
|
86
85
|
return (
|
|
87
86
|
<Pressable
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
accessibilityLabel={resolveDayAccessibilityLabel(
|
|
88
|
+
formatDate(date, { locale: calendar.locale, style: "full" }),
|
|
89
|
+
state
|
|
90
|
+
)}
|
|
90
91
|
accessibilityState={{ selected: state.isSelected }}
|
|
91
92
|
className={slots.cell({ className })}
|
|
92
|
-
disabled={
|
|
93
|
-
feedback="fade"
|
|
94
|
-
haptic="selection"
|
|
93
|
+
disabled={state.isUnavailable}
|
|
94
|
+
feedback={state.isPressable ? "fade" : "none"}
|
|
95
|
+
haptic={state.isPressable ? "selection" : false}
|
|
95
96
|
onPress={handlePress}
|
|
96
97
|
testID={resolvePartTestID(calendar.testID, `day-${serialiseDate(date)}`)}
|
|
97
98
|
>
|
|
@@ -52,7 +52,7 @@ export type CalendarContextValue = {
|
|
|
52
52
|
captionLayout: CalendarCaptionLayout;
|
|
53
53
|
/** The calendar's own `testID`, which its parts derive theirs from — see `resolvePartTestID`. */
|
|
54
54
|
testID: string | undefined;
|
|
55
|
-
/** The enclosing `Field.Label`'s text,
|
|
55
|
+
/** The enclosing `Field.Label`'s text, which the caption reads before the month. */
|
|
56
56
|
label: string | null;
|
|
57
57
|
};
|
|
58
58
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
2
|
import { Text } from "react-native";
|
|
3
3
|
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
4
|
+
import { Field } from "../field";
|
|
4
5
|
import { Calendar } from "./calendar";
|
|
5
6
|
import type { CalendarDate } from "./calendar.date";
|
|
6
7
|
|
|
@@ -28,11 +29,21 @@ describe("Calendar", () => {
|
|
|
28
29
|
expect(screen.getByRole("button", { name: "Next month" })).toBeOnTheScreen();
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
test("opens on today's month by the fake clock and marks today in the
|
|
32
|
+
test("opens on today's month by the fake clock and marks today in the label", async () => {
|
|
32
33
|
await renderWithProviders(<Calendar locale="en" testID="cal" />);
|
|
33
34
|
const today = screen.getByTestId("cal-day-2026-10-14");
|
|
34
|
-
expect(today).
|
|
35
|
-
expect(screen.getByTestId("cal-day-2026-10-15")).not.
|
|
35
|
+
expect(today.props.accessibilityLabel).toMatch(/, Today$/);
|
|
36
|
+
expect(screen.getByTestId("cal-day-2026-10-15").props.accessibilityLabel).not.toMatch(/Today/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("an enclosing Field.Label is read on the caption, before the month", async () => {
|
|
40
|
+
await renderWithProviders(
|
|
41
|
+
<Field>
|
|
42
|
+
<Field.Label>Date of birth</Field.Label>
|
|
43
|
+
<Calendar locale="en" testID="cal" />
|
|
44
|
+
</Field>
|
|
45
|
+
);
|
|
46
|
+
expect(screen.getByRole("button", { name: "Date of birth, October 2026" })).toBeOnTheScreen();
|
|
36
47
|
});
|
|
37
48
|
|
|
38
49
|
test("a day is a button named by its full date", async () => {
|
|
@@ -60,7 +71,7 @@ describe("Calendar", () => {
|
|
|
60
71
|
test("the today prop overrides the clock", async () => {
|
|
61
72
|
await renderWithProviders(<Calendar locale="en" testID="cal" today={day(2027, 3, 9)} />);
|
|
62
73
|
expect(screen.getByRole("button", { name: "March 2027" })).toBeOnTheScreen();
|
|
63
|
-
expect(screen.getByTestId("cal-day-2027-03-09")).
|
|
74
|
+
expect(screen.getByTestId("cal-day-2027-03-09").props.accessibilityLabel).toMatch(/, Today$/);
|
|
64
75
|
});
|
|
65
76
|
});
|
|
66
77
|
|
|
@@ -157,8 +168,8 @@ describe("Calendar", () => {
|
|
|
157
168
|
expect(onSelect).toHaveBeenLastCalledWith({ end: null, start: day(2026, 10, 5) });
|
|
158
169
|
await press("2026-10-09");
|
|
159
170
|
expect(onSelect).toHaveBeenLastCalledWith({ end: day(2026, 10, 9), start: day(2026, 10, 5) });
|
|
160
|
-
expect(screen.getByTestId("cal-day-2026-10-05")).
|
|
161
|
-
expect(screen.getByTestId("cal-day-2026-10-09")).
|
|
171
|
+
expect(screen.getByTestId("cal-day-2026-10-05").props.accessibilityLabel).toMatch(/, Range start$/);
|
|
172
|
+
expect(screen.getByTestId("cal-day-2026-10-09").props.accessibilityLabel).toMatch(/, Range end$/);
|
|
162
173
|
});
|
|
163
174
|
|
|
164
175
|
test("tapping an earlier day second makes it the start", async () => {
|
|
@@ -252,6 +263,12 @@ describe("Calendar", () => {
|
|
|
252
263
|
expect(onSelect).not.toHaveBeenCalled();
|
|
253
264
|
});
|
|
254
265
|
|
|
266
|
+
test("isReadOnly days are not announced disabled, the selected one included", async () => {
|
|
267
|
+
await renderWithProviders(<Calendar isReadOnly locale="en" selected={day(2026, 10, 5)} testID="cal" />);
|
|
268
|
+
expect(screen.getByTestId("cal-day-2026-10-05")).not.toBeDisabled();
|
|
269
|
+
expect(screen.getByTestId("cal-day-2026-10-14")).not.toBeDisabled();
|
|
270
|
+
});
|
|
271
|
+
|
|
255
272
|
test("isReadOnly ignores day taps but paging still works", async () => {
|
|
256
273
|
const onSelect = jest.fn();
|
|
257
274
|
const onMonthChange = jest.fn();
|
|
@@ -383,7 +383,8 @@ function CalendarRoot(props: CalendarProps): ReactElement {
|
|
|
383
383
|
* `minDate`/`maxDate` bound what can be picked and, unless `startMonth`/`endMonth` say otherwise,
|
|
384
384
|
* how far paging goes. `disabled` takes further matchers: a date, a span, weekdays or a predicate.
|
|
385
385
|
*
|
|
386
|
-
* `isDisabled` and `isInvalid` cascade in from an enclosing `Field`, whose label
|
|
386
|
+
* `isDisabled` and `isInvalid` cascade in from an enclosing `Field`, whose label the caption
|
|
387
|
+
* reads before the month.
|
|
387
388
|
* The week starts where the locale says, and names come from `Intl`.
|
|
388
389
|
*
|
|
389
390
|
* @example
|
|
@@ -13,8 +13,10 @@ import {
|
|
|
13
13
|
isDateSelected,
|
|
14
14
|
reconcileVisibleMonth,
|
|
15
15
|
resolveCalendarAxes,
|
|
16
|
+
resolveCaptionLabel,
|
|
16
17
|
resolveCaptionPage,
|
|
17
18
|
resolveCommittedPageDirection,
|
|
19
|
+
resolveDayAccessibilityLabel,
|
|
18
20
|
resolveDayState,
|
|
19
21
|
resolveDayTone,
|
|
20
22
|
resolveMonthBounds,
|
|
@@ -318,6 +320,56 @@ describe("resolveDayState", () => {
|
|
|
318
320
|
});
|
|
319
321
|
expect(resolveDayState({ ...base, cell, isCalendarDisabled: true }).isPressable).toBe(false);
|
|
320
322
|
});
|
|
323
|
+
|
|
324
|
+
test("only a day that cannot be picked is announced disabled; read-only alone is not", () => {
|
|
325
|
+
const cell = { date: d(2026, 10, 5), isOutside: false, weekIndex: 0, dayIndex: 0 };
|
|
326
|
+
expect(resolveDayState({ ...base, cell }).isUnavailable).toBe(false);
|
|
327
|
+
expect(resolveDayState({ ...base, cell, isReadOnly: true }).isUnavailable).toBe(false);
|
|
328
|
+
expect(resolveDayState({ ...base, cell, isDisabled: () => true }).isUnavailable).toBe(true);
|
|
329
|
+
expect(resolveDayState({ ...base, cell, isCalendarDisabled: true }).isUnavailable).toBe(true);
|
|
330
|
+
expect(resolveDayState({ ...base, cell, isCalendarDisabled: true, isReadOnly: true }).isUnavailable).toBe(true);
|
|
331
|
+
expect(resolveDayState({ ...base, cell: { ...cell, isOutside: true } }).isUnavailable).toBe(true);
|
|
332
|
+
expect(
|
|
333
|
+
resolveDayState({ ...base, cell: { ...cell, isOutside: true }, selectOutsideDays: true }).isUnavailable
|
|
334
|
+
).toBe(false);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe("resolveCaptionLabel", () => {
|
|
339
|
+
test("the caption reads the field's name before the month, since the grid itself is never read", () => {
|
|
340
|
+
expect(resolveCaptionLabel("Date of birth", "October 2026")).toBe("Date of birth, October 2026");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("with no field label it is just the month", () => {
|
|
344
|
+
expect(resolveCaptionLabel(null, "October 2026")).toBe("October 2026");
|
|
345
|
+
expect(resolveCaptionLabel("", "October 2026")).toBe("October 2026");
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe("resolveDayAccessibilityLabel", () => {
|
|
350
|
+
const plain = { isToday: false, rangeRole: null };
|
|
351
|
+
|
|
352
|
+
test("a plain day reads as just its date", () => {
|
|
353
|
+
expect(resolveDayAccessibilityLabel("Monday 5 October 2026", plain)).toBe("Monday 5 October 2026");
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("today and the range ends are in the label, so they read with hints off", () => {
|
|
357
|
+
expect(resolveDayAccessibilityLabel("Monday 5 October 2026", { isToday: true, rangeRole: "start" })).toBe(
|
|
358
|
+
"Monday 5 October 2026, Today, Range start"
|
|
359
|
+
);
|
|
360
|
+
expect(resolveDayAccessibilityLabel("Friday 9 October 2026", { ...plain, rangeRole: "end" })).toBe(
|
|
361
|
+
"Friday 9 October 2026, Range end"
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("a lone or middle range day adds nothing", () => {
|
|
366
|
+
expect(resolveDayAccessibilityLabel("Monday 5 October 2026", { ...plain, rangeRole: "only" })).toBe(
|
|
367
|
+
"Monday 5 October 2026"
|
|
368
|
+
);
|
|
369
|
+
expect(resolveDayAccessibilityLabel("Monday 5 October 2026", { ...plain, rangeRole: "middle" })).toBe(
|
|
370
|
+
"Monday 5 October 2026"
|
|
371
|
+
);
|
|
372
|
+
});
|
|
321
373
|
});
|
|
322
374
|
|
|
323
375
|
describe("resolveMonthBounds", () => {
|
|
@@ -270,6 +270,11 @@ export type CalendarDayState = {
|
|
|
270
270
|
isHidden: boolean;
|
|
271
271
|
/** Takes a tap. */
|
|
272
272
|
isPressable: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* Announced as disabled: it takes no tap for a reason other than `isReadOnly`. A read-only
|
|
275
|
+
* calendar shows an answer, so its days must not all read "dimmed".
|
|
276
|
+
*/
|
|
277
|
+
isUnavailable: boolean;
|
|
273
278
|
};
|
|
274
279
|
|
|
275
280
|
/**
|
|
@@ -305,6 +310,7 @@ export function resolveDayState({
|
|
|
305
310
|
const isSelected = showsSelection && isDateSelected(selection, date);
|
|
306
311
|
const rangeRole = showsSelection && selection.mode === "range" ? resolveRangeRole(selection.value, date) : null;
|
|
307
312
|
const dayDisabled = isDisabled(date);
|
|
313
|
+
const isUnavailable = isHidden || dayDisabled || isCalendarDisabled || (isOutside && !selectOutsideDays);
|
|
308
314
|
|
|
309
315
|
return {
|
|
310
316
|
isSelected,
|
|
@@ -314,10 +320,37 @@ export function resolveDayState({
|
|
|
314
320
|
isOutside,
|
|
315
321
|
isDisabled: dayDisabled,
|
|
316
322
|
isHidden,
|
|
317
|
-
isPressable: !
|
|
323
|
+
isPressable: !isUnavailable && !isReadOnly,
|
|
324
|
+
isUnavailable,
|
|
318
325
|
};
|
|
319
326
|
}
|
|
320
327
|
|
|
328
|
+
/**
|
|
329
|
+
* What a screen reader says for the caption: the enclosing `Field.Label`, then the caption text —
|
|
330
|
+
* "Date of birth, October 2026". The caption carries the field's name because it is the
|
|
331
|
+
* calendar's one accessible heading: the grid view is not `accessible`, and `role="grid"` maps to
|
|
332
|
+
* no iOS trait, so a label on the grid is never read.
|
|
333
|
+
*/
|
|
334
|
+
export function resolveCaptionLabel(fieldLabel: string | null, text: string): string {
|
|
335
|
+
return fieldLabel ? `${fieldLabel}, ${text}` : text;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* What a screen reader says for a day: the full date, then "Today" and the range end it is —
|
|
340
|
+
* "Monday 5 October 2026, Today, Range start". The state words sit in the label, not the hint,
|
|
341
|
+
* because many VoiceOver users turn hints off and would hear only the date.
|
|
342
|
+
*/
|
|
343
|
+
export function resolveDayAccessibilityLabel(
|
|
344
|
+
dateLabel: string,
|
|
345
|
+
{ isToday, rangeRole }: Pick<CalendarDayState, "isToday" | "rangeRole">
|
|
346
|
+
): string {
|
|
347
|
+
const parts = [dateLabel];
|
|
348
|
+
if (isToday) parts.push("Today");
|
|
349
|
+
if (rangeRole === "start") parts.push("Range start");
|
|
350
|
+
if (rangeRole === "end") parts.push("Range end");
|
|
351
|
+
return parts.join(", ");
|
|
352
|
+
}
|
|
353
|
+
|
|
321
354
|
/**
|
|
322
355
|
* The first and last months the arrows and the swipe can reach.
|
|
323
356
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { type SharedValue, useFrameCallback, useSharedValue } from "react-native-reanimated";
|
|
3
3
|
import { scheduleOnRN } from "react-native-worklets";
|
|
4
4
|
|
|
@@ -13,6 +13,15 @@ export type TextAnimationClockOptions = {
|
|
|
13
13
|
onLimit?: () => void;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
export type TextAnimationClock = {
|
|
17
|
+
/** Milliseconds into the current run. */
|
|
18
|
+
elapsed: SharedValue<number>;
|
|
19
|
+
/** The run `elapsed` has been rewound for. Lags `runId` until the rewind lands. */
|
|
20
|
+
run: SharedValue<number>;
|
|
21
|
+
/** The run this render belongs to, counted during render. */
|
|
22
|
+
runId: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
16
25
|
/**
|
|
17
26
|
* An elapsed-ms shared value that advances by each frame's `dt` while running.
|
|
18
27
|
*
|
|
@@ -24,17 +33,26 @@ export type TextAnimationClockOptions = {
|
|
|
24
33
|
* A run is identified by `runKey`. Changing it rewinds to 0, and a limit
|
|
25
34
|
* crossed by an older run is dropped rather than reported, so an interrupted
|
|
26
35
|
* animation never fires its predecessor's callback.
|
|
36
|
+
*
|
|
37
|
+
* The rewind runs in an effect, after the new render has committed, so a
|
|
38
|
+
* part drawn for the new run compares `run` with `runId` and holds its start
|
|
39
|
+
* until they match — new text never paints at the old run's end.
|
|
27
40
|
*/
|
|
28
41
|
export function useTextAnimationClock({
|
|
29
42
|
isRunning,
|
|
30
43
|
runKey,
|
|
31
44
|
limitMs,
|
|
32
45
|
onLimit,
|
|
33
|
-
}: TextAnimationClockOptions):
|
|
46
|
+
}: TextAnimationClockOptions): TextAnimationClock {
|
|
34
47
|
const elapsed = useSharedValue(0);
|
|
35
48
|
const run = useSharedValue(0);
|
|
36
49
|
const reported = useSharedValue(false);
|
|
37
50
|
const runRef = useRef(0);
|
|
51
|
+
// Counted during render, so the units of a new run know it before they paint.
|
|
52
|
+
const [counted, setCounted] = useState({ runKey, id: 0 });
|
|
53
|
+
const current = counted.runKey === runKey ? counted : { runKey, id: counted.id + 1 };
|
|
54
|
+
if (current !== counted) setCounted(current);
|
|
55
|
+
const runId = current.id;
|
|
38
56
|
const onLimitRef = useRef(onLimit);
|
|
39
57
|
|
|
40
58
|
useEffect(() => {
|
|
@@ -60,21 +78,21 @@ export function useTextAnimationClock({
|
|
|
60
78
|
elapsed.value = next;
|
|
61
79
|
}, false);
|
|
62
80
|
|
|
63
|
-
//
|
|
81
|
+
// `run` is written last, so a frame between the writes still holds the start.
|
|
64
82
|
useEffect(() => {
|
|
65
|
-
runRef.current
|
|
66
|
-
run.value = runRef.current;
|
|
83
|
+
runRef.current = runId;
|
|
67
84
|
elapsed.value = 0;
|
|
68
85
|
reported.value = false;
|
|
69
|
-
|
|
86
|
+
run.value = runId;
|
|
87
|
+
}, [runId, elapsed, reported, run]);
|
|
70
88
|
|
|
71
89
|
// After the rewind above, so a new run is live again; a run that already
|
|
72
90
|
// reached its limit stays off when `isRunning` flips back on.
|
|
73
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies:
|
|
91
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runId is the trigger, not a value read here
|
|
74
92
|
useEffect(() => {
|
|
75
93
|
frame.setActive(isRunning && !reported.value);
|
|
76
94
|
return () => frame.setActive(false);
|
|
77
|
-
}, [frame, isRunning, reported,
|
|
95
|
+
}, [frame, isRunning, reported, runId]);
|
|
78
96
|
|
|
79
|
-
return elapsed;
|
|
97
|
+
return { elapsed, run, runId };
|
|
80
98
|
}
|
|
@@ -10,6 +10,7 @@ import Animated, {
|
|
|
10
10
|
} from "react-native-reanimated";
|
|
11
11
|
import { useCalmMotion } from "../../hooks/use-calm-motion";
|
|
12
12
|
import { cn } from "../../lib/cn";
|
|
13
|
+
import { TEXT_MAX_FONT_SIZE_MULTIPLIER } from "../text/text.variants";
|
|
13
14
|
import type { TextAnimationBase } from "./text-animation.types";
|
|
14
15
|
import {
|
|
15
16
|
formatNumber,
|
|
@@ -177,6 +178,9 @@ export function TextAnimationRolling({
|
|
|
177
178
|
accessibilityHint,
|
|
178
179
|
}: TextAnimationRollingProps): ReactElement {
|
|
179
180
|
const isCalm = useCalmMotion();
|
|
181
|
+
// One cap for the measuring digit, the wheels and the static cells, the
|
|
182
|
+
// same default the other parts use, so a balance never outgrows its card.
|
|
183
|
+
const fontCap = maxFontSizeMultiplier ?? TEXT_MAX_FONT_SIZE_MULTIPLIER;
|
|
180
184
|
const textClass = cn(
|
|
181
185
|
useTextAnimationClass({ variant, size, weight, color, align, transform, className }),
|
|
182
186
|
"tabular-nums"
|
|
@@ -242,7 +246,7 @@ export function TextAnimationRolling({
|
|
|
242
246
|
{...HIDDEN}
|
|
243
247
|
allowFontScaling={allowFontScaling}
|
|
244
248
|
className={cn(textClass, slots.layer(), "opacity-0")}
|
|
245
|
-
maxFontSizeMultiplier={
|
|
249
|
+
maxFontSizeMultiplier={fontCap}
|
|
246
250
|
onLayout={onLayout}
|
|
247
251
|
>
|
|
248
252
|
0
|
|
@@ -259,7 +263,7 @@ export function TextAnimationRolling({
|
|
|
259
263
|
isLate={hasMounted}
|
|
260
264
|
key={key}
|
|
261
265
|
lineHeight={lineHeight}
|
|
262
|
-
maxFontSizeMultiplier={
|
|
266
|
+
maxFontSizeMultiplier={fontCap}
|
|
263
267
|
rank={rank}
|
|
264
268
|
stagger={stagger}
|
|
265
269
|
/>
|
|
@@ -269,7 +273,7 @@ export function TextAnimationRolling({
|
|
|
269
273
|
allowFontScaling={allowFontScaling}
|
|
270
274
|
className={textClass}
|
|
271
275
|
key={key}
|
|
272
|
-
maxFontSizeMultiplier={
|
|
276
|
+
maxFontSizeMultiplier={fontCap}
|
|
273
277
|
>
|
|
274
278
|
{cell.text}
|
|
275
279
|
</NativeText>
|
|
@@ -9,9 +9,11 @@ import Animated, {
|
|
|
9
9
|
} from "react-native-reanimated";
|
|
10
10
|
import { useCalmMotion } from "../../hooks/use-calm-motion";
|
|
11
11
|
import { cn } from "../../lib/cn";
|
|
12
|
+
import { TEXT_MAX_FONT_SIZE_MULTIPLIER } from "../text/text.variants";
|
|
12
13
|
import type { TextAnimationBase } from "./text-animation.types";
|
|
13
14
|
import {
|
|
14
15
|
resolveNextPhrase,
|
|
16
|
+
resolveSwapProgress,
|
|
15
17
|
resolveWidestPhrase,
|
|
16
18
|
TEXT_ANIMATION_ROTATE_DISTANCE,
|
|
17
19
|
TEXT_ANIMATION_ROTATE_INTERVAL_MS,
|
|
@@ -44,6 +46,11 @@ type RotatingLayerProps = {
|
|
|
44
46
|
text: string;
|
|
45
47
|
phase: "enter" | "exit";
|
|
46
48
|
progress: SharedValue<number>;
|
|
49
|
+
/** The swap `progress` has been rewound for. */
|
|
50
|
+
swap: SharedValue<number>;
|
|
51
|
+
/** The swap this layer was rendered for — it holds its start until `swap` catches up. */
|
|
52
|
+
swapId: number;
|
|
53
|
+
isSwapping: boolean;
|
|
47
54
|
distance: number;
|
|
48
55
|
className: string;
|
|
49
56
|
allowFontScaling?: boolean;
|
|
@@ -53,19 +60,23 @@ type RotatingLayerProps = {
|
|
|
53
60
|
/**
|
|
54
61
|
* One phrase over the slot — the one arriving or the one leaving. Both read
|
|
55
62
|
* the same progress, so the swap is a single animation however fast the
|
|
56
|
-
* interval runs.
|
|
63
|
+
* interval runs. Progress rewinds in an effect, after the layers mount, so a
|
|
64
|
+
* layer waits for `swap` to reach its own swap before it follows progress.
|
|
57
65
|
*/
|
|
58
66
|
function TextAnimationRotatingLayer({
|
|
59
67
|
text,
|
|
60
68
|
phase,
|
|
61
69
|
progress,
|
|
70
|
+
swap,
|
|
71
|
+
swapId,
|
|
72
|
+
isSwapping,
|
|
62
73
|
distance,
|
|
63
74
|
className,
|
|
64
75
|
allowFontScaling,
|
|
65
76
|
maxFontSizeMultiplier,
|
|
66
77
|
}: RotatingLayerProps): ReactElement {
|
|
67
78
|
const style = useAnimatedStyle(() => {
|
|
68
|
-
const t = progress.value;
|
|
79
|
+
const t = resolveSwapProgress(isSwapping, swap.value, swapId, progress.value);
|
|
69
80
|
if (phase === "enter") return { opacity: t, transform: [{ translateY: (1 - t) * distance }] };
|
|
70
81
|
return { opacity: 1 - t, transform: [{ translateY: -t * distance }] };
|
|
71
82
|
});
|
|
@@ -115,13 +126,16 @@ export function TextAnimationRotating({
|
|
|
115
126
|
const isCalm = useCalmMotion();
|
|
116
127
|
const textClass = useTextAnimationClass({ variant, size, weight, color, align, transform, className });
|
|
117
128
|
const phrasesKey = phrases.join("\u0000");
|
|
118
|
-
|
|
129
|
+
// `swapId` counts every swap, so each one's layers know which rewind is theirs.
|
|
130
|
+
const [state, setState] = useState({ key: phrasesKey, index: 0, previous: -1, swapId: 0 });
|
|
119
131
|
// A new list starts over, committed during render, so switching away and
|
|
120
132
|
// back never restores the old list's index or its transition.
|
|
121
|
-
if (state.key !== phrasesKey) setState({ key: phrasesKey, index: 0, previous: -1 });
|
|
133
|
+
if (state.key !== phrasesKey) setState({ key: phrasesKey, index: 0, previous: -1, swapId: state.swapId });
|
|
122
134
|
// Calm motion holds the first phrase with no swap in flight.
|
|
123
|
-
const { index, previous } =
|
|
135
|
+
const { index, previous, swapId } =
|
|
136
|
+
state.key === phrasesKey && !isCalm ? state : { index: 0, previous: -1, swapId: state.swapId };
|
|
124
137
|
const progress = useSharedValue(1);
|
|
138
|
+
const swap = useSharedValue(0);
|
|
125
139
|
const isRotating = isActive && !isCalm && phrases.length > 1;
|
|
126
140
|
|
|
127
141
|
useEffect(() => {
|
|
@@ -130,7 +144,7 @@ export function TextAnimationRotating({
|
|
|
130
144
|
setState((current) => {
|
|
131
145
|
const from = current.key === phrasesKey ? current.index : 0;
|
|
132
146
|
const next = resolveNextPhrase(from, phrases.length, true) ?? from;
|
|
133
|
-
return { key: phrasesKey, index: next, previous: from };
|
|
147
|
+
return { key: phrasesKey, index: next, previous: from, swapId: current.swapId + 1 };
|
|
134
148
|
});
|
|
135
149
|
}, intervalMs);
|
|
136
150
|
return () => clearInterval(timer);
|
|
@@ -139,18 +153,20 @@ export function TextAnimationRotating({
|
|
|
139
153
|
// Turning calm motion on drops the rotated state, so resuming waits for the
|
|
140
154
|
// next swap instead of replaying the transition that was cut short.
|
|
141
155
|
useEffect(() => {
|
|
142
|
-
if (isCalm) setState({ key: phrasesKey, index: 0, previous: -1 });
|
|
156
|
+
if (isCalm) setState((current) => ({ key: phrasesKey, index: 0, previous: -1, swapId: current.swapId }));
|
|
143
157
|
}, [isCalm, phrasesKey]);
|
|
144
158
|
|
|
145
|
-
//
|
|
159
|
+
// `swap` is written after the rewind, so a frame between the writes still
|
|
160
|
+
// holds the layers at their start.
|
|
146
161
|
useEffect(() => {
|
|
147
162
|
if (previous < 0) {
|
|
148
163
|
progress.value = 1;
|
|
149
164
|
return;
|
|
150
165
|
}
|
|
151
166
|
progress.value = 0;
|
|
167
|
+
swap.value = swapId;
|
|
152
168
|
progress.value = withTiming(1, { duration: transitionMs, easing: Easing.out(Easing.cubic) });
|
|
153
|
-
}, [
|
|
169
|
+
}, [swapId, previous, transitionMs, progress, swap]);
|
|
154
170
|
|
|
155
171
|
const [widths, setWidths] = useState<Readonly<Record<string, number>>>({});
|
|
156
172
|
const guess = useMemo(() => resolveWidestPhrase(phrases), [phrases]);
|
|
@@ -175,7 +191,11 @@ export function TextAnimationRotating({
|
|
|
175
191
|
const leaving = previous >= 0 ? phrases[previous] : undefined;
|
|
176
192
|
const reserved = reserve === "widest" ? (phrases[widest] ?? shown) : shown;
|
|
177
193
|
const distance = transition.kind === "slide" ? (transition.distance ?? TEXT_ANIMATION_ROTATE_DISTANCE) : 0;
|
|
178
|
-
|
|
194
|
+
// The same default cap as the other parts, for the slot, the measures and the layers.
|
|
195
|
+
const textProps = {
|
|
196
|
+
allowFontScaling,
|
|
197
|
+
maxFontSizeMultiplier: maxFontSizeMultiplier ?? TEXT_MAX_FONT_SIZE_MULTIPLIER,
|
|
198
|
+
};
|
|
179
199
|
|
|
180
200
|
// The in-flow copy sizes the slot; the hidden measures settle which phrase
|
|
181
201
|
// really is widest once they have laid out; the layers draw over the slot.
|
|
@@ -213,8 +233,11 @@ export function TextAnimationRotating({
|
|
|
213
233
|
{...textProps}
|
|
214
234
|
className={textClass}
|
|
215
235
|
distance={distance}
|
|
236
|
+
isSwapping
|
|
216
237
|
key={`exit-${previous}`}
|
|
217
238
|
progress={progress}
|
|
239
|
+
swap={swap}
|
|
240
|
+
swapId={swapId}
|
|
218
241
|
phase="exit"
|
|
219
242
|
text={leaving}
|
|
220
243
|
/>
|
|
@@ -223,8 +246,11 @@ export function TextAnimationRotating({
|
|
|
223
246
|
{...textProps}
|
|
224
247
|
className={textClass}
|
|
225
248
|
distance={distance}
|
|
249
|
+
isSwapping={leaving !== undefined}
|
|
226
250
|
key={`enter-${index}`}
|
|
227
251
|
progress={progress}
|
|
252
|
+
swap={swap}
|
|
253
|
+
swapId={swapId}
|
|
228
254
|
phase="enter"
|
|
229
255
|
text={shown}
|
|
230
256
|
/>
|
|
@@ -202,7 +202,7 @@ export function TextAnimationTyping({
|
|
|
202
202
|
const rest = resolveTypingRest(timeline);
|
|
203
203
|
const runKey = `${phrasesKey}|${speed}|${eraseSpeed}|${holdMs}|${isLooping}|${isActive}`;
|
|
204
204
|
|
|
205
|
-
const elapsed = useTextAnimationClock({
|
|
205
|
+
const { elapsed } = useTextAnimationClock({
|
|
206
206
|
isRunning: isActive && !isCalm,
|
|
207
207
|
runKey,
|
|
208
208
|
limitMs: Number.POSITIVE_INFINITY,
|
|
@@ -5,7 +5,7 @@ import { resolveTextClass, TEXT_MAX_FONT_SIZE_MULTIPLIER } from "../text/text.va
|
|
|
5
5
|
import type { TextAnimationBase } from "./text-animation.types";
|
|
6
6
|
import {
|
|
7
7
|
resolveEffectFrame,
|
|
8
|
-
|
|
8
|
+
resolveRunProgress,
|
|
9
9
|
type TextAnimationEffect,
|
|
10
10
|
type TypingSample,
|
|
11
11
|
} from "./text-animation.variants";
|
|
@@ -42,6 +42,10 @@ export type TextAnimationUnitDrive =
|
|
|
42
42
|
| {
|
|
43
43
|
kind: "reveal";
|
|
44
44
|
elapsed: SharedValue<number>;
|
|
45
|
+
/** The run the clock has rewound for. */
|
|
46
|
+
run: SharedValue<number>;
|
|
47
|
+
/** The run this unit was rendered for — it holds its start until `run` catches up. */
|
|
48
|
+
runId: number;
|
|
45
49
|
delayMs: number;
|
|
46
50
|
staggerMs: number;
|
|
47
51
|
durationMs: number;
|
|
@@ -89,7 +93,16 @@ export function TextAnimationUnit({
|
|
|
89
93
|
const shown = isAtRest || (sample.phraseIndex === drive.phraseIndex && drive.index < sample.visibleCount);
|
|
90
94
|
return { opacity: shown ? 1 : 0 };
|
|
91
95
|
}
|
|
92
|
-
const t = isAtRest
|
|
96
|
+
const t = isAtRest
|
|
97
|
+
? 1
|
|
98
|
+
: resolveRunProgress(
|
|
99
|
+
drive.run.value,
|
|
100
|
+
drive.runId,
|
|
101
|
+
drive.elapsed.value,
|
|
102
|
+
drive.delayMs,
|
|
103
|
+
drive.staggerMs,
|
|
104
|
+
drive.durationMs
|
|
105
|
+
);
|
|
93
106
|
const frame = resolveEffectFrame(drive.effect, t);
|
|
94
107
|
return {
|
|
95
108
|
opacity: frame.opacity,
|
|
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, jest, test } from "@jest/globals";
|
|
|
2
2
|
import type { ReactElement, ReactNode } from "react";
|
|
3
3
|
import { CalmMotionProvider } from "../../hooks/use-calm-motion";
|
|
4
4
|
import { act, renderWithProviders, screen } from "../../test/render";
|
|
5
|
+
import { TEXT_MAX_FONT_SIZE_MULTIPLIER } from "../text/text.variants";
|
|
5
6
|
import { TextAnimation } from "./text-animation";
|
|
6
7
|
|
|
7
8
|
function Calm({ children }: { children: ReactNode }): ReactElement {
|
|
@@ -132,6 +133,12 @@ describe("TextAnimation.Rotating", () => {
|
|
|
132
133
|
expect(screen.getAllByLabelText(/./)).toHaveLength(1);
|
|
133
134
|
});
|
|
134
135
|
|
|
136
|
+
test("caps font scaling at the default every other part uses", async () => {
|
|
137
|
+
await renderWithProviders(<TextAnimation.Rotating phrases={["fast", "calm"]} />);
|
|
138
|
+
const texts = screen.getAllByText(/./, { includeHiddenElements: true });
|
|
139
|
+
for (const text of texts) expect(text.props.maxFontSizeMultiplier).toBe(TEXT_MAX_FONT_SIZE_MULTIPLIER);
|
|
140
|
+
});
|
|
141
|
+
|
|
135
142
|
test("hides the layers and probes from assistive technology", async () => {
|
|
136
143
|
await renderWithProviders(<TextAnimation.Rotating phrases={["fast", "calm"]} />);
|
|
137
144
|
expect(screen.queryByText("fast")).not.toBeOnTheScreen();
|
|
@@ -263,6 +270,12 @@ describe("TextAnimation.Rolling", () => {
|
|
|
263
270
|
expect(screen.getByRole("text", { name: "$12.5k" })).toBeOnTheScreen();
|
|
264
271
|
});
|
|
265
272
|
|
|
273
|
+
test("caps font scaling at the default every other part uses", async () => {
|
|
274
|
+
await renderWithProviders(<TextAnimation.Rolling prefix="$" value={1284} />);
|
|
275
|
+
const texts = screen.getAllByText(/./, { includeHiddenElements: true });
|
|
276
|
+
for (const text of texts) expect(text.props.maxFontSizeMultiplier).toBe(TEXT_MAX_FONT_SIZE_MULTIPLIER);
|
|
277
|
+
});
|
|
278
|
+
|
|
266
279
|
test("hides every wheel digit from assistive technology", async () => {
|
|
267
280
|
await renderWithProviders(<TextAnimation.Rolling value={42} />);
|
|
268
281
|
expect(screen.queryByText("4")).not.toBeOnTheScreen();
|
|
@@ -107,6 +107,8 @@ function buildPieces(text: string, split: "word" | "character"): { pieces: Revea
|
|
|
107
107
|
type UnitShared = {
|
|
108
108
|
className: string;
|
|
109
109
|
elapsed: SharedValue<number>;
|
|
110
|
+
run: SharedValue<number>;
|
|
111
|
+
runId: number;
|
|
110
112
|
delayMs: number;
|
|
111
113
|
durationMs: number;
|
|
112
114
|
effect: TextAnimationEffect;
|
|
@@ -124,6 +126,8 @@ function renderUnit(shared: UnitShared, key: string, text: string, index: number
|
|
|
124
126
|
drive={{
|
|
125
127
|
kind: "reveal",
|
|
126
128
|
elapsed: shared.elapsed,
|
|
129
|
+
run: shared.run,
|
|
130
|
+
runId: shared.runId,
|
|
127
131
|
delayMs: shared.delayMs,
|
|
128
132
|
staggerMs: shared.delays[index] ?? 0,
|
|
129
133
|
durationMs: shared.durationMs,
|
|
@@ -212,7 +216,7 @@ function TextAnimationReveal({
|
|
|
212
216
|
// A `line` split has no units until the paragraph is measured, so its clock
|
|
213
217
|
// waits for them rather than reaching a zero limit on an empty reveal.
|
|
214
218
|
const isMeasured = split !== "line" || lines !== null;
|
|
215
|
-
const elapsed = useTextAnimationClock({
|
|
219
|
+
const { elapsed, run, runId } = useTextAnimationClock({
|
|
216
220
|
isRunning: isActive && !isCalm && isMeasured,
|
|
217
221
|
runKey,
|
|
218
222
|
limitMs: total,
|
|
@@ -228,6 +232,8 @@ function TextAnimationReveal({
|
|
|
228
232
|
const shared: UnitShared = {
|
|
229
233
|
className: textClass,
|
|
230
234
|
elapsed,
|
|
235
|
+
run,
|
|
236
|
+
runId,
|
|
231
237
|
delayMs,
|
|
232
238
|
durationMs,
|
|
233
239
|
effect,
|
|
@@ -16,8 +16,10 @@ import {
|
|
|
16
16
|
resolveRollDirection,
|
|
17
17
|
resolveRollTarget,
|
|
18
18
|
resolveRowJustify,
|
|
19
|
+
resolveRunProgress,
|
|
19
20
|
resolveStaggerDelay,
|
|
20
21
|
resolveStaggerDelays,
|
|
22
|
+
resolveSwapProgress,
|
|
21
23
|
resolveTotalDuration,
|
|
22
24
|
resolveTypedPhrase,
|
|
23
25
|
resolveTypedRange,
|
|
@@ -197,6 +199,17 @@ describe("resolveUnitProgress", () => {
|
|
|
197
199
|
});
|
|
198
200
|
});
|
|
199
201
|
|
|
202
|
+
describe("resolveRunProgress", () => {
|
|
203
|
+
test("holds a unit at its start until the clock has rewound for its run", () => {
|
|
204
|
+
expect(resolveRunProgress(1, 2, 5000, 0, 0, 300)).toBe(0);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("follows the clock once the run is current", () => {
|
|
208
|
+
expect(resolveRunProgress(2, 2, 5000, 0, 0, 300)).toBe(1);
|
|
209
|
+
expect(resolveRunProgress(2, 2, 0, 0, 0, 300)).toBe(0);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
200
213
|
describe("resolveEffectFrame", () => {
|
|
201
214
|
test("every effect rests at full opacity, no offset, full scale", () => {
|
|
202
215
|
const effects = [
|
|
@@ -353,6 +366,20 @@ describe("resolveNextPhrase", () => {
|
|
|
353
366
|
});
|
|
354
367
|
});
|
|
355
368
|
|
|
369
|
+
describe("resolveSwapProgress", () => {
|
|
370
|
+
test("shows a phrase whole when no swap is in flight", () => {
|
|
371
|
+
expect(resolveSwapProgress(false, 0, 3, 0.4)).toBe(1);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test("holds a new swap at its start until progress has rewound for it", () => {
|
|
375
|
+
expect(resolveSwapProgress(true, 2, 3, 1)).toBe(0);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("follows progress once the swap is current", () => {
|
|
379
|
+
expect(resolveSwapProgress(true, 3, 3, 0.4)).toBe(0.4);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
356
383
|
describe("resolveWidestPhrase", () => {
|
|
357
384
|
test("picks the most graphemes, the first on a tie", () => {
|
|
358
385
|
expect(resolveWidestPhrase(["fast", "reliable", "small", "accurate"])).toBe(1);
|
|
@@ -462,6 +489,12 @@ describe("resolveRollDirection", () => {
|
|
|
462
489
|
expect(resolveRollDirection(2, 2)).toBe("up");
|
|
463
490
|
expect(resolveRollDirection(2, 1)).toBe("down");
|
|
464
491
|
});
|
|
492
|
+
|
|
493
|
+
test("follows the magnitude of a negative number, not its sign", () => {
|
|
494
|
+
expect(resolveRollDirection(-19, -20)).toBe("up");
|
|
495
|
+
expect(resolveRollDirection(-20, -19)).toBe("down");
|
|
496
|
+
expect(resolveRollDirection(-3, 3)).toBe("up");
|
|
497
|
+
});
|
|
465
498
|
});
|
|
466
499
|
|
|
467
500
|
describe("resolveWheelOffset", () => {
|
|
@@ -410,6 +410,35 @@ export function resolveUnitProgress(
|
|
|
410
410
|
return easeOutCubic(linear);
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
+
/**
|
|
414
|
+
* A rotating layer's progress. With no swap in flight the phrase shows whole;
|
|
415
|
+
* a layer rendered for a swap holds its start until progress has rewound for
|
|
416
|
+
* that swap, so the arriving phrase never paints a frame fully shown.
|
|
417
|
+
*/
|
|
418
|
+
export function resolveSwapProgress(isSwapping: boolean, shownSwap: number, swapId: number, progress: number): number {
|
|
419
|
+
"worklet";
|
|
420
|
+
if (!isSwapping) return 1;
|
|
421
|
+
return shownSwap === swapId ? progress : 0;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* A unit's progress on its own run. Until the clock has rewound for the run
|
|
426
|
+
* the unit was rendered for, it holds the unit at its start, so new text never
|
|
427
|
+
* paints a frame at the previous run's finished value.
|
|
428
|
+
*/
|
|
429
|
+
export function resolveRunProgress(
|
|
430
|
+
shownRun: number,
|
|
431
|
+
runId: number,
|
|
432
|
+
elapsedMs: number,
|
|
433
|
+
delayMs: number,
|
|
434
|
+
staggerDelayMs: number,
|
|
435
|
+
durationMs: number
|
|
436
|
+
): number {
|
|
437
|
+
"worklet";
|
|
438
|
+
if (shownRun !== runId) return 0;
|
|
439
|
+
return resolveUnitProgress(elapsedMs, delayMs, staggerDelayMs, durationMs);
|
|
440
|
+
}
|
|
441
|
+
|
|
413
442
|
/**
|
|
414
443
|
* What a unit looks like at progress `t`. Only opacity and transform — a
|
|
415
444
|
* unit's layout is final from the first frame, so nothing reflows as it enters.
|
|
@@ -691,9 +720,13 @@ export function resolveRollTarget(currentPos: number, digit: number, direction:
|
|
|
691
720
|
return base + delta;
|
|
692
721
|
}
|
|
693
722
|
|
|
694
|
-
/**
|
|
723
|
+
/**
|
|
724
|
+
* Wheels roll up when the shown digits grow or hold, down when they shrink.
|
|
725
|
+
* The wheels draw the magnitude — the sign is a static cell — so −19 → −20
|
|
726
|
+
* rolls up, the short way, though the value went down.
|
|
727
|
+
*/
|
|
695
728
|
export function resolveRollDirection(previous: number, next: number): RollDirection {
|
|
696
|
-
return next < previous ? "down" : "up";
|
|
729
|
+
return Math.abs(next) < Math.abs(previous) ? "down" : "up";
|
|
697
730
|
}
|
|
698
731
|
|
|
699
732
|
/**
|