Skip to content

Instantly share code, notes, and snippets.

@pitt500
Created May 29, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pitt500/2525178ce8f401e33caab7b6eb183e55 to your computer and use it in GitHub Desktop.
Save pitt500/2525178ce8f401e33caab7b6eb183e55 to your computer and use it in GitHub Desktop.
import SwiftUI
public struct SpinnerView: UIViewRepresentable {
public typealias UIViewType = UIActivityIndicatorView
public init(isAnimating: Binding<Bool>, style: UIActivityIndicatorView.Style) {
self._isAnimating = isAnimating
self.style = style
}
@Binding var isAnimating: Bool
let style: UIActivityIndicatorView.Style
public func makeUIView(context: UIViewRepresentableContext<SpinnerView>) -> UIActivityIndicatorView {
return UIActivityIndicatorView(style: style)
}
public func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<SpinnerView>) {
if isAnimating {
uiView.isUserInteractionEnabled = false
uiView.startAnimating()
} else {
uiView.isUserInteractionEnabled = true
uiView.stopAnimating()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment