From a18d2e2e000a76d735164e0e6d5f7a890713889f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 25 May 2023 13:08:46 -0500 Subject: [PATCH] refactored names for Tabs and related classes Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tab.swift | 3 ++- VDS/Components/Tabs/Tabs.swift | 23 ++++++++++++----------- VDS/Components/Tabs/TabsContainer.swift | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index f780d469..2b9ff6bc 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -11,7 +11,8 @@ import Combine extension Tabs { - open class TabItem: View { + @objc(VDSTab) + open class Tab: View { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index 111b9347..f886e655 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -9,6 +9,7 @@ import Foundation import UIKit import VDSColorTokens +@objc(VDSTabs) open class Tabs: View { //-------------------------------------------------- @@ -95,7 +96,7 @@ open class Tabs: View { open var tabSpacing: CGFloat { tabStackView.spacing } - open var tabItems: [TabItem] = [] + open var tabViews: [Tab] = [] //-------------------------------------------------- // MARK: - Private Properties @@ -154,24 +155,24 @@ open class Tabs: View { private func updateTabItems(with models: [TabModel]) { // Clear existing tab items - for tabItem in tabItems { + for tabItem in tabViews { tabItem.removeFromSuperview() } - tabItems.removeAll() + tabViews.removeAll() // Create new tab items from the models for model in models { - let tabItem = TabItem() + let tabItem = Tab() tabItem.text = model.text tabItem.onClick = model.onClick tabItem.width = model.width - tabItems.append(tabItem) + tabViews.append(tabItem) tabStackView.addArrangedSubview(tabItem) tabItem .publisher(for: UITapGestureRecognizer()) .sink { [weak self] gesture in - guard let self, let tabItem = gesture.view as? TabItem else { return } - if let selectedIndex = tabItems.firstIndex(of: tabItem) { + guard let self, let tabItem = gesture.view as? Tab else { return } + if let selectedIndex = tabViews.firstIndex(of: tabItem) { self.selectedIndex = selectedIndex self.onTabChange?(selectedIndex) } @@ -182,8 +183,8 @@ open class Tabs: View { } private func scrollToSelectedIndex(animated: Bool) { - if orientation == .horizontal && self.overflow == .scroll, selectedIndex < tabItems.count { - let selectedTab = tabItems[selectedIndex] + if orientation == .horizontal && self.overflow == .scroll, selectedIndex < tabViews.count { + let selectedTab = tabViews[selectedIndex] scrollView.scrollRectToVisible(selectedTab.frame, animated: animated) } } @@ -203,7 +204,7 @@ open class Tabs: View { tabStackView.spacing = orientation == .horizontal ? VDSLayout.Spacing.space6X.value : VDSLayout.Spacing.space4X.value // Update tab appearance based on properties - for (index, tabItem) in tabItems.enumerated() { + for (index, tabItem) in tabViews.enumerated() { tabItem.selected = selectedIndex == index tabItem.index = index tabItem.minWidth = minWidth @@ -212,7 +213,7 @@ open class Tabs: View { tabItem.orientation = orientation tabItem.surface = surface tabItem.indicatorPosition = indicatorPosition - tabItem.accessibilityLabel = "\(tabItem.text) \(tabItem.selected ? "selected" : "unselected") \(index+1) of \(tabItems.count)" + tabItem.accessibilityLabel = "\(tabItem.text) \(tabItem.selected ? "selected" : "unselected") \(index+1) of \(tabViews.count)" } // Deactivate old constraint diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 623e5b73..ccb01c1c 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -8,6 +8,7 @@ import Foundation import UIKit +@objc(VDSTabsContainer) open class TabsContainer: View { //-------------------------------------------------- // MARK: - Enums