Repository navigation
fix(core): a touch press's release lasts until its fade has played #9758
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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] Under a finger, a press's release now lasts until its fade has played. The touch press controller ended the release on a clock started at the lift, so when the page's script delayed the fade's first frame, the release was cut short mid-fade. It now ends when the press's release animation ends, on the surface or on a part inside it that a component draws the release on, or on its clock where no release animation runs (an instant release, a surface without one, or an engine without Web Animations). This applies to every surface the touch press controller drives: buttons, switches, checkboxes, cards, menu rows and list rows. | ||
|
|
||
| @vjeux |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,7 +109,8 @@ interface LiveGesture { | |
| * for a press of the Space key. | ||
| */ | ||
| pointerId: number | null; | ||
| timer: ReturnType<typeof setTimeout> | null; | ||
| /** Cancels the clock the current phase owes, or the release it waits for. */ | ||
| timer: (() => void) | null; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -165,6 +166,76 @@ export function pressFadeMs(element: Element): number { | |
| return reduced ? Math.min(scaled, PRESS_FADE_MS) : scaled; | ||
| } | ||
|
|
||
| /** | ||
| * The release animations that still run for `element`'s press. Each is a | ||
| * finite CSS animation that has not finished. It runs on the element, on its | ||
| * `::before` or `::after`, or on a descendant whose nearest press owner is | ||
| * the element, because a component can draw its release on a part inside the | ||
| * surface. A press owner nested inside plays the release of its own press, | ||
|
Comment on lines
+171
to
+174
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. Non-blocking (comment style): this sentence now runs 34 words and carries two topics, where the animation runs and why. A split keeps both facts: * finite CSS animation that has not finished. It runs on the element, on its
* `::before` or `::after`, or on a descendant whose nearest press owner is
* the element. A component can draw its release on a part inside the
* surface. A press owner nested inside plays the release of its own press, |
||
| * so it never extends this one. The list is empty where the engine has no Web | ||
| * Animations. | ||
| */ | ||
| function releaseAnimationsOf(element: Element): Animation[] { | ||
| if (typeof element.getAnimations !== 'function') { | ||
| return []; | ||
| } | ||
| return element.getAnimations({subtree: true}).filter(animation => { | ||
| // The effect of a CSS animation is a KeyframeEffect. Its target is the | ||
| // element, also when the animation runs on a pseudo-element. | ||
| const effect = animation.effect as KeyframeEffect | null; | ||
| const target = effect?.target ?? null; | ||
| if ( | ||
| effect == null || | ||
| target == null || | ||
| !('animationName' in animation) || | ||
| (target !== element && | ||
| target.closest(`[${PRESSABLE_ATTRIBUTE}]`) !== element) | ||
| ) { | ||
| return false; | ||
| } | ||
| if (!Number.isFinite(Number(effect.getComputedTiming().endTime))) { | ||
| return false; | ||
| } | ||
| return animation.playState !== 'finished'; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Calls `end` when the release on `element` is over. A busy main thread | ||
| * delays the first frame of the release animation, and with it the end. So a | ||
| * clock that starts at the `fading` write can cut the release short. When | ||
| * `clockMs` runs out, the release waits for each release animation that still | ||
| * runs or still waits for its first frame. It ends when those finish or are | ||
| * cancelled, as when the surface is unmounted or restyled. With no release | ||
| * animation (an instant release, a surface without one, an engine without Web | ||
| * Animations), the release ends at the clock. Returns a cancel. | ||
| */ | ||
| function endAfterRelease( | ||
| element: Element, | ||
| clockMs: number, | ||
| end: () => void, | ||
| ): () => void { | ||
| let waiting = true; | ||
| const timer = setTimeout(() => { | ||
| const running = releaseAnimationsOf(element); | ||
| if (running.length === 0) { | ||
| end(); | ||
| return; | ||
| } | ||
| void Promise.allSettled( | ||
| running.map(async animation => animation.finished), | ||
| ).then(() => { | ||
| if (waiting) { | ||
| end(); | ||
| } | ||
| }); | ||
| }, clockMs); | ||
| return () => { | ||
| waiting = false; | ||
| clearTimeout(timer); | ||
| }; | ||
| } | ||
|
|
||
| const TIMER_EVENT = { | ||
| fade: 'fadeEnd', | ||
| flash: 'flashEnd', | ||
|
|
@@ -181,7 +252,7 @@ function paintElement(element: HTMLElement, paint: PressPaint): void { | |
|
|
||
| function clearTimer(slot: Slot): void { | ||
| if (slot.live?.timer != null) { | ||
| clearTimeout(slot.live.timer); | ||
| slot.live.timer(); | ||
| slot.live.timer = null; | ||
| } | ||
| } | ||
|
|
@@ -217,25 +288,32 @@ function apply(slot: Slot, step: PressStep): void { | |
| } | ||
| if (step.timer != null) { | ||
| const kind = step.timer; | ||
| // A TIMER, never `requestAnimationFrame`: iOS throttles frame callbacks | ||
| // while a scroll runs, so a frame-based delay would fire late, after the | ||
| // scroll, and paint a control nobody is pressing any more. | ||
| live.timer = setTimeout( | ||
| () => { | ||
| if (slot.live != null) { | ||
| slot.live.timer = null; | ||
| } | ||
| apply( | ||
| slot, | ||
| pressGestureStep(slot.live?.gesture ?? idlePressGesture(), { | ||
| kind: TIMER_EVENT[kind], | ||
| }), | ||
| ); | ||
| }, | ||
| // The release fade follows the theme's tempo (AST-108). The onset delay | ||
| // and the tap flash do not. | ||
| kind === 'fade' ? pressFadeMs(live.element) : TIMER_MS[kind], | ||
| ); | ||
| const fire = () => { | ||
| if (slot.live != null) { | ||
| slot.live.timer = null; | ||
| } | ||
| apply( | ||
| slot, | ||
| pressGestureStep(slot.live?.gesture ?? idlePressGesture(), { | ||
| kind: TIMER_EVENT[kind], | ||
| }), | ||
| ); | ||
| }; | ||
| if (kind === 'fade') { | ||
| // The release fade follows the theme's tempo (AST-108). It ends when | ||
| // its animation ends, however late a busy main thread let it start. | ||
| live.timer = endAfterRelease( | ||
| live.element, | ||
| pressFadeMs(live.element), | ||
| fire, | ||
| ); | ||
| } else { | ||
| // A TIMER, never `requestAnimationFrame`: iOS throttles frame callbacks | ||
| // while a scroll runs, so a frame-based delay would fire late, after the | ||
| // scroll, and paint a control nobody is pressing any more. | ||
| const timer = setTimeout(fire, TIMER_MS[kind]); | ||
| live.timer = () => clearTimeout(timer); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Non-blocking (test fidelity):
'pending'is not a Web AnimationsplayState(it isidle,running,pausedorfinished). An animation still waiting for its first frame reportsplayState: 'running'withpending: true, so this case currently repeats the running case. Modelling it that way would show the case as an engine reports it.