Skip to content

Comments

Improve intrinsic height sheet#456

Merged
MarcHidalgo5 merged 8 commits intodevelopfrom
improve-intrinsicHeightSheet
Feb 23, 2026
Merged

Improve intrinsic height sheet#456
MarcHidalgo5 merged 8 commits intodevelopfrom
improve-intrinsicHeightSheet

Conversation

@MarcHidalgo5
Copy link
Contributor

@MarcHidalgo5 MarcHidalgo5 commented Feb 23, 2026

Summary

This PR improves intrinsicHeightSheet behavior on Android while keeping iOS behavior unchanged.

What changed

  • Kept the existing iOS intrinsic-height implementation as-is:
    • getCGSize
    • .presentationDetents([.height(sheetSize.height)])
    • .fixedSize(horizontal: false, vertical: true)
  • Added Android-specific handling for intrinsic detents:
    • Uses .intrinsicSheetDetents(sheetSize) with an Android bottom compensation (+20).
    • Locks sheet size to the first valid measured height on Android to reduce unnecessary recompositions/height updates.

Why

On Android (Skip/Compose), the same detent behavior as iOS is not stable enough by default. This adjustment makes the height behavior more predictable while preserving iOS parity.

Visual comparison

iOS

Simulator.Screen.Recording.-.iPhone.17.-.2026-02-23.at.17.01.28.mov

Android

Screen_recording_20260223_170005.webm

MarcHidalgo5 and others added 7 commits February 23, 2026 12:23
Refactor the view modifiers for intrinsic height sheets to unify and
simplify logic by introducing `intrinsicSheetDetents`. This new
helper function abstracts the platform-specific sheet detent logic,
handling size checking and applying appropriate presentation detents
more efficiently. The change cleans up repeated code, removing
conditional compilation blocks and reducing potential for
maintenance errors.
Add conditional compilation to `intrinsicSheetDetents` method, wrapping
`fixedSize` modifier with `#if canImport(Darwin)`. This ensures
correct behavior on non-Darwin platforms, which might not support
`.fixedSize` for `.presentationDetents`. This change is crucial for
maintaining cross-platform compatibility and avoiding unexpected
layout behavior.
Reset the sheet size to zero on presentation to guarantee an update
to the correct size when the sheet is shown again. This fix is crucial
for preventing incorrect size carry-over in repeated presentations.

Improve size update logic by introducing a function to check for
significant size changes before updating. This prevents unnecessary
updates and reduces potential re-rendering loops, especially on Darwin
platforms.

Compensate for the bottom space on Android to ensure the sheet opens
with the intended appearance.
Remove platform-specific (Darwin/Android) conditional checks to streamline
and simplify the intrinsicHeightSheet implementation. The decision
ensures consistent behavior across all platforms and removes unnecessary
complexity, providing a cleaner and more maintainable codebase.
Removes redundant onChange checks for sheet presentation state, relying
instead on the default behavior of SwiftUI's sheet presentation.
Refactors sheet presentation logic to accommodate both Darwin and
non-Darwin platforms using a conditional compilation approach.
This simplifies code and improves maintainability while ensuring
consistent behavior across platforms.
Simplify the logic for intrinsicSheetDetents by removing the
conditional height check. Adjust the androidBottomCompensation
from 24.0 to 20.0 for better UI consistency across platforms.
Simplify the SwiftUI intrinsic height sheet implementation by removing code
specific to non-Darwin platforms, ensuring that only Darwin-specific logic
is applied. The `intrinsicSheetDetents` and related compensation logic were
removed as they were redundant, simplifying the logic focused on `canImport(Darwin)`.
@MarcHidalgo5 MarcHidalgo5 merged commit 7c5d83d into develop Feb 23, 2026
3 checks passed
@MarcHidalgo5 MarcHidalgo5 deleted the improve-intrinsicHeightSheet branch February 23, 2026 16:23
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