Skip to content

Instantly share code, notes, and snippets.

@profh
Created November 30, 2020 16:27
Show Gist options
  • Save profh/d2ae0c01158d818ed18c29f24cb0089a to your computer and use it in GitHub Desktop.
Save profh/d2ae0c01158d818ed18c29f24cb0089a to your computer and use it in GitHub Desktop.
A quick hack to add navigation in SwiftUI to buttons
// A quick hack to add navigation in SwiftUI to buttons
// Using Swift 5.0
// Running on macOS 11.0
// Qapla'
//
import SwiftUI
extension View {
func navigate<NewView: View>(to view: NewView, when binding: Binding<Bool>) -> some View {
NavigationView {
ZStack {
self
.navigationBarTitle("")
.navigationBarHidden(true)
NavigationLink(
destination: view
.navigationBarTitle("")
.navigationBarHidden(true),
isActive: binding
) { EmptyView() }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment