Repository navigation
feat(native-overlay): dismiss a collapsed toast stack by swiping toward its edge - #335
huhuanming wants to merge 2 commits into
Conversation
…rd its edge A collapsed stack, including a single toast, now behaves as one banner: dragging it toward the anchored edge moves every card and dismisses them together, and dragging it away expands a stack of two or more. An expanded stack is a list: cards still swipe sideways one at a time, and pushing the stack toward the edge collapses it. The direction follows the expanded state, which the user changes, instead of the toast count, which changes on its own. - iOS and Android lock the axis when the drag starts and move every card of the stack inside its scaled slot. A group dismissal starts all exits before one layout pass, so back cards keep their depth and faded body and no card is promoted into the front slot while the group leaves. - Toasts shown during a drag wait and enter after release, so a new card never takes the dragged card's slot. A drag whose owner is closed in code ends cleanly instead of deferring later toasts forever. - Web applies the gestures to touch input with the lane's anchored edge as the dismiss direction; mouse and pen keep the horizontal swipe, since hover already expands the stack. - SPEC gains a stack gesture contract and the iOS simulator run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Devin Review found 2 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| slot.onRelease = { translationX, translationY, velocityX, velocityY, cancelled -> | ||
| val current = drag?.takeIf { it.owner === entry } | ||
| drag = null | ||
| if (current != null) { | ||
| finishDrag(current, translationX, translationY, velocityX, velocityY, cancelled) | ||
| } | ||
| flushDeferredAdds() |
There was a problem hiding this comment.
🔴 Crash when collapsing a toast stack
An upward swipe from an expanded back card reenters onRelease when the collapse disables that card’s drag. If a toast arrived during the swipe, flushDeferredAdds modifies the list that layout is iterating, crashing Android.
Learn more
ToastSlot.onTouchEvent notifies the presenter before clearing the slot’s dragging flag. For a successful collapse, finishDrag immediately calls layout. That layout walks the mutable entries list and revokes drag eligibility on every back card. The allowDrag setter still sees the released card as dragging and calls onRelease again. The nested callback runs flushDeferredAdds, and add inserts the queued toast into the list mid-iteration.
Example: Expand cards A and B, swipe up on B, and let C arrive before releasing. The release collapses A and B, then insertion of C invalidates the outer layout iterator.
Recommended fix: Snapshot the release displacement and velocity, then clear the slot’s drag state before invoking onRelease. Only the presenter’s current drag owner must finalize a drag. Post deferred additions for cancellations that originate inside layout so insertion runs after the layout pass. Cover release from an expanded back card with a queued arrival in a presenter-level test.
Was this helpful? React with 👍 or 👎 to provide feedback.
| function clearPress(pointerId: number, { node }: IToastPress) { | ||
| presses.delete(pointerId); | ||
| if (stackDrag?.pointerId === pointerId) { | ||
| abandonStackDrag(); | ||
| } | ||
| clearSwipe(node, pointerId); | ||
| } |
There was a problem hiding this comment.
🟡 Toasts queued during a sideways swipe can stay hidden
Toasts shown during a horizontal swipe go into deferredItems. Only abandonStackDrag and onGlobalPointerEnd flush that list. If clearNodePresses or onWindowBlur clears the swipe, the press is deleted first, so the later pointerup returns early and the toast stays unmounted until another drag ends.
Learn more
sync defers newly visible toasts while isDragging() is true. isDragging() is true during a stack drag and also during a horizontal swipe (node.swiping). Only abandonStackDrag (stack drags) and the end of onGlobalPointerEnd call flushDeferredItems. A horizontal swipe can also end through clearPress, called from clearNodePresses (in deleteToast, unmount, or a generation change in sync) and from onWindowBlur. That path deletes the press, so the real pointerup later hits if (!press) return and nothing flushes the queue.
Example: A user swipes card A sideways. The app calls show('B'), so B is deferred. The app then hides A in code. deleteToast clears A's press and swipe. On release, onGlobalPointerEnd returns early. B is never drawn until some later drag ends.
Recommended fix: In clearPress, check whether the swipe being cleared belonged to this pointer. If so, schedule flushDeferredItems in a microtask, the way abandonStackDrag does. A second flush from onGlobalPointerEnd does nothing because the queue is already empty.
| function clearPress(pointerId: number, { node }: IToastPress) { | |
| presses.delete(pointerId); | |
| if (stackDrag?.pointerId === pointerId) { | |
| abandonStackDrag(); | |
| } | |
| clearSwipe(node, pointerId); | |
| } | |
| function clearPress(pointerId: number, { node }: IToastPress) { | |
| presses.delete(pointerId); | |
| if (stackDrag?.pointerId === pointerId) { | |
| abandonStackDrag(); | |
| } | |
| const wasSwiping = node.swiping && node.swipePointerId === pointerId; | |
| clearSwipe(node, pointerId); | |
| if (wasSwiping) { | |
| queueMicrotask(flushDeferredItems); | |
| } | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
| node.swipeOut = true; | ||
| }); | ||
| layouts.forEach(({ node, layout }) => | ||
| deleteToast(node, 'swipe', true, layout) |
There was a problem hiding this comment.
P2: [Preserve replacement toasts created by swipe callbacks]
If the front card's onDismiss calls show() for a back card's ID, the store synchronously updates that back card's DOM node to the new generation. This loop then dismisses the replacement with swipe, so a toast created by the callback disappears immediately.
Commit the group dismissal for the captured generations before invoking the application callbacks.
| function isDragging(): boolean { | ||
| return ( | ||
| stackDrag !== undefined || | ||
| [...nodes.values()].some((node) => node.swiping) |
There was a problem hiding this comment.
P2: [Flush deferred web toasts when a horizontal drag is interrupted]
Start a horizontal drag on an infinite-duration toast, show another toast, then blur the window. The new toast is queued because node.swiping is true. Blur clears that flag through clearPress, but only the ordinary pointer-end path flushes the horizontal drag's queue. With no later store update, the queued toast never mounts.
Schedule the flush from shared horizontal swipe teardown after the current event or reconciliation finishes.
| slot.onVerticalDrag = { dy -> drag?.takeIf { it.owner === entry }?.let { applyVerticalDrag(it, dy) } } | ||
| slot.onRelease = { translationX, translationY, velocityX, velocityY, cancelled -> | ||
| val current = drag?.takeIf { it.owner === entry } | ||
| drag = null |
There was a problem hiding this comment.
P2: [Keep Android drags tied to the initiating touch]
On an expanded stack, start a vertical drag on one card, then drag and release a second card with another finger. Android can deliver the fingers to separate slots. The second slot enters local drag state even though beginDrag refuses it, and its release gets current == null but still clears drag. The first drag can no longer settle its cards, and queued toasts can enter before the first finger lifts.
The same ownership needs to hold inside a slot. If the original finger lifts while another stays down, index-zero rawX and rawY can start measuring the remaining finger against the original down point. Bind the accepted gesture to its slot and pointer ID throughout movement and release.
|
|
||
| function dismissStack(drag: IStackDrag) { | ||
| const { group, edgeSign } = drag; | ||
| const leaving = drag.participants.filter((node) => !node.removed); |
There was a problem hiding this comment.
P2: [Release a web drag participant when it changes lanes]
Start an upward swipe on a collapsed top lane, then update a back card's position to bottom-center before release. The move clears presses owned by the moved node, but the drag belongs to the front card, so the moved card stays in drag.participants. It follows the top lane's offset and is dismissed by that swipe using the old lane's geometry.
Detach a moved participant from the drag and clear its offset when reconciling the lane change.
| [data-onekey-toast][data-stack-drag="true"]{transition:none} | ||
| [data-onekey-toast][data-removed="true"][data-swipe-out="true"][data-swipe-axis="y"]{animation:onekey-toast-stack-swipe-out ${TOAST_MOTION.cardExitMs}ms ${cardExitEase} forwards} | ||
| @keyframes onekey-toast-stack-swipe-out{ | ||
| 0%{transform:translateY(var(--drag-y,0px)) var(--y) scale(var(--toast-pane-scale,1));opacity:1} |
There was a problem hiding this comment.
P2: [Preserve web stack visibility and card height during the exit]
With four active toasts, a touch stack swipe assigns this animation to the hidden fourth card. Its opening opacity:1 overrides the normal hidden opacity, so an off-stack card can flash during the exit. The visible collapsed back cards also keep reading --front-toast-height, which can drop to 0px when the active stack leaves or change when a queued toast enters.
Capture visibility and rendered height at release and use that snapshot for the exit. The hidden cards should still receive their dismissal and close events.
| drag.mode === 'collapse' && | ||
| (toward >= COLLAPSE_PUSH_DISTANCE || towardSpeed >= SWIPE_FLICK_VELOCITY) | ||
| ) { | ||
| touchExpandedGroup = undefined; |
There was a problem hiding this comment.
P2: [Allow touch collapse while a mouse hover is active]
On a device with both touch and a mouse or trackpad, park the pointer over two toasts to expand them, then use a finger to push the stack toward its anchor. The release clears the touch and keyboard flags, but isExpanded() still sees the stored mouse hover. The cards settle back expanded even after crossing the collapse threshold.
Suppress the existing hover expansion when the touch collapse succeeds and let the next mouse or pen interaction expand it again.
| [data-onekey-toast][data-swiping="true"]{transform:translateX(var(--swipe-amount,0px)) var(--y) scale(var(--toast-pane-scale,1));opacity:var(--swipe-opacity,1);transition:none} | ||
| [data-onekey-toast][data-swipe-out="true"][data-y-position="bottom"],[data-onekey-toast][data-swipe-out="true"][data-y-position="top"]{animation:onekey-toast-swipe-out ${TOAST_MOTION.cardExitMs}ms ${cardExitEase} forwards} | ||
| /* A touch stack drag moves every card of the stack with the finger; a stack dismissal leaves past the anchored edge. */ | ||
| [data-onekey-toast][data-stack-drag="true"]{transition:none} |
There was a problem hiding this comment.
P2: [Restore the programmatic exit transition for dragged participants]
If application code dismisses a back card while the front card owns a touch stack drag, the back card becomes removed while retaining data-stack-drag. This rule keeps transition:none in effect, so the card disappears immediately during what should be its normal animated exit.
Release the card's drag transition suppression when starting its programmatic exit.
| cancelTimer(entry) | ||
| if (report) onEvent?.invoke(entry.id, entry.item.generation, "dismiss", reason) | ||
| val scale = entry.slot.scaleY.takeIf { it > 0.01f } ?: 1f | ||
| entry.slot.card.translationY = offset / scale |
There was a problem hiding this comment.
P2: [Reproject Android vertical drag offsets when the pane rescales]
On a foldable, hold a vertical drag while an obstruction change resizes the toast pane. This code divides the window offset by the current slot scale, but the layout's reprojectDrag() only handles horizontal motion. If the scale halves while the finger stays still, the vertical drag displacement also halves until the next pointer move.
Store each vertical offset in window pixels and reproject it when the corresponding slot scale changes.
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Cursor review failed. Remote error: |
|
Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b2fc16835c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function isDragging(): boolean { | ||
| return ( | ||
| stackDrag !== undefined || | ||
| [...nodes.values()].some((node) => node.swiping) | ||
| ); |
There was a problem hiding this comment.
Flush deferred toasts when a horizontal drag loses focus
On Web, start a horizontal swipe, show another toast while the pointer is held, then switch windows or tabs before releasing. The new toast is deferred because node.swiping counts as dragging, but onWindowBlur() clears all presses without calling flushDeferredItems(). Unlike a vertical drag, clearing a horizontal swipe does not schedule a flush through abandonStackDrag(), and subsequent pointer-up events return because the press is gone. The deferred toast therefore remains invisible until an unrelated store update or another gesture occurs. Flush pending items whenever the final drag is abandoned, including window blur, to preserve the specified enter-after-drag lifecycle.
AGENTS.md reference: AGENTS.md:L16-L18
Useful? React with 👍 / 👎.
| [data-onekey-toast][data-stack-drag="true"]{transition:none} | ||
| [data-onekey-toast][data-removed="true"][data-swipe-out="true"][data-swipe-axis="y"]{animation:onekey-toast-stack-swipe-out ${TOAST_MOTION.cardExitMs}ms ${cardExitEase} forwards} | ||
| @keyframes onekey-toast-stack-swipe-out{ | ||
| 0%{transform:translateY(var(--drag-y,0px)) var(--y) scale(var(--toast-pane-scale,1));opacity:1} |
There was a problem hiding this comment.
Preserve hidden cards' opacity during stack dismissal
When a collapsed Web stack contains more than three toasts, dismissing it with a vertical touch swipe makes the previously hidden fourth and subsequent cards flash into view. beginStackDrag() includes every active card, and dismissStack() assigns this animation to all participants, including those with data-visible="false". The explicit opacity:1 keyframe overrides their normal opacity:0, revealing extra stacked cards during the exit instead of preserving the specified three-visible-card limit. Keep invisible participants transparent throughout the animation while still dismissing them and emitting their callbacks.
AGENTS.md reference: AGENTS.md:L16-L18
Useful? React with 👍 / 👎.
| if (current != null) { | ||
| finishDrag(current, translationX, translationY, velocityX, velocityY, cancelled) | ||
| } | ||
| flushDeferredAdds() |
There was a problem hiding this comment.
Avoid flushing deferred additions from a nested release
On Android, collapse an expanded stack by dragging its second or third card upward while a new toast arrives mid-drag. ToastSlot.onTouchEvent() invokes this release handler before clearing slot.dragging, so finishDrag() enters the collapse layout with the slot still dragging. That layout disables the back card's allowDrag, whose setter synchronously invokes onRelease again. The nested invocation reaches flushDeferredAdds() and inserts the pending toast into entries while the outer layout() is iterating that same mutable list, causing a ConcurrentModificationException on the UI thread. Clear the slot's drag state before invoking release, or defer additions until the layout iteration has completed.
AGENTS.md reference: AGENTS.md:L16-L18
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| slot.onRelease = { translationX, translationY, velocityX, velocityY, cancelled -> | ||
| val current = drag?.takeIf { it.owner === entry } | ||
| drag = null | ||
| if (current != null) { | ||
| finishDrag(current, translationX, translationY, velocityX, velocityY, cancelled) | ||
| } | ||
| flushDeferredAdds() |
There was a problem hiding this comment.
🟠 P1: Android crash when collapsing toast stack
Severity: severe
When an upward swipe collapses the stack from a back card, onRelease runs again inside layout. The second callback mounts any queued toast while layout is iterating entries, crashing the app.
| if (stackDrag?.pointerId === pointerId) { | ||
| abandonStackDrag(); | ||
| } |
There was a problem hiding this comment.
🟡 P2: Queued web toasts stranded after blur
Severity: non-severe
When the window loses focus during a horizontal swipe, clearPress cancels the swipe without releasing queued toasts. With a persistent toast on screen, queued toasts stay hidden until another store update or gesture drains the queue.
Summary
Follow-up to #307. A single toast swiped sideways felt wrong: on iOS a banner is pushed up and away, and only list items are swiped sideways. This PR keeps sideways swipes for list items and makes a collapsed stack behave like a banner.
64, or20at500/s, dismisses them together40or500/sexpands 2+ cards; a single toast settles back50or500/scollapsesThe direction follows the expanded state, which the user changes, not the toast count, which changes on its own. So clearing a stack never switches direction halfway, and the collapsed group leaves together, so no card is promoted into the front slot during the exit.
dismiss('swipe')thenclose('swipe'), newest first, and only cards present when the drag began are dismissed.No count badge in this round; that is deferred until the gesture is tried on devices.
Verification
tscand eslint passed. Jest 13 suites / 175 tests passed, including new cases for collapsed touch dismissal with a toast shown mid-drag, pull-to-expand, push-to-collapse, a single-toast flick, mouse keeping horizontal only, and a bottom lane dismissing downward. Chromium browser suite 26/26 passed (no new browser cases).:onekeyfe_react-native-native-overlay:testDebugUnitTest48/48 passed, including a new axis-lock test for vertical drags.simctl/adb shell input swipe) and toasts shown through$Toast. The installed binaries were checked for the new drag code first. Same results on both:Not verified yet
touch_pathdrags were not recognized as pans while itsswipeaction was; a hand drag on a device should confirm.🤖 Generated with Claude Code