Skip to content

Place balloons against unclipped anchor bounds - #1024

Merged
skydoves merged 1 commit into
mainfrom
fix/anchor-scrolled-off-screen
Sep 13, 2026
Merged

skydoves merged 1 commit into
mainfrom
fix/anchor-scrolled-off-screen

Conversation

@skydoves

@skydoves skydoves commented Sep 13, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1022. The anchor bounds were captured with boundsInWindow(), which clips — an anchor scrolled out of a Modifier.verticalScroll column collapses to Rect.Zero, so the balloon was placed against the window origin (the arrow jumping to the top-left corner), and the off-screen dismissal never fired because it skipped empty rects.

The anchor rect now comes from localToWindow on its four corners, and the clipped rect is used only to decide whether the anchor is still on screen — which also covers an anchor clipped away inside the window, something the old window-coordinate check could not see.

Covered by four regression tests in ReportedScenarioTest, each confirmed to fail against the current code.

Summary by CodeRabbit

  • Bug Fixes

    • Balloons now track anchors accurately when they are clipped, rotated, scaled, or partially visible.
    • Balloons dismiss when their anchors leave the visible area, including when scrolled out of a scrolling container.
    • Balloons shown before an anchor finishes appearing now wait for the anchor instead of dismissing prematurely.
  • Documentation

    • Clarified balloon dismissal behavior for clipped and not-yet-visible anchors.

Both anchor capture sites read `boundsInWindow()`, which clips: an anchor
scrolled out of a `Modifier.verticalScroll` column (clipped rather than
disposed, unlike a `LazyColumn` item) collapses to `Rect.Zero`, so the
balloon was placed against the window origin — the arrow jumping to the
top-left corner reported in #1022. The "anchor left the window" dismissal
never fired either, because it skipped empty rects.

`toBalloonAnchor()` now maps the anchor's own four corners through
`localToWindow` for the real rect, and reads the clipped rect only for the
separate verdict on whether the anchor is still on screen. That verdict
also covers an anchor clipped away inside the window, which the old
window-coordinate comparison could not see at all, so it replaces it.

Dismissal is latched on an anchor that has been seen: `AnimatedVisibility`
with `expandVertically()` clips its content to nothing on the frame it
starts, and a balloon shown in that frame must wait for its anchor rather
than dismiss itself permanently.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: adb7fd70-0aac-444c-b115-c5ae5dd484af

📥 Commits

Reviewing files that changed from the base of the PR and between 9f24fa2 and a703b35.

📒 Files selected for processing (4)
  • balloon/src/commonMain/kotlin/com/skydoves/balloon/BalloonHost.kt
  • balloon/src/commonMain/kotlin/com/skydoves/balloon/BalloonPopup.kt
  • balloon/src/skiaTest/kotlin/com/skydoves/balloon/ReportedScenarioTest.kt
  • docs/showing.md

Walkthrough

The change replaces raw anchor bounds with structured geometry and visibility state. Popup positioning uses uncropped anchor geometry. Visible balloons dismiss when anchors become clipped or leave the window. Tests and documentation cover these cases.

Changes

Balloon anchor capture and popup behavior

Layer / File(s) Summary
Structured anchor capture
balloon/src/commonMain/kotlin/com/skydoves/balloon/BalloonHost.kt, balloon/src/commonMain/kotlin/com/skydoves/balloon/BalloonPopup.kt
BalloonAnchor stores uncropped geometry and screen visibility. Modifier.balloon captures all anchor corners and BalloonHost forwards the structured value.
Popup positioning and dismissal
balloon/src/commonMain/kotlin/com/skydoves/balloon/BalloonPopup.kt
Popup positioning uses anchor.rect. A visible balloon dismisses after its anchor becomes clipped or leaves the window. An anchor that has not appeared yet does not trigger dismissal.
Regression coverage and documentation
balloon/src/skiaTest/kotlin/com/skydoves/balloon/ReportedScenarioTest.kt, docs/showing.md
Tests cover scrolling, clipping, real-edge positioning, and animated entry. Documentation describes the updated dismissal behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant AnchorModifier
  participant BalloonHost
  participant BalloonPopupLayer
  participant PositionProvider
  AnchorModifier->>BalloonHost: Capture BalloonAnchor
  BalloonHost->>BalloonPopupLayer: Pass structured anchor
  BalloonPopupLayer->>PositionProvider: Use anchor.rect
  BalloonPopupLayer->>BalloonPopupLayer: Track visibility and dismiss when needed
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/anchor-scrolled-off-screen

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

Comment @coderabbitai help to get the list of available commands.

@skydoves
skydoves merged commit 42647b7 into main Sep 13, 2026
4 of 5 checks passed
@skydoves
skydoves deleted the fix/anchor-scrolled-off-screen branch September 13, 2026 01:38
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.

Balloon arrow jumps to the top-left when the anchor composable is scrolled off-screen

1 participant