added comments
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
b0576634ae
commit
fcbb6e99e4
@ -8,12 +8,18 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
/// Protocol used for any object to be able to launch a loader
|
||||||
public protocol LoaderLaunchable {
|
public protocol LoaderLaunchable {
|
||||||
func presentLoader(surface: Surface, size: Int?)
|
func presentLoader(surface: Surface, size: Int?)
|
||||||
func dismissLoader()
|
func dismissLoader()
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LoaderLaunchable {
|
extension LoaderLaunchable {
|
||||||
|
|
||||||
|
/// Default implementation for presenting
|
||||||
|
/// - Parameters:
|
||||||
|
/// - surface: Surface for the Loader
|
||||||
|
/// - size: Size for the loader, nil is default.
|
||||||
public func presentLoader(surface: Surface, size: Int? = nil) {
|
public func presentLoader(surface: Surface, size: Int? = nil) {
|
||||||
if let presenting = UIApplication.topViewController() {
|
if let presenting = UIApplication.topViewController() {
|
||||||
let viewController = LoaderViewController(nibName: nil, bundle: nil).with {
|
let viewController = LoaderViewController(nibName: nil, bundle: nil).with {
|
||||||
@ -28,6 +34,7 @@ extension LoaderLaunchable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dismisses the Loader
|
||||||
public func dismissLoader() {
|
public func dismissLoader() {
|
||||||
if let presenting = UIApplication.topViewController() as? LoaderViewController {
|
if let presenting = UIApplication.topViewController() as? LoaderViewController {
|
||||||
presenting.dismiss(animated: true)
|
presenting.dismiss(animated: true)
|
||||||
|
|||||||
@ -9,23 +9,41 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
|
|
||||||
public class LoaderViewController: UIViewController, Surfaceable {
|
/// ViewController to show the Loader, this will be presented using the LoaderLaunchable Protocl.
|
||||||
|
open class LoaderViewController: UIViewController, Surfaceable {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Private Properties
|
||||||
|
//--------------------------------------------------
|
||||||
private var loader = Loader()
|
private var loader = Loader()
|
||||||
private var backgroundColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark)
|
private var backgroundColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark)
|
||||||
|
|
||||||
public var surface: Surface = .light
|
|
||||||
public var size: Int?
|
|
||||||
|
|
||||||
public override func viewDidLoad() {
|
//--------------------------------------------------
|
||||||
|
// MARK: - Public Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
/// Current Surface used within this Control and used to passdown to child views
|
||||||
|
open var surface: Surface = .light { didSet { updateView() }}
|
||||||
|
|
||||||
|
/// Size of the Height and Width of the Loader view.
|
||||||
|
open var size: Int? { didSet { updateView() }}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Lifecycle
|
||||||
|
//--------------------------------------------------
|
||||||
|
open override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
setup()
|
view.addSubview(loader)
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
loader.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||||
|
loader.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func viewWillAppear(_ animated: Bool) {
|
open override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
updateView()
|
updateView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update this view based off of property chang
|
||||||
open func updateView() {
|
open func updateView() {
|
||||||
view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8)
|
view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8)
|
||||||
if let size {
|
if let size {
|
||||||
@ -33,12 +51,4 @@ public class LoaderViewController: UIViewController, Surfaceable {
|
|||||||
}
|
}
|
||||||
loader.surface = surface
|
loader.surface = surface
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setup() {
|
|
||||||
view.addSubview(loader)
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
loader.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
||||||
loader.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user