struct A: View {
@State var isActive = false
@State var number = Int.random(in: 1..<10).description
var body: some View {
NavigationView {
Container {
VStack {
Button(action: {
self.isActive.toggle()
}) {
Text("移動A\(number)")
}
NavigationLink(destination: B(),isActive: $isActive) {
EmptyView()
}
}
}
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct Container <Content : View> : View {
var content : Content
@State var isLogin = false
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
ZStack {
Color.yellow.edgesIgnoringSafeArea(.all)
VStack {
VStack() {
if isLogin {
content
} else {
Text("ログインへ")
}
}
}
}.onAppear() {
isLogin = false
}
}
}