Skip to content
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ Carthage/Build
# `pod install` in .travis.yml
#
# Pods/
## SPM Support
.swiftpm/
.build/
*.xcodeproj
*.Resolved

## Cocoapods Example project
!Example/*.xcodeproj
24 changes: 17 additions & 7 deletions DSLoadable/Classes/DSLoadable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
// }
}

/**
Expand Down Expand Up @@ -161,3 +170,4 @@ extension DSLoadable where Self: UIView, Self: DSLoadableConfigurable {
}

extension UIView: DSLoadable { }
#endif
38 changes: 34 additions & 4 deletions DSLoadable/Classes/DSLoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"),
]
)