[SwiftUI] Bring UIActivityIndicatorView to SwiftUI

Updated
Sep 17, 2019 2:52 PM
Created
Sep 17, 2019 2:51 PM
Tags
Keywords
struct IndicatorView : UIViewRepresentable {
  
  @Binding var isAnimating: Bool
 
  func makeUIView(context: UIViewRepresentableContext<IndicatorView>) -> UIActivityIndicatorView {
    let view = UIActivityIndicatorView()
    return view
  }
  
  func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<IndicatorView>) {
    if isAnimating {
      uiView.startAnimating()
    } else {
      uiView.stopAnimating()
    }
  }
}

IndicatorView(isAnimating: .constant(true))