Logo for tanaschita.com

Adapting SwiftUI layouts for iPhone Duo

Learn how to respond to changing window sizes without device or orientation checks.

02 Nov 2026 · 5 min read

Opening or closing iPhone Duo can resize an app while it is running. A layout that fits the compact outer display may therefore receive considerably more space on the inner display without the app being relaunched.

In this article, we'll explore ways to make SwiftUI layouts adapt to changing space.

Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE

Adapting list and detail navigation

A common SwiftUI interface uses a List inside a NavigationStack to navigate to a detail screen. This setup responds to size changes, but continues to display one screen at a time. On iPhone Duo's larger inner display, the list and detail could instead make use of the available space together.

For this, we can use NavigationSplitView. It presents the list and selected detail side by side when space allows and automatically collapses them into stack-based navigation in a compact environment:

struct FieldNotesView: View {
@State private var selection: Specimen?
var body: some View {
NavigationSplitView {
List(Specimen.examples, selection: $selection) { specimen in
NavigationLink(value: specimen) {
Label(specimen.name, systemImage: "leaf")
}
}
.navigationTitle("Field Notes")
} detail: {
if let selection {
SpecimenDetails(specimen: selection)
} else {
ContentUnavailableView(
"Select a specimen",
systemImage: "leaf"
)
}
}
}
}

NavigationSplitView manages that transition while preserving the selected specimen. This also means that the layout doesn't need to know when the device folds or unfolds. It responds to the resulting presentation environment instead.

Adapting content to the available space

Beyond navigation, we can also adapt how individual views arrange and present their content. SwiftUI offers several tools for this, such as ViewThatFits or horizontalSizeClass.

Let's look at an example using horizontalSizeClass. It has two possible values: .compact and .regular. In a typical full-screen presentation, iPhones in portrait as well as the outer display of a closed iPhone Duo use .compact. The inner display of an open iPhone Duo and a full-screen iPad use .regular. The value always describes the space the app currently has, not the device it runs on.

For example, SwiftUI's Table view already adapts to these values. It displays all columns in .regular and only the first column in .compact. To keep the habitat and conservation status visible in the compact presentation, we can include them in the first column:

private struct SpecimenTable: View {
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
var body: some View {
Table(Specimen.examples) {
TableColumn("Name") { specimen in
VStack(alignment: .leading) {
Text(specimen.name)
if horizontalSizeClass == .compact {
Text("\(specimen.habitat) · \(specimen.status)")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
TableColumn("Habitat", value: \.habitat)
TableColumn("Status", value: \.status)
}
}
}

When a layout decision depends on whether content fits within a particular view, ViewThatFits can be a better choice. The article on building adaptive layouts with ViewThatFits explores that approach.

Letting SwiftUI handle changing safe areas

Safe areas work on iPhone Duo the same way as on any other device. SwiftUI provides the current safe area and keeps it up to date, so we don't have to calculate it ourselves, even when the available space changes while the app is running.

We can still let a decorative background extend to the edges with ignoresSafeArea(), while keeping text and interactive elements inside the safe area:

ZStack {
Color.green
.ignoresSafeArea()
VStack(spacing: 16) {
Text("European tree frog")
.font(.largeTitle)
Button("Add observation") {
// Add a new field note
}
}
.padding()
}

Conclusion

Preparing a SwiftUI layout for iPhone Duo doesn't require detecting the device. Standard navigation containers, size classes and safe areas allow the same view hierarchy to respond as the app moves between different presentations.

Sponsorship logo
Preparing for a technical iOS job interview
Preparing for a technical iOS Job Interview with over 300 questions & answers. Covering Swift & Objective-C, SwiftUI & UIKit, Combine, HTTP Networking, iOS File System, Core Data, Concurrency with async/await, Security, Automated Testing, Dependency Management, AI & Machine Learning and more.
LEARN MORE
Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE
Sponsorship logo
Become a sponsor of tanaschita.com
By publishing an article on different iOS topics every week, tanaschita.com is constantly growing in the developer community and may provide a great audience for you as a sponsor.
CLICK TO LEARN MORE

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

accessibility

swiftui

ios

Making custom SwiftUI controls accessible with accessibilityRepresentation

Learn how to give a custom control the accessibility behavior of a native SwiftUI control.

19 Oct 2026 · 5 min read

Latest articles and tips

© 2026 tanaschita.com

Privacy policy

Impressum