55 lines
1.9 KiB
Swift
55 lines
1.9 KiB
Swift
//
|
|
// LoaderViewController.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 7/5/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDSColorTokens
|
|
|
|
/// 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)
|
|
|
|
//--------------------------------------------------
|
|
// 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
|
|
}
|
|
}
|