Skip to content

Instantly share code, notes, and snippets.

@indyfromoz
Forked from zntfdr/popToRoot.swift
Created April 24, 2020 09:26
Show Gist options
  • Save indyfromoz/fe223d84bde099f3321f9f420d2444fd to your computer and use it in GitHub Desktop.
Save indyfromoz/fe223d84bde099f3321f9f420d2444fd 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