Skip to content

Instantly share code, notes, and snippets.

@zntfdr
Last active December 18, 2023 02:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zntfdr/64e27da563b6a601615dd3b704e9bab8 to your computer and use it in GitHub Desktop.
Save zntfdr/64e27da563b6a601615dd3b704e9bab8 to your computer and use it in GitHub Desktop.
//
import SwiftUI
extension Notification.Name {
static let popEverything = Notification.Name("pop_everything")
}
struct MoreTabView: View {
@State var triggerNext: Bool = false
@State var allowNavigationLinks: Bool = true
var body: some View {
VStack {
NavigationLink(
destination: View2(),
isActive: $triggerNext) {
Text("tap1")
}.isDetailLink(false)
}.onReceive(NotificationCenter.default.publisher(for: .popEverything)) { _ in
self.triggerNext = false
}
}
}
struct View2: View {
@State var showingNext: Bool = false
var body: some View {
VStack {
NavigationLink(destination: View3(), isActive: $showingNext) {
Text("tap2")
}
}
}
}
struct View3: View {
var body: some View {
VStack {
Button(action: {
NotificationCenter.default.post(name: .popEverything, object: nil)
}) {
Text("last tap")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment