diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index 41f70d4a..0b6b8fac 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -83,8 +83,11 @@ open class Tabs: View { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - /// A callback when the selectedIndex changes. Passes parameters (event, tabIndex). - open var onTabChange: ((Int) -> Void)? + /// A callback when the selectedIndex changes. Passes parameters (tabIndex). + open var onTabDidSelect: ((Int) -> Void)? + + /// A callback when the Tab determine if a item should be selected. + open var onTabShouldSelect:((Int) -> Bool)? /// Determines the layout of the Tabs, defaults to horizontal open var orientation: Orientation = .horizontal { didSet { if oldValue != orientation { setNeedsUpdate() } } } @@ -237,9 +240,11 @@ open class Tabs: View { tabStackView.addArrangedSubview(tabItem) tabItem.onClick = { [weak self] tab in guard let self else { return } - model.onClick?(tab.index) - self.selectedIndex = tab.index - self.onTabChange?(tab.index) + if self.onTabShouldSelect?(tab.index) ?? true { + model.onClick?(tab.index) + self.selectedIndex = tab.index + self.onTabDidSelect?(tab.index) + } } } setNeedsUpdate() diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 13401e99..d44b877f 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -164,7 +164,7 @@ open class TabsContainer: View { stackView.axis = orientation == .horizontal ? .vertical : .horizontal stackView.spacing = space - tabMenu.onTabChange = { [weak self] index in + tabMenu.onTabDidSelect = { [weak self] index in guard let self else { return } self.tabClicked(index: index) }