From 58a4dc594aa319f6e34eeec395a292c68dd011b0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 5 Jul 2023 16:04:38 -0500 Subject: [PATCH] updated to included a LoaderLaunchable Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 8 ++++ VDS/Components/Loader/Loader.swift | 10 +---- VDS/Components/Loader/LoaderLaunchable.swift | 36 +++++++++++++++ .../Loader/LoaderViewController.swift | 44 +++++++++++++++++++ 4 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 VDS/Components/Loader/LoaderLaunchable.swift create mode 100644 VDS/Components/Loader/LoaderViewController.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 01b97406..2f702291 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -110,6 +110,8 @@ EAD062A72A3B67770015965D /* UIView+CALayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD062A62A3B67770015965D /* UIView+CALayer.swift */; }; EAD062B02A3B873E0015965D /* BadgeIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD062AF2A3B873E0015965D /* BadgeIndicator.swift */; }; EAD0688E2A55F819002E3A2D /* Loader.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD0688D2A55F819002E3A2D /* Loader.swift */; }; + EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD068912A560B65002E3A2D /* LoaderViewController.swift */; }; + EAD068942A560C13002E3A2D /* LoaderLaunchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD068932A560C13002E3A2D /* LoaderLaunchable.swift */; }; EAD8D2C128BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD8D2C028BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift */; }; EAF1FE9929D4850E00101452 /* Clickable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF1FE9829D4850E00101452 /* Clickable.swift */; }; EAF1FE9B29DB1A6000101452 /* Changeable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF1FE9A29DB1A6000101452 /* Changeable.swift */; }; @@ -245,6 +247,8 @@ EAD062A62A3B67770015965D /* UIView+CALayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+CALayer.swift"; sourceTree = ""; }; EAD062AF2A3B873E0015965D /* BadgeIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BadgeIndicator.swift; sourceTree = ""; }; EAD0688D2A55F819002E3A2D /* Loader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loader.swift; sourceTree = ""; }; + EAD068912A560B65002E3A2D /* LoaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoaderViewController.swift; sourceTree = ""; }; + EAD068932A560C13002E3A2D /* LoaderLaunchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoaderLaunchable.swift; sourceTree = ""; }; EAD8D2C028BFDE8B006EB6A6 /* UIGestureRecognizer+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIGestureRecognizer+Publisher.swift"; sourceTree = ""; }; EAF1FE9829D4850E00101452 /* Clickable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clickable.swift; sourceTree = ""; }; EAF1FE9A29DB1A6000101452 /* Changeable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Changeable.swift; sourceTree = ""; }; @@ -710,6 +714,8 @@ isa = PBXGroup; children = ( EAD0688D2A55F819002E3A2D /* Loader.swift */, + EAD068912A560B65002E3A2D /* LoaderViewController.swift */, + EAD068932A560C13002E3A2D /* LoaderLaunchable.swift */, ); path = Loader; sourceTree = ""; @@ -915,6 +921,7 @@ EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */, EAC9258F2911C9DE00091998 /* EntryField.swift in Sources */, EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, + EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */, EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */, EAF7F13328A2A16500B287F5 /* AttachmentLabelAttributeModel.swift in Sources */, EA0FC2C62914222900DF80B4 /* ButtonGroup.swift in Sources */, @@ -973,6 +980,7 @@ EA596ABF2A16B4F500300C4B /* Tabs.swift in Sources */, EAC71A212A2E1DC000E47A9F /* SelectorItemBase.swift in Sources */, EAD062A72A3B67770015965D /* UIView+CALayer.swift in Sources */, + EAD068942A560C13002E3A2D /* LoaderLaunchable.swift in Sources */, EA985BEC2968A91200F2FF2E /* TitleLockupTitleModel.swift in Sources */, 5FC35BE328D51405004EBEAC /* Button.swift in Sources */, ); diff --git a/VDS/Components/Loader/Loader.swift b/VDS/Components/Loader/Loader.swift index 607dd65a..582eaf2b 100644 --- a/VDS/Components/Loader/Loader.swift +++ b/VDS/Components/Loader/Loader.swift @@ -28,18 +28,10 @@ open class Loader: View { /// The Int used to determine the height and width of the Loader public var size: Int = 40 { didSet { setNeedsUpdate() } } + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - - override open var layer: CAShapeLayer { - get { return super.layer as! CAShapeLayer } - } - - override open class var layerClass: AnyClass { - return CAShapeLayer.self - } - open override func setup() { super.setup() addSubview(icon) diff --git a/VDS/Components/Loader/LoaderLaunchable.swift b/VDS/Components/Loader/LoaderLaunchable.swift new file mode 100644 index 00000000..7793b000 --- /dev/null +++ b/VDS/Components/Loader/LoaderLaunchable.swift @@ -0,0 +1,36 @@ +// +// LoaderLaunchable.swift +// VDS +// +// Created by Matt Bruce on 7/5/23. +// + +import Foundation +import UIKit + +public protocol LoaderLaunchable { + func presentLoader(surface: Surface, size: Int?) + func dismissLoader() +} + +extension LoaderLaunchable { + public func presentLoader(surface: Surface, size: Int? = nil) { + if let presenting = UIApplication.topViewController() { + let viewController = LoaderViewController(nibName: nil, bundle: nil).with { + $0.surface = surface + if let size { + $0.size = size + } + $0.modalPresentationStyle = .overFullScreen + $0.modalTransitionStyle = .crossDissolve + } + presenting.present(viewController, animated: true) + } + } + + 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 new file mode 100644 index 00000000..260dc5a7 --- /dev/null +++ b/VDS/Components/Loader/LoaderViewController.swift @@ -0,0 +1,44 @@ +// +// LoaderViewController.swift +// VDS +// +// Created by Matt Bruce on 7/5/23. +// + +import Foundation +import UIKit +import VDSColorTokens + +public class LoaderViewController: UIViewController, Surfaceable { + 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() { + super.viewDidLoad() + setup() + } + + public override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + updateView() + } + + open func updateView() { + view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8) + if let size { + loader.size = size + } + loader.surface = surface + } + + private func setup() { + view.addSubview(loader) + NSLayoutConstraint.activate([ + loader.centerXAnchor.constraint(equalTo: view.centerXAnchor), + loader.centerYAnchor.constraint(equalTo: view.centerYAnchor) + ]) + } +}