title: SwiftUI toggle State bool onTapGesture using main tread
body: <p>I wrote the following to attempt to display a &quot;arrow.down.circle.fill&quot; and then when tapped display a progress view until tasks are done on the main tread. I then want to display the down arrow image again. I noticed it works fine when using a background thread, but then my UI in my main view doesn't update because published changes on background threads aren't allowed.</p>
  <pre><code>struct TestAnimation: View {
      @State var isLoading: Bool = false
      var body: some View {
          if !isLoading {
              Image(systemName: &quot;arrow.down.circle.fill&quot;)
                  .font(.system(size: 35))
                  .padding()
                  .foregroundColor(.blue)
                  .imageScale(.large)
                  .onTapGesture {
                      DoSomthingMainTread()
                  }
          }
          else {
              ProgressView()
                  .progressViewStyle(CircularProgressViewStyle(tint: .blue))
                  .padding(30)
                  .scaleEffect(3)
          }
      }
      
      func DoSomthingMainTread(){
          DispatchQueue.global(qos: .background).async {
              isLoading = true
              DispatchQueue.main.async {
                  sleep(3) //call function here
              }
              isLoading = false
          }
      }
  }
  </code></pre>
  <p>Thanks for any help!!</p>