Skip to content

feat(native-overlay): dismiss a collapsed toast stack by swiping toward its edge - #335

Closed
huhuanming wants to merge 2 commits into
mainfrom
feat/toast-stack-swipe-up
Closed

huhuanming wants to merge 2 commits into
mainfrom
feat/toast-stack-swipe-up

Conversation

@huhuanming

@huhuanming huhuanming commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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.

Stack state Toward the anchored edge (up for top) Away from the edge Sideways
Collapsed, including a single toast Every card follows; release at 64, or 20 at 500/s, dismisses them together Rubber band with back cards fanning out; release at 40 or 500/s expands 2+ cards; a single toast settles back Front card only (unchanged)
Expanded Stack follows at half distance; release at 50 or 500/s collapses Rubber band, settles back The dragged card (unchanged)

The 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.

  • iOS / Android: the axis locks when the drag starts. A group dismissal starts every exit before one layout pass, so back cards keep their depth scale and faded body. Each card reports dismiss('swipe') then close('swipe'), newest first, and only cards present when the drag began are dismissed.
  • New toasts mid-drag wait and enter after release instead of taking the dragged card's slot. Updates and dismissals of cards on screen still apply at once. If the dragged card is closed in code, the drag ends instead of deferring later toasts forever.
  • Web: touch input only, with the lane's anchored edge (top or bottom) as the dismiss direction. Mouse and pen keep the horizontal swipe, since hover already expands the stack.
  • SPEC §5.14 gains a "Stack gestures" contract and the runtime evidence below.

No count badge in this round; that is deferred until the gesture is tried on devices.

Verification

  • Web: tsc and 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).
  • Android: Kotlin compiled; :onekeyfe_react-native-native-overlay:testDebugUnitTest 48/48 passed, including a new axis-lock test for vertical drags.
  • iOS and Android: built into app-monorepo and run on an iPhone 17 Pro simulator (iOS 26.0) and a Pixel 7 emulator (API 35) with injected swipes (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:
Case Result
Single toast, swipe up Dismissed
Collapsed stack of 3, pull down Expanded
Expanded, middle card sideways Only that card closed
Expanded, push up Collapsed, nothing closed
Slow 30 pt push Settled back
Collapsed stack, swipe up All cards closed together
Toast shown 0.8 s into that swipe Entered after release and stayed

Not verified yet

  • Physical iPhone and Android devices.
  • A real touch browser (covered by jsdom tests only).
  • VoiceOver / TalkBack, reduced motion, iPad, and the top obstruction shift with the new gestures.
  • The simulator's step-wise touch_path drags were not recognized as pans while its swipe action was; a hand drag on a device should confirm.

🤖 Generated with Claude Code


Devin Review

…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>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +641 to +647
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 482 to 488
function clearPress(pointerId: number, { node }: IToastPress) {
presses.delete(pointerId);
if (stackDrag?.pointerId === pointerId) {
abandonStackDrag();
}
clearSwipe(node, pointerId);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Suggested change
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);
}
}

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

node.swipeOut = true;
});
layouts.forEach(({ node, layout }) =>
deleteToast(node, 'swipe', true, layout)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sidmorizon

Copy link
Copy Markdown
Contributor

@codex review

@sidmorizon

Copy link
Copy Markdown
Contributor

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T09:04:26.662583Z b2fc168 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sidmorizon

Copy link
Copy Markdown
Contributor

Cursor review failed.

Remote error: cursor_permission_denied: HTTP 403 Forbidden: Cloud Agent is not available for free users. Please upgrade to Pro.

@cursor

cursor Bot commented Nov 26, 2026

Copy link
Copy Markdown

Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings.

@sidmorizon

Copy link
Copy Markdown
Contributor

Devin Cloud review ↗

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +553 to +557
function isDragging(): boolean {
return (
stackDrag !== undefined ||
[...nodes.values()].some((node) => node.swiping)
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +644 to +647
if (current != null) {
finishDrag(current, translationX, translationY, velocityX, velocityY, cancelled)
}
flushDeferredAdds()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@sidmorizon

Copy link
Copy Markdown
Contributor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines +641 to +647
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()

@sidmorizon sidmorizon Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

Comment on lines +484 to +486
if (stackDrag?.pointerId === pointerId) {
abandonStackDrag();
}

@sidmorizon sidmorizon Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@huhuanming huhuanming closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants