Skip to content

TechThings/NavigationTransition

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Zoom Navigation Transition – New in iOS 18! πŸŽ‰

iOS 18 introduces a new way to navigate between views in SwiftUI – Zoom Navigation Transition. This smooth and visually appealing animation makes transitions between screens more intuitive and engaging.

πŸ“Œ Demonstration

πŸ”Ή How It Works

Instead of the standard push transition, Zoom Navigation Transition shrinks the current view while seamlessly expanding the new screen. This effect works perfectly for apps where users transition from an overview to a detailed view (e.g., list β†’ details).

It also enables intuitive back navigation using gestures, making the user experience even smoother.

πŸ”Ή Implementation

To implement Zoom Navigation Transition, you need to:

βœ… Define the source of the animation using matchedTransitionSource
βœ… Add the modifier .navigationTransition(.zoom) to the destination view

Both elements must share the same @Namespace variable to ensure a smooth and natural animation.

πŸ“Œ Example Code

import SwiftUI

struct TestView: View {
    @State private var route: [String] = []
    @Namespace private var transitionNamespace
    
    var body: some View {
        NavigationStack(path: $route) {
            VStack {
                Rectangle()
                    .fill(.blue.gradient)
                    .frame(width: 200, height: 300)
                    .clipShape(RoundedRectangle(cornerRadius: 12))
                    .matchedTransitionSource(id: "rectangle", in: transitionNamespace)
                    .onTapGesture {
                        route.append("details")
                    }
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .navigationDestination(for: String.self) { destination in
                switch destination {
                case "details":
                    Rectangle()
                        .fill(.blue.gradient)
                        .toolbarVisibility(.hidden, for: .navigationBar)
                        .clipShape(RoundedRectangle(cornerRadius: 12))
                        .navigationTransition(
                            .zoom(
                                sourceID: "rectangle",
                                in: transitionNamespace
                            )
                        )
                default:
                    EmptyView()
                }
            }
        }
    }
}

#Preview {
    TestView()
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%