ActivityIndicator.swift 774 B

123456789101112131415161718192021222324252627
  1. //
  2. // ActivityIndicator.swift
  3. // naiyoup
  4. //
  5. // Created by C Auto on 2021/5/30.
  6. //
  7. import SwiftUI
  8. struct ActivityIndicator: UIViewRepresentable {
  9. typealias UIView = UIActivityIndicatorView
  10. var isAnimating: Bool
  11. var configuration = { (indicator: UIView) in }
  12. func makeUIView(context: UIViewRepresentableContext<Self>) -> UIView { UIView() }
  13. func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<Self>) {
  14. isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
  15. configuration(uiView)
  16. }
  17. }
  18. extension View where Self == ActivityIndicator {
  19. func configure(_ configuration: @escaping (Self.UIView)->Void) -> Self {
  20. Self.init(isAnimating: self.isAnimating, configuration: configuration)
  21. }
  22. }