Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI ProgressView not showing when inside List

In the following simple example you will find that the first time you tap Toggle Loading the ProgressView is shown as it should, but the second time (3rd tap) it's not. It seems to be caused by the surrounding List.

Any ideas what the issue is and how to make it work?

struct ContentView: View {

    @State private var isLoading = false

    var body: some View {
        List {
            if isLoading {
                HStack(alignment: .center, spacing: 10) {
                    ProgressView()
                    Text("Loading")
                }
            } else {
                Text("Not Loading")
            }

            Button("Toggle Loading") {
                isLoading.toggle()
            }
        }
    }
}
like image 678
Isaak Avatar asked May 02 '26 06:05

Isaak


1 Answers

struct ContentView: View {
  
  @State private var isLoading = false
  
  var body: some View {
    List {
      HStack(alignment: .center, spacing: 10) {
        if isLoading {
          ProgressView()
        }
        Text(isLoading ? "Loading" : "Not Loading")
      }
      
      Button("Toggle Loading") {
        isLoading.toggle()
      }
    }
  }
}
like image 119
zzzwco Avatar answered May 05 '26 13:05

zzzwco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!