diff --git a/.gitignore b/.gitignore index 93c86d3..894ec9a 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,11 @@ Carthage/Build # `pod install` in .travis.yml # # Pods/ +## SPM Support +.swiftpm/ +.build/ +*.xcodeproj +*.Resolved + +## Cocoapods Example project +!Example/*.xcodeproj diff --git a/DSLoadable/Classes/DSLoadable.swift b/DSLoadable/Classes/DSLoadable.swift index f14b93e..31c1230 100644 --- a/DSLoadable/Classes/DSLoadable.swift +++ b/DSLoadable/Classes/DSLoadable.swift @@ -18,7 +18,9 @@ //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN //THE SOFTWARE. +#if canImport(UIKit) import Foundation +import UIKit import MSAutoView /// Defines the structure of a loading view configuration. The first argument is the view that needs to be loaded. The second argument is the loading view @@ -103,20 +105,27 @@ extension DSLoadable where Self: UIView { return } configuration?(self, v) - addSubviewWithConstraints(v) +// DispatchQueue.main.async { + self.addSubviewWithConstraints(v) +// } } public func loadableStartLoading(configuration: DSLoadingViewFromConfiguration) { let view = configuration(self) - addSubviewWithConstraints(view) +// DispatchQueue.main.async { + self.addSubviewWithConstraints(view) +// } } public func loadableStopLoading(loadingViewType: UIView.Type = DSLoadingView.self, configuration: DSLoadableConfiguration? = nil) { - guard let loadingView = subviews.first(where: { type(of: $0) == loadingViewType }) else { - return - } - configuration?(self, loadingView) - loadingView.removeFromSuperview() +// DispatchQueue.main.async { + guard let loadingView = self.subviews.first(where: { type(of: $0) == loadingViewType }) else { + return + } + configuration?(self, loadingView) + + loadingView.removeFromSuperview() +// } } /** @@ -161,3 +170,4 @@ extension DSLoadable where Self: UIView, Self: DSLoadableConfigurable { } extension UIView: DSLoadable { } +#endif diff --git a/DSLoadable/Classes/DSLoadingView.swift b/DSLoadable/Classes/DSLoadingView.swift index 58a2c7b..c1607e9 100644 --- a/DSLoadable/Classes/DSLoadingView.swift +++ b/DSLoadable/Classes/DSLoadingView.swift @@ -18,11 +18,41 @@ //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN //THE SOFTWARE. +#if canImport(UIKit) import UIKit -import MSAutoView -open class DSLoadingView: MSAutoView { - - @IBOutlet public weak var indicatorView: UIActivityIndicatorView! +open class DSLoadingView: UIView { + public var indicatorView: UIActivityIndicatorView! + + public override init(frame: CGRect) { + super.init(frame: frame) + addIndicatorView() + } + + public required init?(coder: NSCoder) { + super.init(coder: coder) + addIndicatorView() + } + + private func addIndicatorView() { + backgroundColor = UIColor.black.withAlphaComponent(0.33) + + indicatorView = UIActivityIndicatorView() + indicatorView.translatesAutoresizingMaskIntoConstraints = false + indicatorView.style = .white + indicatorView.color = .red + + let constraints = [ + indicatorView.topAnchor.constraint(equalTo: topAnchor), + indicatorView.leadingAnchor.constraint(equalTo: leadingAnchor), + indicatorView.centerXAnchor.constraint(equalTo: centerXAnchor), + indicatorView.centerYAnchor.constraint(equalTo: centerYAnchor) + ] + + addSubview(indicatorView) + constraints.forEach({ $0.isActive = true }) + indicatorView.startAnimating() + } } +#endif diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e1fd2f4 --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "DSLoadable", + platforms: [.iOS("11.4")], + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "DSLoadable", + targets: ["DSLoadable"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(url: "https://github.com/MaherKSantina/MSAutoView", .upToNextMajor(from: "3.1.1")) + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "DSLoadable", + dependencies: ["MSAutoView"], + path: "DSLoadable/Classes"), + ] +)