Skip to content

Instantly share code, notes, and snippets.

@JagCesar
Created July 3, 2024 17:57
Show Gist options
  • Select an option

  • Save JagCesar/17fa60e25ca196f5cb171d518157ee67 to your computer and use it in GitHub Desktop.

Select an option

Save JagCesar/17fa60e25ca196f5cb171d518157ee67 to your computer and use it in GitHub Desktop.
SwiftUI view that pushes twice on iOS 18 b2
//
// ContentView.swift
// dev
//
// Created by César Pinto Castillo on 2024-07-03.
//
import SwiftUI
struct ContentView: View {
@State private var pathManager = PathManager()
@State private var selectedTab: Tabs = .first
var body: some View {
TabView(selection: $selectedTab) {
Tab("First", systemImage: "circle", value: .first) {
NavigationStack(path: $pathManager.firstPath) {
NavigationLink(value: NavigationPath.third) {
Text("Open Third")
}
.navigationDestination()
}
}
Tab("Second", systemImage: "square", value: .second) {
NavigationStack(path: $pathManager.secondPath) {
NavigationLink(value: NavigationPath.fourth) {
Text("Open Fourth")
}
.navigationDestination()
}
}
}
}
}
enum Tabs {
case first
case second
}
enum NavigationPath {
case third
case fourth
}
extension View {
func navigationDestination() -> some View {
self.navigationDestination(for: NavigationPath.self) { path in
switch path {
case .fourth:
Text("Fourth")
case .third:
Text("Third")
}
}
}
}
@Observable
class PathManager {
var firstPath: [NavigationPath] = []
var secondPath: [NavigationPath] = []
}
#Preview {
ContentView()
}
@vojtabohm
Copy link

Check out my answer on Apple Dev Forums. It's a bug in iOS 18 and 18.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment