Skip to content

Feature: FloatingPanelAdaptiveLayoutAnchor initializer with absolute inset + edge (fixed position, adaptive size) #682

@fawzirifai

Description

@fawzirifai

Summary

Add a new initializer to FloatingPanelAdaptiveLayoutAnchor that pins the panel position using absolute inset + edge (same semantics as FloatingPanelLayoutAnchor(absoluteInset:edge:referenceGuide:)), while keeping adaptive sizing: the panel should still shrink to content when content is small and expand (capped by safe area / contentBoundingGuide) when content is large.

Motivation

  • FloatingPanelLayoutAnchor(absoluteInset:edge:referenceGuide:) gives fixed positioning (e.g. “panel top at 8pt from safe area top”) but the panel size is fixed (e.g. full height), not content-driven.
  • FloatingPanelAdaptiveLayoutAnchor(absoluteOffset:contentLayout:referenceGuide:contentBoundingGuide:) gives adaptive sizing (shrink to content, cap by safe area) but the position is derived from the content dimension (offset from reference), not from a fixed inset + edge.

There is no way to get both:

  1. Position: Pin the panel from a specific edge with a fixed inset (e.g. “top of panel at safe area top + 8pt”).
  2. Size: Adaptive to content (shrink when content is small, grow up to safe area when content is large).

That combination is useful for panels that should always start at a consistent place (e.g. below a toast) but still size to their content.

Proposed API

Add an initializer on FloatingPanelAdaptiveLayoutAnchor:

/// Position is pinned from the given edge at a fixed inset (like FloatingPanelLayoutAnchor).
/// Size remains adaptive: panel shrinks to content and is capped by contentBoundingGuide.
init(
    absoluteInset: CGFloat,
    edge: FloatingPanelReferenceEdge,
    contentLayout: UILayoutGuide,
    referenceGuide: FloatingPanelLayoutReferenceGuide,
    contentBoundingGuide: FloatingPanelLayoutContentBoundingGuide = .none
)

Behavior:

  • Position: Same as FloatingPanelLayoutAnchor(absoluteInset:absoluteInset, edge: edge, referenceGuide: referenceGuide) — the panel’s leading edge (in the panel’s main axis) is placed at absoluteInset from the given edge of the reference guide (e.g. for a bottom panel with edge: .top, the panel’s top is at referenceGuide.topAnchor + absoluteInset).
  • Size: Unchanged from current adaptive behavior — panel height/width follows contentLayout and is capped by contentBoundingGuide (e.g. .safeArea).

Example use case

A panel that should sit below a toast (fixed top inset) but still size to its content:

// Panel position: top pinned at safeArea.top + topAnchorInset
// Panel size: height = content, capped by safe area
.full: FloatingPanelAdaptiveLayoutAnchor(
    absoluteInset: Self.topAnchorInset,  // e.g. 8pt or below toast
    edge: .top,
    contentLayout: targetGuide,
    referenceGuide: .safeArea,
    contentBoundingGuide: .safeArea
)

Thank you for considering this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions