updated tabs interface for shouldSelect and didSelect
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
25759b39e5
commit
57db5768ef
@ -83,8 +83,11 @@ open class Tabs: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// A callback when the selectedIndex changes. Passes parameters (event, tabIndex).
|
/// A callback when the selectedIndex changes. Passes parameters (tabIndex).
|
||||||
open var onTabChange: ((Int) -> Void)?
|
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
|
/// Determines the layout of the Tabs, defaults to horizontal
|
||||||
open var orientation: Orientation = .horizontal { didSet { if oldValue != orientation { setNeedsUpdate() } } }
|
open var orientation: Orientation = .horizontal { didSet { if oldValue != orientation { setNeedsUpdate() } } }
|
||||||
@ -237,9 +240,11 @@ open class Tabs: View {
|
|||||||
tabStackView.addArrangedSubview(tabItem)
|
tabStackView.addArrangedSubview(tabItem)
|
||||||
tabItem.onClick = { [weak self] tab in
|
tabItem.onClick = { [weak self] tab in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
model.onClick?(tab.index)
|
if self.onTabShouldSelect?(tab.index) ?? true {
|
||||||
self.selectedIndex = tab.index
|
model.onClick?(tab.index)
|
||||||
self.onTabChange?(tab.index)
|
self.selectedIndex = tab.index
|
||||||
|
self.onTabDidSelect?(tab.index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
|
|||||||
@ -164,7 +164,7 @@ open class TabsContainer: View {
|
|||||||
stackView.axis = orientation == .horizontal ? .vertical : .horizontal
|
stackView.axis = orientation == .horizontal ? .vertical : .horizontal
|
||||||
stackView.spacing = space
|
stackView.spacing = space
|
||||||
|
|
||||||
tabMenu.onTabChange = { [weak self] index in
|
tabMenu.onTabDidSelect = { [weak self] index in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.tabClicked(index: index)
|
self.tabClicked(index: index)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user