Created
March 24, 2021 08:40
-
-
Save takoikatakotako/d5a2781b0fc46a0a60feebcfc5235e23 to your computer and use it in GitHub Desktop.
SwiftUIで初めの画面に遷移する(popToRootViewController)
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
import SwiftUI | |
struct ContentView: View { | |
@State var isActive : Bool = false | |
var body: some View { | |
NavigationView { | |
NavigationLink( | |
destination: SecondView(rootIsActive: $isActive), | |
isActive: $isActive | |
) { | |
Text("Go SecondView") | |
} | |
.isDetailLink(false) | |
.navigationBarTitle("Root") | |
} | |
} | |
} | |
struct SecondView: View { | |
@Binding var rootIsActive : Bool | |
var body: some View { | |
NavigationLink(destination: ThirdView(shouldPopToRootView: self.$rootIsActive)) { | |
Text("Go ThirdView") | |
} | |
.isDetailLink(false) | |
.navigationBarTitle("SecondView") | |
} | |
} | |
struct ThirdView: View { | |
@Binding var shouldPopToRootView : Bool | |
var body: some View { | |
VStack { | |
Button (action: { shouldPopToRootView = false } ){ | |
Text("Pop to RootView") | |
} | |
}.navigationBarTitle("ThirdView") | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
refs: SwiftUI: How to pop to Root view