The code must be fairly self-explanatory: I’ve a listing of things. When clicking the “…”, it pops up a sheet. When clicking the button within the sheet it goes to an entire new view.
Nevertheless, there are two issues with the implementation:
- I’ve to click on “again” a number of instances within the third view so as to come again to the primary view. How do I repair this?
- NavigationLink(isActive) is marked as deprecated. What’s the easiest way to exchange it?
This is the code:
struct TestView: View {
@State personal var secondViewPresented = false
@State personal var thirdViewPresented = false
var physique: some View {
ForEach(["1", "2", "3"], id: .self) { choice in
HStack {
Textual content(choice)
Button(motion: {
self.secondViewPresented = true
}) {
Picture(systemName: "ellipsis")
.padding()
}
}
}
.sheet(isPresented: self.$secondViewPresented) {
secondView()
}
.background(
NavigationLink(
vacation spot: ThirdView(),
isActive: self.$thirdViewPresented
) {
EmptyView()
}
)
.onAppear() {
// self.thirdViewPresented = false - would not assist
}
}
personal func secondView() -> some View {
HStack {
Button(motion: {
self.secondViewPresented = false
self.thirdViewPresented = true
}) {
HStack {
Textual content("Go to third View (thirdViewPresented)")
}
.body(maxWidth: .infinity, maxHeight: .infinity)
}
}
.presentationDetents([.fraction(0.1)])
.padding()
}
}
struct ThirdView: View {
var physique: some View {
Textual content("ThirdView")
}
}
#Preview {
NavigationStack {
TestView()
}
}