Why fullScreenCover always take just first index of an array?
This is some example of code:
struct TestView: View {
@State private var isFullScreen: Bool = false
var body: some View {
VStack{
ForEach(0..<5, id:.self) { number in
VStack{
Text("(number)")
.background(.red)
.foregroundColor(.white)
.padding(20)
.onTapGesture {
isFullScreen.toggle()
}
}
.fullScreenCover(isPresented: $isFullScreen) {
test2View(title: number)
}
}
}
}
}
This is the code of test2View:
struct test2View: View {
var title:Int
var body: some View {
Text("(title)")
}
}
Whenever I click on any number it always show just 0, but when I make navigationLink instead of fullScreenCover, it works as expected, but navigationLink isn’t a solution for my problem, I want that to be fullScreenCover.
2
Answers
I found a solution using .fullScreenCover item parameter like this:
It’s because
fullScreenCover
is using a singleisFullScreen
for each number so only the first one works. Fix by adding a third intermediaryView
to hold anisFullScreen
bool for each number, e.g.