Adaptive layout utilities for iPhone Duo — SwiftUI helpers that turn the folded and unfolded poses into plain layout intent.
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.
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")
]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.
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 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- 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).
Every public symbol ships with doc comments, and the package includes a DocC catalog. Build it in Xcode with Product > Build Documentation.
- 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.
DuoLayoutKit is available under the MIT license. See LICENSE.