Skip to content

Prevent negative item widths when available space is exhausted - #168

Merged
bryankeller merged 1 commit into
airbnb:masterfrom
jordanmcadoo:jordanm--clamp-item-width
Sep 24, 2026
Merged

bryankeller merged 1 commit into
airbnb:masterfrom
jordanmcadoo:jordanm--clamp-item-width

Conversation

@jordanmcadoo

@jordanmcadoo jordanmcadoo commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Change summary

Clamp calculated item widths to zero when the available space is smaller than the configured insets and inter-item spacing.

Context

Layout can run before a collection view has a usable width, or while its bounds are temporarily smaller than its insets and spacing. The current calculation can produce negative item widths, resulting in invalid cell geometry.

Clamping the result prevents invalid widths while preserving normal layout once sufficient space is available.

Before / after

skeleton-comparison

How was it tested?

  • Added regression tests for zero and narrow bounds, section and item insets, inter-item spacing, and width recovery after resizing.
  • Covered full-width items that ignore item insets and normal multi-column layout.
  • Confirmed the regression cases fail without the fix.
  • Ran locally with Xcode 26: xcodebuild test -project MagazineLayout.xcodeproj -scheme MagazineLayout -destination "platform=iOS Simulator,name=iPhone 17,OS=26.5" CODE_SIGNING_ALLOWED=NO — 65 tests passed.
  • Ran on CI.

@jordanmcadoo
jordanmcadoo marked this pull request as ready for review September 24, 2026 17:44
@jordanmcadoo
jordanmcadoo force-pushed the jordanm--clamp-item-width branch from ebab4cb to d4e524d Compare September 24, 2026 17:47

@bryankeller bryankeller left a comment

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.

Thanks! Agreed that negative sizes should not be possible.

@bryankeller
bryankeller merged commit a45a664 into airbnb:master Sep 24, 2026
1 check passed
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.

2 participants