vds_ios/VDS/Components/Loader/LoaderViewController.swift
Matt Bruce 6bf3e19ebe added @objcMembers to all classes
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-07-25 10:53:26 -05:00

57 lines
2.0 KiB
Swift

//
// LoaderViewController.swift
// VDS
//
// Created by Matt Bruce on 7/5/23.
//
import Foundation
import UIKit
import VDSCoreTokens
/// ViewController to show the Loader, this will be presented using the LoaderLaunchable Protocl.
@objcMembers
@objc(VDSLoaderViewController)
open class LoaderViewController: UIViewController, Surfaceable {
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private var loader = Loader()
private var backgroundColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark)
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
/// Current Surface and this is used to pass down to child objects that implement Surfacable
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()
view.addSubview(loader)
NSLayoutConstraint.activate([
loader.centerXAnchor.constraint(equalTo: view.centerXAnchor),
loader.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateView()
}
/// Used to make changes to the View based off a change events or from local properties.
open func updateView() {
view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8)
if let size {
loader.size = size
}
loader.surface = surface
}
}