ciaranrobrien/SwiftUIFrameReader
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
}Use ScenePaddingReader to read the scene padding of the container view.
ScenePaddingReader { scenePadding 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 26.0+
Installation
- Install with Swift Package Manager.
- Import
SwiftUIFrameReaderto start using.
Package Metadata
Repository: ciaranrobrien/SwiftUIFrameReader
Stars: 3
Forks: 0
Open issues: 0
Default branch: main
Primary language: swift
Topics: swift, swiftui
README: README.md