From 1986eceae208e45ad93caaf85a024bfb827aa463 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 17:07:28 -0500 Subject: [PATCH] updated tabs for logic on numberoflines Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tabs.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index bc14d54f..cd138d60 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -144,6 +144,10 @@ open class Tabs: View { orientation == .horizontal && fillContainer ? .center : .left } + private var applyOverflow: Bool { + orientation == .horizontal && overflow == .scroll && !fillContainer + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -258,7 +262,9 @@ open class Tabs: View { /// Updates the Tab individual views from local properties. private func updateTabs() { + let numberOfLines = applyOverflow ? 1 : 0 for (index, tabItem) in tabViews.enumerated() { + tabItem.label.numberOfLines = numberOfLines tabItem.size = size tabItem.isSelected = selectedIndex == index tabItem.index = index @@ -277,10 +283,10 @@ open class Tabs: View { contentViewWidthConstraint?.isActive = false // Apply overflow - if orientation == .horizontal && overflow == .scroll && !fillContainer { - let contentWidth = tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width + if applyOverflow { contentViewWidthConstraint = nil - scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.bounds.height) + scrollView.contentSize = CGSize(width: tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width, + height: scrollView.bounds.height) } else { contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor) scrollView.contentSize = bounds.size @@ -294,6 +300,11 @@ open class Tabs: View { scrollToSelectedIndex(animated: true) } + open override func layoutSubviews() { + super.layoutSubviews() + updateContentView() + } + //update layout for borderline private func updateBorderline() { //borderLine