From fcbb6e99e4ea94b7c848f9cd775ea874abdf389e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 10 Jul 2023 14:46:19 -0500 Subject: [PATCH] added comments Signed-off-by: Matt Bruce --- VDS/Components/Loader/LoaderLaunchable.swift | 7 ++++ .../Loader/LoaderViewController.swift | 42 ++++++++++++------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/VDS/Components/Loader/LoaderLaunchable.swift b/VDS/Components/Loader/LoaderLaunchable.swift index 7793b000..7befd931 100644 --- a/VDS/Components/Loader/LoaderLaunchable.swift +++ b/VDS/Components/Loader/LoaderLaunchable.swift @@ -8,12 +8,18 @@ import Foundation import UIKit +/// Protocol used for any object to be able to launch a loader public protocol LoaderLaunchable { func presentLoader(surface: Surface, size: Int?) func dismissLoader() } 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) { if let presenting = UIApplication.topViewController() { let viewController = LoaderViewController(nibName: nil, bundle: nil).with { @@ -28,6 +34,7 @@ extension LoaderLaunchable { } } + /// Dismisses the Loader public func dismissLoader() { if let presenting = UIApplication.topViewController() as? LoaderViewController { presenting.dismiss(animated: true) diff --git a/VDS/Components/Loader/LoaderViewController.swift b/VDS/Components/Loader/LoaderViewController.swift index 260dc5a7..7e18c0c1 100644 --- a/VDS/Components/Loader/LoaderViewController.swift +++ b/VDS/Components/Loader/LoaderViewController.swift @@ -9,23 +9,41 @@ import Foundation import UIKit 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 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() - 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) updateView() } - + + /// Update this view based off of property chang open func updateView() { view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8) if let size { @@ -33,12 +51,4 @@ public class LoaderViewController: UIViewController, Surfaceable { } loader.surface = surface } - - private func setup() { - view.addSubview(loader) - NSLayoutConstraint.activate([ - loader.centerXAnchor.constraint(equalTo: view.centerXAnchor), - loader.centerYAnchor.constraint(equalTo: view.centerYAnchor) - ]) - } }