Swiftpack.co -  SwiftUI-Plus/Containers as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
SwiftUI-Plus/Containers
Useful SwiftUI container view's. FittingGeometry, ScrollableView, LayoutReader, PageView, UIKitView. (iOS)
.package(url: "https://github.com/SwiftUI-Plus/Containers.git", from: "1.4.1")

ios

Containers

Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+

Useful SwiftUI container view's for additional convenience.

Includes:

  • FittingGeometryReader (auto-sizes its height)
  • ScrollableView (support various contentMode options)
  • LayoutReader (supports readable and other other guides)
  • PageView (TabView in paging style but supports auto-sizing)
  • UIKit View (Easily nest UIView's in SwiftUI, including auto-sizing)

FittingGeometry

A geometry reader that automatically sizes its height to 'fit' its content.

FittingGeometryReader { geo in
    Text("The height is now \(geo.size.height)")
}

LayoutReader

A container view that provides a layout proxy, allowing you to query various layout properties usually only available via UIKit.

The most useful example is layout-relative to the readableContentGuide

Features

  • Familiar API (similar to GeometryReader)
  • SafeArea, content (layoutMargins) and readable content guide layouts
  • Responds automatically to dynamic type changes
  • Respects interface orientation and other layout changes
LayoutReader { layout in
    Rectangle()
        .foregroundColor(.red)
        .frame(maxWidth: layout.frame(in: .readable).width)
}

ScrollView

A scrollview that behaves more similarly to a VStack when its content size is small enough.

ScrollView(contentMode: .fit) {
    Text("I'm aligned to the top")
    Spacer()
    Text("I'm aligned to the bottom, until you scroll ;)")
}

PageView

A page view that behaves similarly to UIPageViewController but adds auto-sizing configuration.

// Passing `fit` for the contentMode forces the PageView to hug its content. To fill the available space, set this to `fill` (its default value)
PageView(selection: $currentPage, contentMode: .fit) {
    Group {
        Text("Page 1")
        Text("Page 2")
        Text("Page 3")
    }
}

Note: This view requires iOS 14+

UIKitView

A SwiftUI view that accepts a single UIView instance to be presented in the hierarchy.

UIKitView {
    let label = UILabel(frame: .zero)
    label.text = "foo"
    return label
}

Installation

The code is packaged as a framework. You can install manually (by copying the files in the Sources directory) or using Swift Package Manager (preferred)

To install using Swift Package Manager, add this to the dependencies section of your Package.swift file:

.package(url: "https://github.com/SwiftUI-Plus/Containers.git", .upToNextMinor(from: "1.0.0"))

Other Packages

If you want easy access to this and more packages, add the following collection to your Xcode 13+ configuration:

https://benkau.com/packages.json

GitHub

link
Stars: 6
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics