Created
July 3, 2024 17:57
-
-
Save JagCesar/17fa60e25ca196f5cb171d518157ee67 to your computer and use it in GitHub Desktop.
SwiftUI view that pushes twice on iOS 18 b2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
However, in a more real-world like example where views are separated and the PathManager passed as an environment object, it seems to work...