From b0dbb2c2a777090db4caa6268906bfa56f1658a6 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Jun 2023 14:17:53 -0500 Subject: [PATCH] cleaned up code in tabs Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tabs.swift | 39 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index 15e17f4e..9ad1e19c 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -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) } }