ios – Why fullScreenCover always take first index from array?

0
91

[ad_1]

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.

[ad_2]