Skip to content

Repository files navigation

DuoLayoutKit

CI Swift 6 Platforms SwiftPM License: MIT

Adaptive layout utilities for iPhone Duo — SwiftUI helpers that turn the folded and unfolded poses into plain layout intent.

Why

iPhone Duo introduces folded and unfolded poses and new multitasking layouts. Apple's guidance is to adapt with size classes, not device or orientation checks. DuoLayoutKit wraps that guidance in small, composable SwiftUI helpers so your app expresses layout intent — "compact" vs. "expanded" — instead of scattering horizontalSizeClass comparisons across your codebase. Because it is built on size classes, the same code also does the right thing on non-foldable iPhones and in iPad Split View.

Installation

Swift Package Manager

In Xcode: File > Add Package Dependencies… and enter https://github.com/yunodevs/DuoLayoutKit.

Or add it to your Package.swift:

dependencies: [
    .package(url: "https://github.com/yunodevs/DuoLayoutKit", from: "0.1.0")
]

Usage

DuoLayout — branch on the current layout mode

import SwiftUI
import DuoLayoutKit

struct LibraryScreen: View {
    var body: some View {
        DuoLayout { mode in
            switch mode {
            case .compact:
                NavigationStack {
                    BookList()
                }
            case .expanded:
                NavigationSplitView {
                    BookList()
                } detail: {
                    BookDetail()
                }
            }
        }
    }
}

The closure re-runs whenever the mode changes — unfolding iPhone Duo, rotating, or entering Split View.

\.duoLayoutMode — read the mode anywhere

Publish the mode once near the root of your scene, then read it from any descendant without threading it through initializers:

@main
struct BooksApp: App {
    var body: some Scene {
        WindowGroup {
            RootView()
                .publishDuoLayoutMode()
        }
    }
}

struct Toolbar: View {
    @Environment(\.duoLayoutMode) private var mode

    var body: some View {
        HStack {
            if mode.isExpanded {
                SearchField()
            }
            AddButton()
        }
    }
}

DuoLayoutMode — the model

DuoLayoutMode is derived purely from the horizontal size class:

Context Mode
iPhone Duo unfolded · iPad full screen · wide split pane .expanded
iPhone Duo folded · iPhone portrait · narrow split pane .compact
DuoLayoutMode(horizontalSizeClass: .regular) // .expanded
DuoLayoutMode(horizontalSizeClass: .compact) // .compact

Requirements

  • iOS 17+ / Mac Catalyst 17+
  • Swift 6+

Testing the folded and unfolded poses in Simulator additionally requires Xcode 27.1 and the iPhone Duo simulator (DeviceHub).

Documentation

Every public symbol ships with doc comments, and the package includes a DocC catalog. Build it in Xcode with Product > Build Documentation.

Roadmap

  • Fold-state-aware layout container (DuoLayout, DuoLayoutMode)
  • Inner/outer display helpers
  • Split layout utilities
  • UIKit support

See CHANGELOG.md for release notes and CONTRIBUTING.md to get involved.

License

DuoLayoutKit is available under the MIT license. See LICENSE.

About

Adaptive SwiftUI layout utilities for iPhone Duo — turn folded and unfolded poses into plain layout intent.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages