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
|
//update the width based on rules
|
||||||
updateWidth()
|
updateContentView()
|
||||||
|
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateWidth() {
|
private func updateContentView() {
|
||||||
// Deactivate old constraint
|
// Deactivate old constraint
|
||||||
contentViewWidthConstraint?.isActive = false
|
contentViewWidthConstraint?.isActive = false
|
||||||
|
|
||||||
// Apply width
|
// Apply overflow
|
||||||
if orientation == .vertical {
|
if orientation == .horizontal && overflow == .scroll && !fillContainer {
|
||||||
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: widthAnchor)
|
let contentWidth = tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width
|
||||||
|
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: contentWidth)
|
||||||
|
scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.bounds.height)
|
||||||
} else {
|
} else {
|
||||||
// Apply overflow
|
contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: widthAnchor)
|
||||||
if overflow == .scroll && !fillContainer {
|
scrollView.contentSize = bounds.size
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollView.isScrollEnabled = scrollIsEnabled
|
scrollView.isScrollEnabled = scrollIsEnabled
|
||||||
|
|
||||||
// Activate old constraint
|
// Activate old constraint
|
||||||
contentViewWidthConstraint?.isActive = true
|
contentViewWidthConstraint?.isActive = true
|
||||||
|
|
||||||
|
scrollToSelectedIndex(animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func layoutSubviews() {
|
open override func layoutSubviews() {
|
||||||
super.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
|
//borderLine
|
||||||
if borderLine {
|
if borderLine {
|
||||||
var edge: UIRectEdge = .bottom
|
var edge: UIRectEdge = .bottom
|
||||||
@ -354,7 +343,5 @@ open class Tabs: View {
|
|||||||
} else {
|
} else {
|
||||||
borderlineView.isHidden = true
|
borderlineView.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToSelectedIndex(animated: true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user