SwiftUI-Backports Documentation

repository·main·Indexed 19 days ago

https://github.com/superwall/ios-backports

A lightweight utility for using the latest SwiftUI modifier APIs on older iOS versions. It centralizes backwards compatibility logic through a Backport type, allowing developers to avoid repetitive #available checks in their UI code.

Tokens
2K
Snippets
3
Records
4
Agent score
15%

What's inside SwiftUI-Backports

  1. How the Backport type works

    main

    The Backport type provides a way to use new SwiftUI modifiers on older iOS versions without using #available checks throughout your UI code.

    Instead of wrapping views in conditional blocks like this:

    if #available(iOS 26.0, *) {
        MyView().glassEffect()
    } else {
        MyView()
    }

    You use the .backport property to access the backported version of the modifier. The Backport type handles the runtime availability branching internally, providing the new effect on supported versions and a graceful fallback on older versions.

    MyView()
        .backport.glassEffect()
  2. Install SwiftUI-Backports via Swift Package Manager

    main

    To add SwiftUI-Backports to your Xcode project using Swift Package Manager (the recommended method):

    1. Open your project in Xcode.
    2. Go to File > Add Packages…
    3. Enter the repository URL: https://github.com/superwall/iOS-Backports
    4. Select the latest version and add it to your app target.
    5. Import the module in your Swift files using import SwiftUIBackports.
    import SwiftUIBackports
    
    struct MyView: View {
        var body: some View {
            AwesomeView()
                .backport.glassEffect()
        }
    }
  3. Reference of backported SwiftUI modifiers

    main

    The following modifiers are available through the .backport property. Note that the specific fallback behavior depends on the implementation within the library for each modifier.

    | iOS Version | Modifier                                | Description                                      |
    |-------------|-----------------------------------------|--------------------------------------------------|
    | iOS 17.0    | `contentTransition(_:)`                 | Applies a basic or numeric content transition    |
    | iOS 18.0    | `matchedTransitionSource(id:in:)`       | Marks a view as a matched transition source      |
    | iOS 18.0    | `presentationSizeForm()`                | Applies `.presentationSizing(.form)`             |
    | iOS 18.0    | `zoom(sourceID:in:)`                    | Applies a zoom navigation transition             |
    | iOS 18.1    | `imagePlayground(_:completion:)`        | Presents an image playground sheet               |
    | iOS 18.0    | `widgetAccentedRenderingMode(_:)`       | Sets how an `Image` should render in widget accented mode |
    | iOS 26.0    | `backgroundExtensionEffect()`           | Extends background beyond safe areas             |
    | iOS 26.0    | `glassButtonStyle()`                    | Applies the glass button style                   |
    | iOS 26.0    | `glassEffect(_:in:)`                    | Applies a glass effect                           |
    | iOS 26.0    | `glassEffect(_:in:fallback:)`           | Glass effect with fallback background            |
    | iOS 26.0    | `glassEffectContainer(spacing:)`        | Embed in a `GlassEffectContainer`                |
    | iOS 26.0    | `glassEffectID(_:in:)`                  | Tags glass views for matched animations          |
    | iOS 26.0    | `glassEffectTransition(_:)`             | Animates glass transitions                       |
    | iOS 26.0    | `glassEffectUnion(_:namespace:)`        | Unites multiple glass effects by ID in a namespace |
    | iOS 26.0    | `glassProminentButtonStyle()`           | Applies the glass prominent button style         |
    | iOS 26.0    | `listSectionMargins(_:_: )`             | Sets margins for list sections                   |
    | iOS 26.0    | `presentationBackground(in:)`           | Applies a fallback background on earlier versions|
    | iOS 26.0    | `scrollEdgeEffectHidden(_:for:)`        | Hides scroll edge effects                        |
    | iOS 26.0    | `scrollEdgeEffectStyle(_:for:)`         | Customizes scroll view edge effects             |
    | iOS 26.0    | `symbolColorRenderingMode(_:)`          | Sets symbol image rendering mode                 |
    | iOS 26.0    | `symbolVariableValueMode(_:)`           | Sets variable value rendering mode               |
    | iOS 26.0    | `tabBarMinimizeBehavior(_:)`           | Sets the tab bar minimize behavior               |
    | iOS 26.0    | `safeAreaBar(edge:alignment:spacing:content:)` | Shows the specified content as a custom bar above or below the modified view |
    | iOS 26.0    | `tabViewBottomAccessory(content:)`      | Places a view as the bottom accessory of the tab view. |
    | iOS 26.0    | `searchToolbarBehavior(_:)`             | Configures the behavior for search in the toolbar. |
    | iOS 26.0    | `sharedBackgroundVisibility(_:)`        | Controls the visibility of the glass background effect on items in the toolbar. |