Repository navigation
fix(core): a BottomSheet touch drag's close keeps its speed, and its scrim fades with it #8105
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
Changes from 5 commits
f864829
c3d9af2
307fdb5
86761b0
8bcccb5
62f82d1
5518789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] BottomSheet: a touch release takes the iOS sheet's measured values, and a release moving back toward where the drag began cancels. A release faster than about 1,000 px/s is a flick: it goes at least to the next detent in its direction, so a short fast flick at the lowest detent closes the sheet instead of springing back. From a higher detent, a flick that would carry past the next detent goes on, so a hard flick closes the sheet and a softer one stops at the next detent. A slow or medium touch throw now travels less than before, and a slow touch drag closes the sheet only past halfway to closed. A sheet a touch drag closes leaves on its close spring, starting at the speed of the drag, and its scrim fades out with it at the theme's tempo. A mouse or pen drag is unchanged. | ||
|
|
||
| @vjeux |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [chore] Internal: the motion foundation's `resolveSettleMs` gives a spring role's settling time at the theme's tempo, so a CSS part that plays with the spring can start and land with it. Not exported from the package entry point. | ||
|
|
||
| @vjeux |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,6 +305,36 @@ function scrimOpacityForView(view: BottomSheetStackView): '0' | '1' { | |
| return view.isStacked && !view.ownsScrim ? '0' : '1'; | ||
| } | ||
|
|
||
| /** | ||
| * Writes the fade a touch drag's close paces on `dialog`'s scrim, or clears | ||
| * it when `ms` is null. `written` keeps the value the host wrote, so a clear | ||
| * removes only that value. | ||
| */ | ||
| function writeScrimFadeDuration( | ||
| dialog: HTMLDialogElement | null, | ||
| ms: number | null, | ||
| written: {current: string | null}, | ||
| ): void { | ||
| if (dialog == null) { | ||
| return; | ||
| } | ||
| const current = dialog.style.getPropertyValue('--_sheet-scrim-duration'); | ||
| if (ms == null) { | ||
| // Only its own value: a stack's 0s pin in the meantime stays. | ||
| if (written.current != null && current === written.current) { | ||
| dialog.style.removeProperty('--_sheet-scrim-duration'); | ||
| } | ||
| written.current = null; | ||
| return; | ||
| } | ||
| // A stack's 0s pin hands the scrim over with no fade; it stays. | ||
| if (current === '0s') { | ||
| return; | ||
| } | ||
| written.current = `${ms}ms`; | ||
| dialog.style.setProperty('--_sheet-scrim-duration', written.current); | ||
| } | ||
|
|
||
| interface BottomSheetSharedProps extends BaseProps<HTMLDivElement> { | ||
| /** Ref forwarded to the visual sheet panel <div>. */ | ||
| ref?: React.Ref<HTMLDivElement>; | ||
|
|
@@ -544,6 +574,18 @@ function StandaloneBottomSheet({ | |
| String(opacity), | ||
| ); | ||
| }, []); | ||
| // The fade duration a touch drag's close wrote, until that close ends. | ||
| const scrimFadeRef = useRef<string | null>(null); | ||
| const handleScrimFadeDuration = useCallback( | ||
| (panel: HTMLElement, ms: number | null) => { | ||
| const view = stackViewRef.current; | ||
| if (view.isStacked && !view.ownsScrim) { | ||
| return; | ||
| } | ||
| writeScrimFadeDuration(panel.closest('dialog'), ms, scrimFadeRef); | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| // A sheet joins the registry for as long as it is presented. For a modal | ||
| // sheet the registry shows the dialog (in open order, repairing same-commit | ||
|
|
@@ -946,6 +988,7 @@ function StandaloneBottomSheet({ | |
| xstyle={xstyle} | ||
| onDismiss={dismissOnLightInteraction} | ||
| onScrimOpacity={handleScrimOpacity} | ||
| onScrimFadeDuration={handleScrimFadeDuration} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only the standalone host passes this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 7ab8a89. The switcher step passes the same fade handler, and both hosts share one writer. A drag-closed switcher flow's scrim now fades with its 710 ms close instead of 300 ms (a new drag-exit unit case and a Chromium case cover it). |
||
| onElementChange={handlePanelElementChange} | ||
| onMotionStart={handleMotionStart} | ||
| onMotionComplete={handleMotionComplete}> | ||
|
|
@@ -1095,6 +1138,16 @@ function SwitcherBottomSheetItem({ | |
| }, | ||
| [hasValidSheetId, onSheetScrimOpacityChange, sheetId], | ||
| ); | ||
| // The fade a touch drag's close wrote on this step's dialog, until that | ||
| // close ends. The step a drag closes becomes the flow's retained step, so | ||
| // its backdrop is the flow's scrim. | ||
| const scrimFadeRef = useRef<string | null>(null); | ||
| const handleScrimFadeDuration = useCallback( | ||
| (panel: HTMLElement, ms: number | null) => { | ||
| writeScrimFadeDuration(panel.closest('dialog'), ms, scrimFadeRef); | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| useLayoutEffect(() => { | ||
| if (!hasValidSheetId) { | ||
|
|
@@ -1297,6 +1350,7 @@ function SwitcherBottomSheetItem({ | |
| xstyle={xstyle} | ||
| onDismiss={dismissOnSwipe} | ||
| onScrimOpacity={handleScrimOpacity} | ||
| onScrimFadeDuration={handleScrimFadeDuration} | ||
| onElementChange={handlePanelElementChange} | ||
| onMotionStart={handleMotionStart} | ||
| onMotionComplete={handleMotionComplete}> | ||
|
|
||
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.
Non-blocking (INV29 style): this is a fragment. Suggest:
// Remove only the value this host wrote. A stack's 0s pin written since then stays.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.
Taken at 5518789, as suggested.