2

I try to use "sheet" modifier to popup a modal view when a List cell was tapped. I find that it's ok in the List Cell View (Modal View could popup multi-times when cell be clicked), but in List View the modal view popups just once.

I have tried using Gesture and Button to trigger the popup, I find that once I use "sheet" modifier to trigger the Modal View, the Result is all the same.


struct ContentView: View {

    var body: some View {

        List {
            ForEach(0..<5) { _ in
                ListRow()
            }
        }

    }
}

struct ListRow: View {
    @State var showDetail: Bool = false
    var body: some View {
        HStack(spacing: 20.0) {
            Button(action: {self.showDetail = true}) {
                HStack {
                    Text("BigTitle")
                        .font(.largeTitle)
                        .fontWeight(.heavy)

                    Spacer()

                    Text("SubTitle")
                        .font(.headline)
                        .fontWeight(.medium)
                         .padding(.trailing, 10)
                }
            }
            .sheet(isPresented: self.$showDetail) {
                DetailView()
            }
        }
        .frame(width: 320, height: 48)
        .padding()
    }
}

struct DetailView: View {
    var body: some View {
        Text("I am Detail View!")
            .font(.largeTitle)
            .fontWeight(.heavy)
    }
}

I had hoped that the modal view could be popped multiple-times in the List View, but in reality the popup occurred just once.

Hope you reply! Thank you!

yawnobleix
  • 1,204
  • 10
  • 21
Alexweng
  • 348
  • 1
  • 5
  • 15
  • 3
    This appears to be a long standing bug when calling a sheet from *inside* a List. (Search on *[swiftui] sheet once* for more details. I found one possible answer that may help you on a workaround - no matter what, you need to move the sheet modifier to the *outside* of your List and then figure out which cell was pressed: https://stackoverflow.com/questions/57063633/swiftui-presentaionlink-does-not-work-second-time/57087399#57087399 –  Aug 21 '19 at 10:02
  • OK,I get. Thank you for your editing and reply. Thanks a lot. – Alexweng Aug 22 '19 at 07:15

0 Answers0