Skip to content

Instantly share code, notes, and snippets.

@simonbs
Created January 26, 2026 10:49
Show Gist options
  • Select an option

  • Save simonbs/a39a8536f9ba1a4b68903147fed02737 to your computer and use it in GitHub Desktop.

Select an option

Save simonbs/a39a8536f9ba1a4b68903147fed02737 to your computer and use it in GitHub Desktop.
How can I present DetailView with a zoom transition without clipping the navigation bar of the presenting view?
import Foundation
import SwiftUI
struct ColorItem: Hashable, Identifiable {
let id = UUID()
let color: Color
}
extension ColorItem {
static var allItems: [Self] {
let colors: [Color] = [.red, .orange, .yellow, .green, .cyan, .blue, .indigo, .purple]
return (0 ..< 50).map { Self(color: colors[$0 % colors.count]) }
}
}
import SwiftUI
struct ContentView: View {
@Namespace private var namespace
@State private var selectedItem: ColorItem?
private let items = ColorItem.allItems
private let columns: [GridItem] = Array(repeating: GridItem(.flexible(), spacing: 12), count: 3)
var body: some View {
NavigationStack {
ScrollView {
LazyVGrid(columns: columns, spacing: 12) {
ForEach(items, id: \.self) { item in
Button {
selectedItem = item
} label: {
RoundedRectangle(cornerRadius: 14)
.fill(item.color)
.aspectRatio(1, contentMode: .fit)
.matchedTransitionSource(id: item.id, in: namespace)
}
}
}
.padding(12)
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Example")
.fullScreenCover(item: $selectedItem) { item in
DetailView(item: item)
.navigationTransition(.zoom(sourceID: item.id, in: namespace))
}
}
}
}
#Preview {
ContentView()
}
import SwiftUI
struct DetailView: View {
let item: ColorItem
@Environment(\.dismiss) private var dismiss
var body: some View {
NavigationStack {
VStack {
RoundedRectangle(cornerRadius: 14)
.fill(item.color)
.aspectRatio(1, contentMode: .fit)
}
.padding()
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Item")
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button {
dismiss()
} label: {
Label("Back", systemImage: "chevron.left")
.labelStyle(.iconOnly)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment