Contents

DevonMartin/EasyGeometryProxy

SwiftUI extension for effortlessly accessing and monitoring view sizes and safe area insets. Replace traditional GeometryReader usage with a streamlined approach. Requires iOS 17.0, macOS 14.0

Usage

Working with your view's size has never been so clean.

Examples:

1. Accessing Safe Area Insets on Appearance

Before:

.background {
    GeometryReader { proxy in
        Color.clear
            .onAppear {
                setBottomSafeArea(proxy.safeAreaInsets)
            }
    }
}

After:

.withViewInsets(onAppear: setBottomSafeArea)

2. Accessing Both Size and Insets on Appearance and Change

Before:

.background {
    GeometryReader { proxy in
        Color.clear
            .onAppear {
                someFunction(proxy)
            }
        .onChange(of: proxy.size, perform: someFunction)
        .onChange(of: proxy.safeAreaInsets, perform: someFunction)
    }
}

After:

.withViewGeometryProxy(
    onAppear: someFunction,
    onChangeSize: someFunction,
    onChangeInsets: someFunction
)

3. Demonstrating Overloading with 0 or 2 Parameters

Explicit

.withViewGeometryProxy { proxy in
    someFunction(proxy)
} onChangeSize: {
    /* 0 parameters */ 
    someFunction()
} onChangeInsets: { oldInsets, newInsets in
    /* 2 parameters */
    someFunction(oldInsets, newInsets)
}

Implicit

.withViewGeometryProxy(
    onAppear: someFunction,
    onChangeSize: someFunction,  // 0 parameters
    onChangeInsets: someFunction // 2 parameters
)

Installation

  1. To use EasyGeometryProxy, in Xcode, navigate to: File ➡ Add Package Dependencies
  1. In the top-right search bar, enter: https://github.com/DevonMartin/EasyGeometryProxy
  1. Ensure your project is selected in the drop down Add to Project menu, and then click Add Package.

That's it! Then, in any file you want to access the package, simply import EasyGeometryProxy.

License

The MIT License (MIT)

Copyright © 2023 Devon Martin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Metadata

Repository: DevonMartin/EasyGeometryProxy

Stars: 1

Forks: 0

Open issues: 0

Default branch: main

Primary language: swift

License: MIT

README: README.md