SwiftUIFrameReader

1.1.0

SwiftUI container views with a subset of GeometryReader features.
ciaranrobrien/SwiftUIFrameReader

What's New

v1.1.0

2025-01-06T23:01:31Z

GeometryValueReader updated with support for non-Equatable values

SwiftUI FrameReader

SwiftUI container views with a subset of GeometryReader features.

Motivation

GeometryReader recalculates its body every time the container view's geometry changes. This can result in unnecessary recalculations if the body only depends on a subset of the container view's geometry information. For example, a child view may depend on the parent view's size but not on its position.

This package provides container views that each offer a subset of the functionality of a GeometryReader. These container views have the same space-filling behaviour as a GeometryReader, but only recalculate their body when their returned value changes.

Get Started

Use SizeReader, SafeAreaReader or BoundsReader to read the size and/or safe area of the container view.

SizeReader { size in
    /// content
}

Use FrameReader to read the frame of the container view in a given coordinate space.

FrameReader(in: .global) { frame in
    /// content
}

Advanced Usage

Provide a key path to any reader to read a single geometry value from the container view.

SizeReader(\.width) { width in
    /// content
}

FrameReader(\.minY, in: .global) { minY in
    /// content
}

Use GeometryValueReader to calculate and read a single geometry value from the container view.

GeometryValueReader { proxy in
    proxy.bounds(of: .scrollView)?.height
} content: { scrollViewHeight in
    /// content
}

Requirements

  • iOS 13.0+, macOS 10.15+, tvOS 13.0+, watchOS 6.0+, visionOS 1.0+
  • Xcode 16.0+

Installation

Contact

@ciaranrobrien on Twitter.

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon May 12 2025 15:22:15 GMT-0900 (Hawaii-Aleutian Daylight Time)