Created
June 12, 2019 21:01
-
-
Save lindskogen/a5b10a48f208256631dee78cba99dd7c to your computer and use it in GitHub Desktop.
SwiftUI Wrapper for UIActivityIndicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
struct ActivityIndicator : UIViewRepresentable { | |
var animating: Bool | |
var hidesWhenStopped = true | |
var style: UIActivityIndicatorView.Style = UIActivityIndicatorView.Style.medium | |
func makeUIView(context: Context) -> UIActivityIndicatorView { | |
let control = UIActivityIndicatorView() | |
updateValues(for: control) | |
return control | |
} | |
func updateValues(for uiView: UIActivityIndicatorView) { | |
uiView.style = style | |
uiView.hidesWhenStopped = hidesWhenStopped | |
if animating { | |
uiView.startAnimating() | |
} else { | |
uiView.stopAnimating() | |
} | |
} | |
func updateUIView(_ uiView: UIActivityIndicatorView, context: Context) { | |
updateValues(for: uiView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment