Swiftpack.co - SwiftUI-Plus/Containers as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by SwiftUI-Plus.
SwiftUI-Plus/Containers 1.6.0
Useful SwiftUI container view's. FittingGeometry, ScrollableView, LayoutReader, PageView, UIKitView. (iOS)
⭐️ 40
🕓 2 years ago
iOS macOS tvOS
.package(url: "https://github.com/SwiftUI-Plus/Containers.git", from: "1.6.0")

ios


Most of these containers now available as in a single Backports library, with a LOT more additions. This should simply my efforts and allow me and others to contribute more backports in the near future. SwiftUI Backports


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: 40
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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