updated tabs interface for shouldSelect and didSelect

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-12-12 15:23:54 -06:00
parent 25759b39e5
commit 57db5768ef
2 changed files with 11 additions and 6 deletions

View File

@ -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()

View File

@ -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)
}