added the borderline as a view to be repositioned based on orientation + indicator position

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-06-08 12:35:00 -05:00
parent 571b41b54e
commit ae4d0f5287

View File

@ -101,10 +101,19 @@ open class Tabs: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
private var tabStackView: UIStackView! private var tabStackView = UIStackView()
private var scrollView: UIScrollView! private var scrollView = UIScrollView()
private var contentView: View! private var contentView = View()
private var borderlineView = View()
private let borderlineSize = 1.0
private var borderlineColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsLowcontrastOnlight, VDSColor.elementsLowcontrastOndark) private var borderlineColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsLowcontrastOnlight, VDSColor.elementsLowcontrastOndark)
private var borderlineViewLeadingConstraint: NSLayoutConstraint?
private var borderlineViewTrailingConstraint: NSLayoutConstraint?
private var borderlineViewTopConstraint: NSLayoutConstraint?
private var borderlineViewBottomConstraint: NSLayoutConstraint?
private var borderlineViewHeightConstraint: NSLayoutConstraint?
private var borderlineViewWidthConstraint: NSLayoutConstraint?
private var contentViewWidthConstraint: NSLayoutConstraint? private var contentViewWidthConstraint: NSLayoutConstraint?
//-------------------------------------------------- //--------------------------------------------------
@ -141,12 +150,22 @@ open class Tabs: View {
tabStackView.axis = .horizontal tabStackView.axis = .horizontal
tabStackView.distribution = .fill tabStackView.distribution = .fill
tabStackView.translatesAutoresizingMaskIntoConstraints = false tabStackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(borderlineView)
contentView.addSubview(tabStackView) contentView.addSubview(tabStackView)
scrollView.pinToSuperView() scrollView.pinToSuperView()
contentView.pinToSuperView() contentView.pinToSuperView()
tabStackView.pinToSuperView() tabStackView.pinToSuperView()
contentView.heightAnchor.constraint(equalTo: scrollView.heightAnchor).isActive = true contentView.heightAnchor.constraint(equalTo: scrollView.heightAnchor).isActive = true
borderlineViewWidthConstraint = borderlineView.widthAnchor.constraint(equalToConstant: 0)
borderlineViewHeightConstraint = borderlineView.heightAnchor.constraint(equalToConstant: 0)
borderlineViewLeadingConstraint = borderlineView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor)
borderlineViewTrailingConstraint = borderlineView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
borderlineViewTopConstraint = borderlineView.topAnchor.constraint(equalTo: contentView.topAnchor)
borderlineViewBottomConstraint = borderlineView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
} }
private func updateTabItems() { private func updateTabItems() {
@ -256,7 +275,6 @@ open class Tabs: View {
} }
//borderLine //borderLine
removeBorders()
if borderLine { if borderLine {
var edge: UIRectEdge = .bottom var edge: UIRectEdge = .bottom
if orientation == .vertical { if orientation == .vertical {
@ -264,7 +282,39 @@ open class Tabs: View {
} else if indicatorPosition == .top { } else if indicatorPosition == .top {
edge = .top edge = .top
} }
addBorder(side: edge, width: 1, color: borderlineColorConfiguration.getColor(self))
borderlineViewLeadingConstraint?.isActive = false
borderlineViewTrailingConstraint?.isActive = false
borderlineViewTopConstraint?.isActive = false
borderlineViewBottomConstraint?.isActive = false
borderlineViewHeightConstraint?.isActive = false
borderlineViewWidthConstraint?.isActive = false
if edge == .left {
borderlineViewWidthConstraint?.constant = borderlineSize
borderlineViewWidthConstraint?.isActive = true
borderlineViewTopConstraint?.isActive = true
borderlineViewLeadingConstraint?.isActive = true
borderlineViewBottomConstraint?.isActive = true
} else if edge == .top {
borderlineViewHeightConstraint?.constant = borderlineSize
borderlineViewHeightConstraint?.isActive = true
borderlineViewTopConstraint?.isActive = true
borderlineViewLeadingConstraint?.isActive = true
borderlineViewTrailingConstraint?.isActive = true
} else {
borderlineViewHeightConstraint?.constant = borderlineSize
borderlineViewHeightConstraint?.isActive = true
borderlineViewLeadingConstraint?.isActive = true
borderlineViewTrailingConstraint?.isActive = true
borderlineViewBottomConstraint?.isActive = true
}
borderlineView.backgroundColor = borderlineColorConfiguration.getColor(self)
borderlineView.isHidden = false
} else {
borderlineView.isHidden = true
} }
scrollToSelectedIndex(animated: true) scrollToSelectedIndex(animated: true)