From 1965920710b4bdc9e8d0f52e45fc064b0fa468a3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 19 Jan 2024 14:50:30 -0600 Subject: [PATCH] fixed delegate bug Signed-off-by: Matt Bruce --- .../HorizontalCombinationViews/Tabs.swift | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift index 178e9c3d..dae0e818 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift @@ -25,7 +25,21 @@ import VDS open var additionalData: [AnyHashable : Any]? //delegate - weak public var delegate: TabsDelegate? + weak public var delegate: TabsDelegate? { + didSet { + if let delegate { + onTabDidSelect = { [weak self] index in + guard let self else { return } + delegate.didSelectItem(.init(row: index, section: 0), tabs: self) + } + + onTabShouldSelect = { [weak self] index in + guard let self else { return true } + return delegate.shouldSelectItem(.init(row: index, section: 0), tabs: self) + } + } + } + } //------------------------------------------------- // MARK: - Layout Views @@ -55,17 +69,5 @@ import VDS selectedIndex = viewModel.selectedIndex surface = viewModel.style ?? .light tabModels = viewModel.tabs.compactMap { TabModel(text: $0.label.text) } - - if let delegate { - onTabDidSelect = { [weak self] index in - guard let self else { return } - delegate.didSelectItem(.init(row: index, section: 0), tabs: self) - } - - onTabShouldSelect = { [weak self] index in - guard let self else { return true } - return delegate.shouldSelectItem(.init(row: index, section: 0), tabs: self) - } - } } }