Repository navigation
fix(BottomSheet): a move of a touch drag no longer restyles the sheet's content #11154
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] BottomSheet: a move of a touch drag no longer restyles the sheet's content. Each move writes the scrim's opacity on the dialog as a custom property, and the property inherited into the sheet, so the browser restyled every element in the sheet on every move: 51 elements a move in a Tall sheet with a short list, 84 in PowerSearch's Filters sheet with three filters, and more with more content. The sheet's panel now ends that inheritance, and a move restyles the dialog, its backdrop, the panel and the edge tint. The scrim follows the drag as before. This applies to the sheet that owns the scrim: a single BottomSheet, or the first sheet of a stack, such as PowerSearch's Filters sheet and Tokenizer's sheet. | ||
|
|
||
| @imdreamrunner |
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
111 changes: 111 additions & 0 deletions
111
packages/core/src/BottomSheet/__tests__/BottomSheetDragRestyle.interaction.browser.spec.ts
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,111 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file BottomSheetDragRestyle.interaction.browser.spec.ts | ||
| * @input The built "Tall sheet" BottomSheet story, real touch input (Chromium | ||
| * CDP) and the interaction harness's rendering trace | ||
| * @output A proof of the style work a touch drag does. A move restyles the | ||
| * dialog and the panel, never the sheet's content. | ||
| * @position An interaction proof beside | ||
| * BottomSheetDetent.interaction.browser.spec.ts, on the same harness. | ||
| */ | ||
|
|
||
| import { | ||
| expect, | ||
| test, | ||
| type Locator, | ||
| type Page, | ||
| } from '@astryxdesign/a11y-spec/playwright'; | ||
| import { | ||
| drag, | ||
| openStory, | ||
| touchDriver, | ||
| traceRendering, | ||
| waitForRest, | ||
| withStorybook, | ||
| type TouchDriver, | ||
| } from '@astryxdesign/interaction-harness'; | ||
|
|
||
| const storybook = withStorybook(test); | ||
|
|
||
| // The most elements one style recalculation may restyle between two moves. | ||
| // A move restyles the dialog, its backdrop, the panel and the edge tint. The | ||
| // limit leaves room for an engine's own boxes. A restyle of the sheet's | ||
| // content counts every element in it. | ||
| const RESTYLED_PER_MOVE = 6; | ||
|
|
||
| interface OpenSheet { | ||
| driver: TouchDriver; | ||
| sheet: Locator; | ||
| handle: {x: number; y: number}; | ||
| } | ||
|
|
||
| async function openSheet(page: Page): Promise<OpenSheet> { | ||
| await openStory(page, storybook(), 'core-bottomsheet--tall-sheet'); | ||
| const driver = await touchDriver(page); | ||
| const trigger = page.getByRole('button', {name: 'Open nearby places'}); | ||
| const box = await trigger.boundingBox(); | ||
| if (box == null) { | ||
| throw new Error('no trigger'); | ||
| } | ||
| await driver.tap({x: box.x + box.width / 2, y: box.y + box.height / 2}); | ||
| const sheet = page | ||
| .getByRole('dialog', {name: 'Nearby places'}) | ||
| .locator('.astryx-bottom-sheet') | ||
| .first(); | ||
| await expect(sheet).toBeVisible(); | ||
| await waitForRest(sheet); | ||
| const rect = await sheet.boundingBox(); | ||
| if (rect == null) { | ||
| throw new Error('no sheet'); | ||
| } | ||
| return { | ||
| driver, | ||
| sheet, | ||
| handle: {x: rect.x + rect.width / 2, y: rect.y + 12}, | ||
| }; | ||
| } | ||
|
|
||
| test("a move of a drag restyles the dialog and the panel, not the sheet's content", async ({ | ||
| page, | ||
| browserName, | ||
| }) => { | ||
| test.skip(browserName !== 'chromium', 'rendering traces are Chromium-only'); | ||
| const {driver, sheet, handle} = await openSheet(page); | ||
| // The proof needs content that a restyle of the whole sheet would count. | ||
| const contentElements = await sheet.evaluate( | ||
| element => element.querySelectorAll('*').length, | ||
| ); | ||
| expect(contentElements).toBeGreaterThan(4 * RESTYLED_PER_MOVE); | ||
| let steady = {from: 0, to: 0}; | ||
| const trace = await traceRendering(page, async () => { | ||
| const played = await driver.play( | ||
| drag( | ||
| handle, | ||
| {x: handle.x, y: handle.y + 240}, | ||
| {durationMs: 600, hz: 60, restMs: 150}, | ||
| ), | ||
| ); | ||
| const moves = played.filter(event => event.type === 'touchMove'); | ||
| // The steady part of the drag: its first moves commit the drag's start, | ||
| // and the lift commits its release. | ||
| steady = { | ||
| from: moves[4].returnedAt, | ||
| to: moves[moves.length - 1].dispatchedAt, | ||
| }; | ||
| await waitForRest(sheet); | ||
| }); | ||
| const restyled = trace.events | ||
| .filter( | ||
| event => | ||
| event.name === 'UpdateLayoutTree' && | ||
| event.t >= steady.from && | ||
| event.t <= steady.to, | ||
| ) | ||
| .map(event => event.elements ?? 0); | ||
| // The drag wrote the scrim: a move's recalculation restyles the dialog too. | ||
| expect(Math.max(...restyled), JSON.stringify(restyled)).toBeGreaterThan(1); | ||
| expect(Math.max(...restyled), JSON.stringify(restyled)).toBeLessThanOrEqual( | ||
| RESTYLED_PER_MOVE, | ||
| ); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.