92 lines
2.9 KiB
Swift
92 lines
2.9 KiB
Swift
//
|
|
// LoaderViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 7/5/23.
|
|
//
|
|
|
|
import Foundation
|
|
import VDS
|
|
import UIKit
|
|
|
|
class LoaderViewController: BaseViewController<Loader>, LoaderLaunchable {
|
|
|
|
var isActive = Toggle().with { $0.isOn = true }
|
|
var isFullscreen = Toggle().with { $0.isOn = false }
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
contentTopView.height(constant: 80)
|
|
addContentTopView(view: component)
|
|
setupPicker()
|
|
}
|
|
|
|
override func setupForm() {
|
|
super.setupForm()
|
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
|
addFormRow(label: "Active", view: isActive)
|
|
|
|
let fullScreen = FormSection().with { $0.title = "LoaderLaunchable (separate from Loader)" }
|
|
fullScreen.addFormRow(label: "presentLoader", view: isFullscreen)
|
|
append(section: fullScreen)
|
|
|
|
isActive
|
|
.publisher(for: .valueChanged)
|
|
.sink { [weak self] toggle in
|
|
self?.component.isActive = toggle.isOn
|
|
}.store(in: &subscribers)
|
|
|
|
isFullscreen
|
|
.publisher(for: .valueChanged)
|
|
.sink { [weak self] toggle in
|
|
guard let self else { return }
|
|
self.showLoader(fullScreen: toggle.isOn)
|
|
}.store(in: &subscribers)
|
|
}
|
|
|
|
func showLoader(fullScreen: Bool) {
|
|
if fullScreen {
|
|
component.isHidden = true
|
|
presentLoader(surface: self.component.surface)
|
|
} else {
|
|
dismissLoader()
|
|
component.isHidden = false
|
|
}
|
|
}
|
|
|
|
func setupPicker() {
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
}
|
|
|
|
public func presentLoader(surface: Surface, size: Int? = nil) {
|
|
if let presenting = UIApplication.topViewController() {
|
|
let viewController = VDS.LoaderViewController(nibName: nil, bundle: nil).with {
|
|
$0.surface = surface
|
|
if let size {
|
|
$0.size = size
|
|
}
|
|
$0.modalPresentationStyle = .overFullScreen
|
|
$0.modalTransitionStyle = .crossDissolve
|
|
}
|
|
viewController.view
|
|
.publisher(for: UITapGestureRecognizer())
|
|
.sink {[weak self] tap in
|
|
guard let self else { return }
|
|
self.isFullscreen.isOn = false
|
|
self.showLoader(fullScreen: false)
|
|
}.store(in: &subscribers)
|
|
presenting.present(viewController, animated: true)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension LoaderViewController: ComponentSampleable {
|
|
static func makeSample() -> ComponentSample {
|
|
let component = Self.makeComponent()
|
|
return ComponentSample(component: component)
|
|
}
|
|
}
|