10

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()
            }
        }
    }
}

1 Answer 1

3
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()
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.