Skip to content
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/refresh-control-reduced-motion-cross-fade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] With Reduce Motion on a phone, Lab's RefreshControl keeps its list in view when a pull is released or a refresh ends. It cross-fades to its new place instead of blanking between the two. The cross-fade comes from a new export of `internal/touch`; apps import nothing new.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This holds only for lists the copy can take: over 1,500 elements, playReducedMotionCrossFade returns null and the animator still dips the list through opacity 0 (transientCopy.ts:47-52). Suggested: "…keeps a list of up to 1,500 elements in view when a pull is released or a refresh ends; a larger list keeps the dip."


@vjeux
1 change: 1 addition & 0 deletions apps/sandbox/scripts/next-export-routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"/pages/perf-scenes/",
"/pages/polymorphic-link/",
"/pages/powersearch-phone/",
"/pages/refresh-control/",
"/pages/scroll-edge-taps/",
"/pages/shell-lab/",
"/pages/showcase-components/",
Expand Down
118 changes: 118 additions & 0 deletions apps/sandbox/src/app/(raw)/pages/refresh-control/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

/**
* @file page.tsx
* @input Nothing
* @output A bare page with a RefreshControl list in a fixed-height card,
* above rows that make the document scroll. A pull past the trigger
* refreshes for 1.5 s: the list settles below the spinner, then returns to
* the top.
* @position A raw page, with no sandbox chrome, for checking a pull to refresh
* on a phone, with motion and under Reduce Motion. The page scrolls with
* the document.
*/

import {useCallback, useState} from 'react';
import * as stylex from '@stylexjs/stylex';
import {REFRESH_REVEAL_VAR, useRefreshControl} from '@astryxdesign/lab';
import {Card} from '@astryxdesign/core/Card';
import {VStack} from '@astryxdesign/core/Layout';
import {List, ListItem} from '@astryxdesign/core/List';
import {Spinner} from '@astryxdesign/core/Spinner';
import {Heading, Text} from '@astryxdesign/core/Text';

const REFRESH_MS = 1500;

const LIST_ROWS = Array.from(
{length: 30},
(_, index) => `Message ${index + 1}`,
);
const PAGE_ROWS = Array.from({length: 30}, (_, index) => `Row ${index + 1}`);

const styles = stylex.create({
scroller: {height: '100%', overflowY: 'auto'},
content: {position: 'relative'},
// The indicator's band sits above the content, inside a box that clips it.
band: {
position: 'absolute',
insetInline: 0,
bottom: '100%',
height: '100lvh',
overflow: 'hidden',
pointerEvents: 'none',
},
indicator: {
position: 'absolute',
insetInline: 0,
bottom: 0,
height: 60,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
revealed: (opacity: string) => ({opacity}),
});

export default function RefreshControlPage() {
const [count, setCount] = useState(0);
const onRefresh = useCallback(async () => {
await new Promise<void>(resolve => {
setTimeout(resolve, REFRESH_MS);
});
setCount(value => value + 1);
}, []);
const control = useRefreshControl({onRefresh, announce: 'Refreshing'});
return (
<VStack gap={4} padding={4}>
<VStack gap={1}>
<Heading level={1}>Refresh control</Heading>
<Text color="secondary">
With the messages at the top, pull them down past the spinner and let
go. They wait below the spinner while the refresh runs, then go back
to the top.
</Text>
</VStack>
<Text>{`Refreshed ${count} times`}</Text>
<Card height="60dvh" padding={0}>
<div
{...stylex.props(styles.scroller)}
role="region"
aria-label="Messages"
tabIndex={0}>
<div
ref={control.contentRef}
{...stylex.props(styles.content)}
aria-busy={control.isRefreshing || undefined}>
<List hasDividers>
{LIST_ROWS.map(row => (
<ListItem key={row} label={row} />
))}
</List>
<div {...stylex.props(styles.band)}>
<div
ref={control.indicatorRef}
aria-hidden
{...stylex.props(styles.indicator)}>
<span
{...stylex.props(
styles.revealed(`var(${REFRESH_REVEAL_VAR}, 0)`),
)}>
<Spinner size="lg" shade="subtle" />
</span>
</div>
</div>
</div>
</div>
</Card>
<VStack gap={2}>
{PAGE_ROWS.map(row => (
<Text key={row} color="secondary">
{row}
</Text>
))}
</VStack>
</VStack>
);
}
6 changes: 6 additions & 0 deletions apps/sandbox/src/app/sandboxPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export const categories: SandboxCategory[] = [
description:
'A DropdownMenu in a fixed top bar that opens as a finger presses it, and one in the content, on a page that scrolls with the document',
},
{
name: 'Refresh Control',
href: '/pages/refresh-control/',
description:
'A RefreshControl list in a card on a page that scrolls with the document, to check a pull to refresh on a phone, also under Reduce Motion',
},
{
name: 'BottomSheet Pull',
href: '/pages/bottom-sheet-pull/',
Expand Down
28 changes: 20 additions & 8 deletions apps/storybook/stories/PullToRefresh.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

import {useCallback, useState, type ReactNode} from 'react';
import {useCallback, useEffect, useState, type ReactNode} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {REFRESH_REVEAL_VAR, useRefreshControl} from '@astryxdesign/lab';
import {Button} from '@astryxdesign/core/Button';
Expand Down Expand Up @@ -163,19 +163,31 @@ function useInbox(refreshMs: number) {
/**
* A list in the app's own scroll container. Pull it down past the top on a
* touch screen, or with a trackpad's two-finger scroll. Past the trigger, the
* refresh starts with the finger down.
* refresh starts with the finger down. The page can dispatch
* `refreshcontrol-story-unmount` on `window` to unmount the list, so a test
* can unmount it in the middle of a change.
*/
export const InAScrollContainer: Story = {
render: function InAScrollContainerStory({refreshMs, rows}) {
const {count, onRefresh} = useInbox(refreshMs);
const [isMounted, setIsMounted] = useState(true);
useEffect(() => {
// Effect: subscribes to the page's window event that unmounts the list.
const unmount = () => setIsMounted(false);
window.addEventListener('refreshcontrol-story-unmount', unmount);
return () =>
window.removeEventListener('refreshcontrol-story-unmount', unmount);
}, []);
return (
<div style={{height: '100dvh'}}>
<PullToRefresh
onRefresh={onRefresh}
count={count}
text={`Updated ${count} times`}>
<Messages rows={rows} count={count} />
</PullToRefresh>
{isMounted && (
<PullToRefresh
onRefresh={onRefresh}
count={count}
text={`Updated ${count} times`}>
<Messages rows={rows} count={count} />
</PullToRefresh>
)}
</div>
);
},
Expand Down
8 changes: 6 additions & 2 deletions docs/architecture/component-style-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ not evidence of conformance or violation.
handoff between sheets, such as the cross-fade
`design:reduced-motion` DR2 requires; AppShell's old content wrap during a
side nav collapse or expand (`component:AppShell` FR17); the SideNav rail's
old state during a collapse or expand (`component:SideNav` FR6); or one moving preview while a
reorderable item is dragged (`design:ordered-collection-reordering`); it is
old state during a collapse or expand (`component:SideNav` FR6); the old
place of content that a Reduce Motion cross-fade moves, fading out as the
content fades in at its new place, such as RefreshControl's list at a
release or a refresh's end (`design:reduced-motion` DR2); or one moving
preview while a reorderable item is dragged
(`design:ordered-collection-reordering`); it is
made by one Core mechanism for its kind, rather than by each component, and is removed within 1
second of the transition ending. Until that shared mechanism exists, a
layer's own exit, presentation-switch, or handoff copy, or a reorderable
Expand Down
5 changes: 4 additions & 1 deletion docs/architecture/react-component-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ those contracts, and one user-facing rule that no component owns: how a
subpath too: it marks a group's member so press feedback leaves its press to
the group's tracker.
`prepareFocusReturnOnRemoval` is on that subpath too: it returns focus when
a removal loses it.
a removal loses it. `playReducedMotionCrossFade` is on that subpath too:
under Reduce Motion, it cross-fades an element through an inert copy, so the
element's area never goes blank. The animator and `motion/reducedMotion.ts`
give only a dip, which blanks the area between the old state and the new one.
- **INV15 — The animator animates a number.** The animator has a value mode:
it plays a number, such as a count or a chart value, on the same timing as its property channels: theme motion tokens for a program-started change, and measured springs only where `spec:AST-094` FR45 keeps them, and hands the value to an `onUpdate`
callback each frame for the component to format and write. The component owns
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/internal/touch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ describe('internal/touch', () => {
);
});

it("re-exports by name the cross-fade Lab's RefreshControl plays", async () => {
const entry: Record<string, unknown> = await import('./touch');
const crossFade = await import('../motion/reducedMotionCrossFade');
// Identity alone passes when both sides are undefined.
expect(typeof entry.playReducedMotionCrossFade).toBe('function');
expect(entry.playReducedMotionCrossFade).toBe(
crossFade.playReducedMotionCrossFade,
);
});

it("re-exports by name the focus hand-off Lab's Comments reads", async () => {
const entry: Record<string, unknown> = await import('./touch');
const swap = await import('../utils/useFocusAcrossSwap');
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/internal/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export type {ActionGroupTrackingOptions} from '../hooks/useActionGroupTracking';
// Lab's TabBar finds a panel's scroll area with Core's scroll test.
export {measureLogicalScrollAxis} from '../hooks/scrollGeometry';

// Lab's RefreshControl cross-fades its list through a copy under Reduce
// Motion, so the list shows on every frame.
export {playReducedMotionCrossFade} from '../motion/reducedMotionCrossFade';
export type {ReducedMotionCrossFade} from '../motion/reducedMotionCrossFade';

// Lab's Comments carries focus to the control that replaces a pressed one,
// Mark as resolved and Reopen, with the same focus hand-off as Core.
export {useFocusAcrossSwap} from '../utils/useFocusAcrossSwap';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/motion/animatedLayout.boundary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('architecture:react-component-runtime INV12 source boundary', () => {
}
});

it("keeps the copy mechanism to the swap and the layer's exit copy", () => {
it("keeps the copy mechanism to the swap, the layer's exit copy and the Reduce Motion cross-fade", () => {
const users = sourceFiles(coreSrc)
.filter(path =>
/from '[./]+(motion\/)?transientCopy'/.test(readFileSync(path, 'utf8')),
Expand All @@ -146,6 +146,7 @@ describe('architecture:react-component-runtime INV12 source boundary', () => {
expect(users).toEqual([
'Layer/layerExitCopy.ts',
'motion/animatedLayout.ts',
'motion/reducedMotionCrossFade.ts',
]);
});

Expand Down
Loading