updated base viewcontroller
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
a72a28513a
commit
de9243b4fa
@ -111,7 +111,6 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
|||||||
initialSetupPerformed = true
|
initialSetupPerformed = true
|
||||||
setup()
|
setup()
|
||||||
contentTopView.backgroundColor = Surface.light.color
|
contentTopView.backgroundColor = Surface.light.color
|
||||||
surfacePickerSelectorView.scrollToBottom = { [weak self] in self?.scrollToBottom()}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,58 +136,68 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
|||||||
open func showDebug(show: Bool) {
|
open func showDebug(show: Bool) {
|
||||||
self.component.debugBorder(show: show, color: .blue)
|
self.component.debugBorder(show: show, color: .blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var contentView: UIView = {
|
|
||||||
return UIView().with {
|
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
public var formStackView = FormSection()
|
public var formStackView = FormSection()
|
||||||
|
|
||||||
public var contentTopView: UIView = {
|
lazy var stackView = UIStackView().with {
|
||||||
return UIView().with {
|
$0.axis = .vertical
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.distribution = .fill
|
||||||
}
|
$0.alignment = .fill
|
||||||
}()
|
$0.spacing = 0
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
}
|
||||||
|
|
||||||
|
let bottomScrollView = UIScrollView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
}
|
||||||
|
|
||||||
public var contentBottomView: UIView = {
|
public var contentTopView = UIView().with {
|
||||||
return UIView().with {
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
}
|
||||||
}
|
|
||||||
}()
|
public var contentBottomView = UIView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
}
|
||||||
|
|
||||||
open override func viewDidLoad() {
|
open override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.backgroundColor = .white
|
view.backgroundColor = .white
|
||||||
|
|
||||||
embed(scrollViewController)
|
|
||||||
scrollViewController.scrollView.alwaysBounceVertical = true
|
|
||||||
scrollViewController.contentView = contentView
|
|
||||||
|
|
||||||
let spacerView = UIView().with{
|
let spacerView = UIView().with{
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
}
|
}
|
||||||
|
|
||||||
contentView.addSubview(contentTopView)
|
let top = UIView.makeWrapper(for: contentTopView, edgeSpacing: 16, isTrailing: false)
|
||||||
contentView.addSubview(contentBottomView)
|
|
||||||
contentView.addSubview(spacerView)
|
// Add the top and bottom views to the stack view
|
||||||
|
stackView.addArrangedSubview(top)
|
||||||
|
stackView.addArrangedSubview(bottomScrollView)
|
||||||
|
|
||||||
|
// Add the stack view to the view controller's view
|
||||||
|
view.addSubview(stackView)
|
||||||
|
|
||||||
|
// Pin the stack view to the edges of the view controller's view
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
stackView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
|
||||||
|
stackView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
|
||||||
|
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
||||||
|
stackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
|
||||||
|
])
|
||||||
|
|
||||||
|
bottomScrollView.addSubview(contentBottomView)
|
||||||
|
|
||||||
|
// Pin the content view to the edges of the scroll view
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
contentBottomView.leadingAnchor.constraint(equalTo: bottomScrollView.leadingAnchor),
|
||||||
|
contentBottomView.trailingAnchor.constraint(equalTo: bottomScrollView.trailingAnchor),
|
||||||
|
contentBottomView.topAnchor.constraint(equalTo: bottomScrollView.topAnchor),
|
||||||
|
contentBottomView.bottomAnchor.constraint(equalTo: bottomScrollView.bottomAnchor),
|
||||||
|
contentBottomView.widthAnchor.constraint(equalTo: bottomScrollView.widthAnchor)
|
||||||
|
])
|
||||||
|
|
||||||
contentBottomView.addSubview(formStackView)
|
contentBottomView.addSubview(formStackView)
|
||||||
|
formStackView.pinToSuperView(.init(top: 0, left: 16, bottom: 0, right: edgeSpacing))
|
||||||
contentTopView.pinTop(edgeSpacing)
|
|
||||||
contentTopView.pinLeading(edgeSpacing)
|
|
||||||
contentTopView.pinTrailing(edgeSpacing)
|
|
||||||
contentBottomView.pinTop(contentTopView.bottomAnchor, edgeSpacing)
|
|
||||||
contentBottomView.pinLeading(edgeSpacing)
|
|
||||||
contentBottomView.pinTrailing(edgeSpacing)
|
|
||||||
|
|
||||||
spacerView
|
|
||||||
.pinTop(contentBottomView.bottomAnchor, 100)
|
|
||||||
.pinLeading()
|
|
||||||
.pinTrailing()
|
|
||||||
.pinBottom()
|
|
||||||
|
|
||||||
formStackView.pinToSuperView()
|
|
||||||
|
|
||||||
view.addSubview(picker)
|
view.addSubview(picker)
|
||||||
picker.pinBottom()
|
picker.pinBottom()
|
||||||
@ -199,15 +208,13 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
|||||||
setupForm()
|
setupForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
private let scrollViewController = ScrollViewController()
|
|
||||||
|
|
||||||
public func setupForm() {
|
public func setupForm() {
|
||||||
addFormRow(label: "Show Bounds", view: .makeWrapper(for: debugViewSwitch))
|
addFormRow(label: "Show Bounds", view: .makeWrapper(for: debugViewSwitch))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func scrollToBottom() {
|
public func scrollToBottom() {
|
||||||
let bottomOffset = CGPoint(x: 0, y: scrollViewController.scrollView.contentSize.height - scrollViewController.scrollView.bounds.height + scrollViewController.scrollView.contentInset.bottom)
|
let bottomOffset = CGPoint(x: 0, y: bottomScrollView.contentSize.height - bottomScrollView.bounds.height + bottomScrollView.contentInset.bottom)
|
||||||
scrollViewController.scrollView.setContentOffset(bottomOffset, animated: true)
|
bottomScrollView.setContentOffset(bottomOffset, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func embed(_ viewController: UIViewController) {
|
private func embed(_ viewController: UIViewController) {
|
||||||
@ -230,11 +237,7 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
|||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
open func addFormRow(label: String, view: UIView) -> UIView {
|
open func addFormRow(label: String, view: UIView) -> UIView {
|
||||||
let view = formStackView.addFormRow(label: label, view: view)
|
return formStackView.addFormRow(label: label, view: view)
|
||||||
if let pickerViewable = view as? any PickerViewable {
|
|
||||||
pickerViewable.scrollToBottom = { [weak self] in self?.scrollToBottom() }
|
|
||||||
}
|
|
||||||
return view
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open func setup() {
|
open func setup() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user