Skip to content

[Masterclass] Clear the home indicator with a content margin, not a spacer row - #237

Open
shrutibalasawebdev wants to merge 1 commit into
NativePHP:mainfrom
shrutibalasawebdev:fix/scroll-anchor-bottom-margin
Open

shrutibalasawebdev wants to merge 1 commit into
NativePHP:mainfrom
shrutibalasawebdev:fix/scroll-anchor-bottom-margin

Conversation

@shrutibalasawebdev

Copy link
Copy Markdown

Fixes #234

Problem

Since #141, a bottom-anchored scroll view ends its content with a spacer row the height of the home indicator, collapsing it to 0 while the keyboard is up. That row lives inside the LazyVStack, just before the bottom anchor.

In a lazy stack, a row is placed from the estimated heights of the rows above it. So the spacer and the anchor after it sit where SwiftUI guesses, and pins to the anchor land there. Resizing the spacer with the keyboard also changes the content while the keyboard re-pin is scrolling. The result, on iOS:

  • A single wrapping column (<scroll-view scroll-anchor="bottom"> with one h-full justify-end column holding the messages) opens blank until you drag, and blanks out when the keyboard shows or hides. (#ISSUE_NUMBER)
  • Messages as direct children: new messages no longer keep the view at the bottom.

Fix

Apply the same clearance as a bottom content margin instead of a spacer row:

.contentMargins(
    .bottom,
    stickBottom && !keyboardShown ? Self.homeIndicatorClearance : 0,
    for: .scrollContent
)

Nothing inside the lazy stack is estimated or resized for it anymore, and the margin collapses with the keyboard exactly as the spacer did. Everything else in #141 is unchanged.

Testing

On an iOS simulator, with a demo app and with a real chat app, both on this branch:

  • Wrapper column: opens at the bottom with messages drawn every time; toggling the keyboard at the bottom and while scrolled up never blanks anything; short conversations still rest at the bottom.
  • Direct children, with a new message arriving every 2s: the view follows new messages at the bottom; scrolling up into history while they arrive leaves you in place; scrolling back to the bottom resumes following.

Android isn't affected: this file is iOS only.

A bottom-anchored scroll view ended its content with a spacer row the
height of the home indicator, collapsing it while the keyboard is up.
Inside the LazyVStack, that row is placed from the estimated heights of
the rows above it, and resizing it with the keyboard changes the content
while the keyboard re-pin is scrolling. Pins to the bottom anchor then
landed short of the real end:

- A single wrapping column (one very tall lazy row) opened blank until
  dragged, and blanked out when the keyboard showed or hid.
- With messages as direct children, new messages no longer kept the
  view at the bottom.

Apply the same clearance as a bottom content margin instead. Nothing
inside the lazy stack changes, and the margin collapses with the
keyboard as the spacer did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016kqQGZ2V3NpkyywRHYfDYh
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.

[Masterclass] scroll-anchor="bottom" with a single wrapping column opens blank on iOS (regressed in 0.9.0)

1 participant