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
|
||||
setup()
|
||||
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) {
|
||||
self.component.debugBorder(show: show, color: .blue)
|
||||
}
|
||||
|
||||
public var contentView: UIView = {
|
||||
return UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
public var formStackView = FormSection()
|
||||
|
||||
public var contentTopView: UIView = {
|
||||
return UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
}()
|
||||
lazy var stackView = UIStackView().with {
|
||||
$0.axis = .vertical
|
||||
$0.distribution = .fill
|
||||
$0.alignment = .fill
|
||||
$0.spacing = 0
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
let bottomScrollView = UIScrollView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
public var contentBottomView: UIView = {
|
||||
return UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
}()
|
||||
public var contentTopView = UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
public var contentBottomView = UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = .white
|
||||
|
||||
embed(scrollViewController)
|
||||
scrollViewController.scrollView.alwaysBounceVertical = true
|
||||
scrollViewController.contentView = contentView
|
||||
|
||||
let spacerView = UIView().with{
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
contentView.addSubview(contentTopView)
|
||||
contentView.addSubview(contentBottomView)
|
||||
contentView.addSubview(spacerView)
|
||||
let top = UIView.makeWrapper(for: contentTopView, edgeSpacing: 16, isTrailing: false)
|
||||
|
||||
// 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)
|
||||
|
||||
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()
|
||||
formStackView.pinToSuperView(.init(top: 0, left: 16, bottom: 0, right: edgeSpacing))
|
||||
|
||||
view.addSubview(picker)
|
||||
picker.pinBottom()
|
||||
@ -199,15 +208,13 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
||||
setupForm()
|
||||
}
|
||||
|
||||
private let scrollViewController = ScrollViewController()
|
||||
|
||||
public func setupForm() {
|
||||
addFormRow(label: "Show Bounds", view: .makeWrapper(for: debugViewSwitch))
|
||||
}
|
||||
|
||||
public func scrollToBottom() {
|
||||
let bottomOffset = CGPoint(x: 0, y: scrollViewController.scrollView.contentSize.height - scrollViewController.scrollView.bounds.height + scrollViewController.scrollView.contentInset.bottom)
|
||||
scrollViewController.scrollView.setContentOffset(bottomOffset, animated: true)
|
||||
let bottomOffset = CGPoint(x: 0, y: bottomScrollView.contentSize.height - bottomScrollView.bounds.height + bottomScrollView.contentInset.bottom)
|
||||
bottomScrollView.setContentOffset(bottomOffset, animated: true)
|
||||
}
|
||||
|
||||
private func embed(_ viewController: UIViewController) {
|
||||
@ -230,11 +237,7 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
|
||||
|
||||
@discardableResult
|
||||
open func addFormRow(label: String, view: UIView) -> UIView {
|
||||
let view = formStackView.addFormRow(label: label, view: view)
|
||||
if let pickerViewable = view as? any PickerViewable {
|
||||
pickerViewable.scrollToBottom = { [weak self] in self?.scrollToBottom() }
|
||||
}
|
||||
return view
|
||||
return formStackView.addFormRow(label: label, view: view)
|
||||
}
|
||||
|
||||
open func setup() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user