Repository navigation
chore(sandbox): preview only, two Reduce Motion returns of a pulled list #11093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4b4aaee
test(RefreshControl): the list shows on every Reduce Motion frame
vjeux 9fec06a
fix(RefreshControl): a Reduce Motion release cross-fades the list
vjeux 4195083
chore(sandbox): a RefreshControl page for a phone check
vjeux 45469bb
chore(sandbox): preview only, two Reduce Motion returns of a pulled list
vjeux 39e5541
fix(motion): a cross-fade in a scroll container copies its visible part
vjeux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
apps/sandbox/src/app/(raw)/pages/refresh-control-ab/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| 'use client'; | ||
|
|
||
| /** | ||
| * @file page.tsx | ||
| * @input Nothing | ||
| * @output A bare page that compares two ways a pulled RefreshControl list | ||
| * returns under Reduce Motion, behind a switch. A cross-fades with a brief | ||
| * copy of the list. B uses one list: it fades out where it was, then fades | ||
| * in at rest. Rows below make the document scroll. | ||
| * @position A raw page, with no sandbox chrome, for a phone check. Preview | ||
| * only. | ||
| */ | ||
|
|
||
| import {useCallback, useEffect, useState} from 'react'; | ||
| import * as stylex from '@stylexjs/stylex'; | ||
| import {REFRESH_REVEAL_VAR, useRefreshControl} from '@astryxdesign/lab'; | ||
| import {Button} from '@astryxdesign/core/Button'; | ||
| import {Card} from '@astryxdesign/core/Card'; | ||
| import {HStack, 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'; | ||
|
|
||
| type Form = 'A' | 'B'; | ||
|
|
||
| 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 FORMS: Record<Form, string> = { | ||
| A: 'A: cross-fade with a brief copy', | ||
| B: 'B: one list, out then in', | ||
| }; | ||
|
|
||
| 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}), | ||
| }); | ||
|
|
||
| function useReducedMotion(): boolean { | ||
| const [isReduced, setIsReduced] = useState(false); | ||
| useEffect(() => { | ||
| const query = window.matchMedia('(prefers-reduced-motion: reduce)'); | ||
| const update = () => setIsReduced(query.matches); | ||
| update(); | ||
| query.addEventListener('change', update); | ||
| return () => query.removeEventListener('change', update); | ||
| }, []); | ||
| return isReduced; | ||
| } | ||
|
|
||
| export default function RefreshControlAbPage() { | ||
| const [form, setForm] = useState<Form>('A'); | ||
| const [count, setCount] = useState(0); | ||
| const isReduced = useReducedMotion(); | ||
| 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 under Reduce Motion</Heading> | ||
| <Text color="secondary"> | ||
| Turn on Reduce Motion in Settings. Pick A or B, then pull the messages | ||
| down past the spinner and let go. Watch the list as it waits below the | ||
| spinner, and as it goes back to the top. | ||
| </Text> | ||
| <Text>{`Reduce Motion is ${isReduced ? 'on' : 'off'}.`}</Text> | ||
| </VStack> | ||
| <HStack gap={2}> | ||
| {(['A', 'B'] as const).map(option => ( | ||
| <Button | ||
| key={option} | ||
| label={FORMS[option]} | ||
| variant={form === option ? 'primary' : 'secondary'} | ||
| aria-pressed={form === option} | ||
| onClick={() => setForm(option)} | ||
| /> | ||
| ))} | ||
| </HStack> | ||
| <Text>{`${FORMS[form]} · Refreshed ${count} times`}</Text> | ||
| <Card height="60dvh" padding={0}> | ||
| <div | ||
| {...stylex.props(styles.scroller)} | ||
| role="region" | ||
| aria-label="Messages" | ||
| tabIndex={0} | ||
| data-refresh-reduce-motion-form={form === 'B' ? 'dip' : undefined}> | ||
| <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> | ||
| ); | ||
| } |
118 changes: 118 additions & 0 deletions
118
apps/sandbox/src/app/(raw)/pages/refresh-control/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"content that a release moves" leaves out the refresh's end, which also lays a copy (
refreshTouchController.ts:644,crossFadeContent(finish, false)) and is not started by a release. Word the item for both moves, or keep the animator's form for the end.