Created
November 30, 2020 16:27
-
-
Save profh/d2ae0c01158d818ed18c29f24cb0089a to your computer and use it in GitHub Desktop.
A quick hack to add navigation in SwiftUI to buttons
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
// 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