cleaned up code in tabs
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c1c57084cb
commit
b0dbb2c2a7
@ -270,48 +270,37 @@ open class Tabs: View {
|
||||
}
|
||||
|
||||
//update the width based on rules
|
||||
updateWidth()
|
||||
updateContentView()
|
||||
|
||||
setNeedsLayout()
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
private func updateWidth() {
|
||||
private func updateContentView() {
|
||||
// Deactivate old constraint
|
||||
contentViewWidthConstraint?.isActive = false
|
||||
|
||||
// Apply width
|
||||
if orientation == .vertical {
|
||||
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: widthAnchor)
|
||||
// Apply overflow
|
||||
if orientation == .horizontal && overflow == .scroll && !fillContainer {
|
||||
let contentWidth = tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width
|
||||
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: contentWidth)
|
||||
scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.bounds.height)
|
||||
} else {
|
||||
// Apply overflow
|
||||
if overflow == .scroll && !fillContainer {
|
||||
let contentWidth = tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width
|
||||
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: contentWidth)
|
||||
|
||||
// Enable scrolling if necessary
|
||||
scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.bounds.height)
|
||||
} else {
|
||||
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: widthAnchor)
|
||||
}
|
||||
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: widthAnchor)
|
||||
scrollView.contentSize = bounds.size
|
||||
}
|
||||
|
||||
scrollView.isScrollEnabled = scrollIsEnabled
|
||||
|
||||
// Activate old constraint
|
||||
contentViewWidthConstraint?.isActive = true
|
||||
|
||||
scrollToSelectedIndex(animated: true)
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
//scrollView Contentsize
|
||||
if orientation == .horizontal && overflow == .scroll && !fillContainer {
|
||||
let contentWidth = tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width
|
||||
scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.bounds.height)
|
||||
} else {
|
||||
scrollView.contentSize = bounds.size
|
||||
}
|
||||
|
||||
|
||||
//borderLine
|
||||
if borderLine {
|
||||
var edge: UIRectEdge = .bottom
|
||||
@ -354,7 +343,5 @@ open class Tabs: View {
|
||||
} else {
|
||||
borderlineView.isHidden = true
|
||||
}
|
||||
|
||||
scrollToSelectedIndex(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user