Created
May 29, 2020 21:10
-
-
Save pitt500/2525178ce8f401e33caab7b6eb183e55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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