refactored names for Tabs and related classes

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-05-25 13:08:46 -05:00
parent 2f7315db86
commit a18d2e2e00
3 changed files with 15 additions and 12 deletions

View File

@ -11,7 +11,8 @@ import Combine
extension Tabs { extension Tabs {
open class TabItem: View { @objc(VDSTab)
open class Tab: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------

View File

@ -9,6 +9,7 @@ import Foundation
import UIKit import UIKit
import VDSColorTokens import VDSColorTokens
@objc(VDSTabs)
open class Tabs: View { open class Tabs: View {
//-------------------------------------------------- //--------------------------------------------------
@ -95,7 +96,7 @@ open class Tabs: View {
open var tabSpacing: CGFloat { tabStackView.spacing } open var tabSpacing: CGFloat { tabStackView.spacing }
open var tabItems: [TabItem] = [] open var tabViews: [Tab] = []
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
@ -154,24 +155,24 @@ open class Tabs: View {
private func updateTabItems(with models: [TabModel]) { private func updateTabItems(with models: [TabModel]) {
// Clear existing tab items // Clear existing tab items
for tabItem in tabItems { for tabItem in tabViews {
tabItem.removeFromSuperview() tabItem.removeFromSuperview()
} }
tabItems.removeAll() tabViews.removeAll()
// Create new tab items from the models // Create new tab items from the models
for model in models { for model in models {
let tabItem = TabItem() let tabItem = Tab()
tabItem.text = model.text tabItem.text = model.text
tabItem.onClick = model.onClick tabItem.onClick = model.onClick
tabItem.width = model.width tabItem.width = model.width
tabItems.append(tabItem) tabViews.append(tabItem)
tabStackView.addArrangedSubview(tabItem) tabStackView.addArrangedSubview(tabItem)
tabItem tabItem
.publisher(for: UITapGestureRecognizer()) .publisher(for: UITapGestureRecognizer())
.sink { [weak self] gesture in .sink { [weak self] gesture in
guard let self, let tabItem = gesture.view as? TabItem else { return } guard let self, let tabItem = gesture.view as? Tab else { return }
if let selectedIndex = tabItems.firstIndex(of: tabItem) { if let selectedIndex = tabViews.firstIndex(of: tabItem) {
self.selectedIndex = selectedIndex self.selectedIndex = selectedIndex
self.onTabChange?(selectedIndex) self.onTabChange?(selectedIndex)
} }
@ -182,8 +183,8 @@ open class Tabs: View {
} }
private func scrollToSelectedIndex(animated: Bool) { private func scrollToSelectedIndex(animated: Bool) {
if orientation == .horizontal && self.overflow == .scroll, selectedIndex < tabItems.count { if orientation == .horizontal && self.overflow == .scroll, selectedIndex < tabViews.count {
let selectedTab = tabItems[selectedIndex] let selectedTab = tabViews[selectedIndex]
scrollView.scrollRectToVisible(selectedTab.frame, animated: animated) 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 tabStackView.spacing = orientation == .horizontal ? VDSLayout.Spacing.space6X.value : VDSLayout.Spacing.space4X.value
// Update tab appearance based on properties // Update tab appearance based on properties
for (index, tabItem) in tabItems.enumerated() { for (index, tabItem) in tabViews.enumerated() {
tabItem.selected = selectedIndex == index tabItem.selected = selectedIndex == index
tabItem.index = index tabItem.index = index
tabItem.minWidth = minWidth tabItem.minWidth = minWidth
@ -212,7 +213,7 @@ open class Tabs: View {
tabItem.orientation = orientation tabItem.orientation = orientation
tabItem.surface = surface tabItem.surface = surface
tabItem.indicatorPosition = indicatorPosition 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 // Deactivate old constraint

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import UIKit import UIKit
@objc(VDSTabsContainer)
open class TabsContainer: View { open class TabsContainer: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Enums // MARK: - Enums