added properties to push down
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
18eec4241b
commit
d90045918b
@ -30,6 +30,14 @@ public class Tabs: View {
|
||||
public enum IndicatorPosition {
|
||||
case top
|
||||
case bottom
|
||||
|
||||
var value: UIRectEdge {
|
||||
if self == .top {
|
||||
return .top
|
||||
} else {
|
||||
return .bottom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Overflow {
|
||||
@ -56,7 +64,7 @@ public class Tabs: View {
|
||||
}
|
||||
|
||||
public var onTabChange: ((Int) -> Void)?
|
||||
public var orientation: Orientation = .vertical { didSet { setNeedsUpdate() } }
|
||||
public var orientation: Orientation = .horizontal { didSet { setNeedsUpdate() } }
|
||||
public var borderLine: Bool = true { didSet { setNeedsUpdate() } }
|
||||
public var fillContainer: Bool = false { didSet { setNeedsUpdate() } }
|
||||
public var indicatorFillTab: Bool = false { didSet { setNeedsUpdate() } }
|
||||
@ -175,6 +183,7 @@ public class Tabs: View {
|
||||
tabItem.size = size
|
||||
tabItem.orientation = orientation
|
||||
tabItem.surface = surface
|
||||
tabItem.indicatorPosition = indicatorPosition
|
||||
}
|
||||
|
||||
if borderLine {
|
||||
@ -220,6 +229,7 @@ public class Tabs: View {
|
||||
public class TabItem: View {
|
||||
public var orientation: Tabs.Orientation = .horizontal { didSet { setNeedsUpdate() } }
|
||||
public var size: Tabs.Size = .medium { didSet { setNeedsUpdate() } }
|
||||
public var indicatorPosition: Tabs.IndicatorPosition = .bottom { didSet { setNeedsUpdate() } }
|
||||
public var label: Label = Label()
|
||||
public var onClick: (() -> Void)? { didSet { setNeedsUpdate() } }
|
||||
public var width: CGFloat? { didSet { setNeedsUpdate() } }
|
||||
@ -228,7 +238,9 @@ public class TabItem: View {
|
||||
private var labelMinWidthConstraint: NSLayoutConstraint?
|
||||
private var labelWidthConstraint: NSLayoutConstraint?
|
||||
private var labelLeadingConstraint: NSLayoutConstraint?
|
||||
|
||||
private var labelTopConstraint: NSLayoutConstraint?
|
||||
private var labelBottomConstraint: NSLayoutConstraint?
|
||||
|
||||
private var textColorConfiguration: SurfaceColorConfiguration { selected ? textColorSelectedConfiguration : textColorNonSelectedConfiguration }
|
||||
private var textColorNonSelectedConfiguration = SurfaceColorConfiguration(VDSColor.elementsSecondaryOnlight , VDSColor.elementsSecondaryOnlight)
|
||||
private var textColorSelectedConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
|
||||
@ -242,14 +254,20 @@ public class TabItem: View {
|
||||
label.backgroundColor = .clear
|
||||
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
label
|
||||
.pinTop(5)
|
||||
.pinTrailing(5)
|
||||
.pinBottom(6)
|
||||
label.pinTrailing()
|
||||
|
||||
labelTopConstraint = label.topAnchor.constraint(equalTo: topAnchor, constant: 0)
|
||||
labelTopConstraint?.isActive = true
|
||||
|
||||
labelBottomConstraint = label.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0)
|
||||
labelBottomConstraint?.isActive = true
|
||||
|
||||
labelLeadingConstraint = label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0)
|
||||
labelLeadingConstraint?.isActive = true
|
||||
|
||||
labelMinWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 44.0)
|
||||
labelMinWidthConstraint?.isActive = true
|
||||
|
||||
labelWidthConstraint = label.widthAnchor.constraint(equalToConstant: 44.0)
|
||||
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tabItemTapped))
|
||||
@ -277,6 +295,12 @@ public class TabItem: View {
|
||||
label.text = text
|
||||
label.textStyle = size.textStyle
|
||||
label.textColor = textColorConfiguration.getColor(self)
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
public override func setNeedsLayout() {
|
||||
super.setNeedsLayout()
|
||||
|
||||
if let width {
|
||||
labelMinWidthConstraint?.isActive = false
|
||||
labelWidthConstraint?.constant = width
|
||||
@ -286,23 +310,32 @@ public class TabItem: View {
|
||||
labelMinWidthConstraint?.isActive = true
|
||||
}
|
||||
|
||||
var leadingSpace: CGFloat
|
||||
if orientation == .horizontal {
|
||||
leadingSpace = 0
|
||||
} else {
|
||||
leadingSpace = size == .medium ? VDSLayout.Spacing.space4X.value : VDSLayout.Spacing.space6X.value
|
||||
}
|
||||
labelLeadingConstraint?.constant = leadingSpace
|
||||
|
||||
var otherSpace: CGFloat
|
||||
if orientation == .horizontal {
|
||||
otherSpace = size == .medium ? VDSLayout.Spacing.space3X.value : VDSLayout.Spacing.space4X.value
|
||||
} else {
|
||||
otherSpace = VDSLayout.Spacing.space2X.value
|
||||
}
|
||||
labelTopConstraint?.constant = otherSpace
|
||||
labelBottomConstraint?.constant = -otherSpace
|
||||
|
||||
if selected {
|
||||
var indicatorPosition: UIRectEdge = .top
|
||||
if orientation == .vertical {
|
||||
indicatorPosition = .left
|
||||
} else {
|
||||
if indicatorPosition == .top {
|
||||
indicatorPosition = .top
|
||||
} else {
|
||||
indicatorPosition = .bottom
|
||||
}
|
||||
var indicator: UIRectEdge = .left
|
||||
if orientation == .horizontal {
|
||||
indicator = indicatorPosition.value
|
||||
}
|
||||
addBorder(side: indicatorPosition, width: indicatorWidth, color: indicatorColorConfiguration.getColor(self))
|
||||
addBorder(side: indicator, width: indicatorWidth, color: indicatorColorConfiguration.getColor(self))
|
||||
} else {
|
||||
removeBorders()
|
||||
}
|
||||
|
||||
setNeedsDisplay()
|
||||
}
|
||||
|
||||
// public override func draw(_ rect: CGRect) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user