shaps80/swiftuibackports
Introducing a collection of SwiftUI backports to make your iOS development easier.
Sponsor
Building useful libraries like these, takes time away from my family. I build these tools in my spare time because I feel its important to give back to the community. Please consider Sponsoring me as it helps keep me working on useful libraries like these 😬
You can also give me a follow and a 'thanks' anytime.
[[Twitter]](http://twitter.com/shaps)
Usage
The library adopts a backport design by Dave DeLong that makes use of a single type to improve discoverability and maintainability when the time comes to remove your backport implementations, in favour of official APIs.
Backports of pure types, can easily be discovered under the Backport namespace. Similarly, modifiers are discoverable under the .backport namespace.
Unfortunately
Environmentbackports cannot be access this way, in those cases the Apple API values will be prefixed withbackportto simplify discovery.
Types:
@Backport.AppStorage("filter-enabled")
private var filterEnabled: Bool = falseModifier:
Button("Show Prompt") {
showPrompt = true
}
.sheet(isPresented: $showPrompt) {
Prompt()
.backport.presentationDetents([.medium, .large])
}Environment:
@Environment(\.backportRefresh) private var refreshActionBackports
SwiftUI
AsyncImageAppStoragebackground– ViewBuilder APIDismissActionDynamicTypeSize
– Label – LabeledContent
NavigationDestination– uses a standard NavigationViewnavigationTitle– newer APIoverlay– ViewBuilder APIonChangeopenURLProgressViewpresentationDetentspresentationDragIndicatorquicklookPreviewrequestReviewRefreshable– includes pull-to-refreshScaledMetricShareLinkStateObjectscrollDisabledscrollDismissesKeyboardscrollIndicatorsSection(_ header:)task– async/await modifier
UIKit
UIHostingConfiguration– simplifies embedding SwiftUI inUICollectionViewCellandUITableViewCell
Extras
Modal Presentations
Adding this to your presented view, you can use the provided closure to present an ActionSheet to a user when they attempt to dismiss interactively. You can also use this to disable interactive dismissals entirely.
presentation(isModal: true) { /* attempt */ }FittingGeometryReader
A custom GeometryReader implementation that correctly auto-sizes itself to its content. This is useful in many cases where you need a GeometryReader but don't want it to implicitly take up its parent View's bounds.
FittingScrollView
A custom ScrollView that respects Spacer's when the content is not scrollable. This is useful when you need to place a view at the edges of your scrollview while its content is small enough to not require scrolling. Another great use case is vertically centered content that becomes top aligned once the content requires scrolling.
Installation
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/shaps80/SwiftUIBackports.git", .upToNextMajor(from: "2.0.0"))
Package Metadata
Repository: shaps80/swiftuibackports
Default branch: main
README: README.md