diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift index e5233ad8..a99d820f 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift @@ -73,6 +73,18 @@ import Foundation public func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { Button.performButtonAction(with: model.tabs[item.tag].action, button: item, delegateObject: delegateObject, additionalData: nil) } + + // MARK: - TabBarProtocol + public func highlightTab(at index: Int) { + guard let newSelectedItem = items?[model.selectedTab] else { return } + selectedItem = newSelectedItem + } + + public func selectTab(at index: Int) { + guard let newSelectedItem = items?[model.selectedTab] else { return } + selectedItem = newSelectedItem + tabBar(self, didSelect: newSelectedItem) + } } extension UITabBarItem: MFButtonProtocol { diff --git a/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift b/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift index fc172d0d..1bf79795 100644 --- a/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/TabBarProtocol.swift @@ -9,5 +9,9 @@ import Foundation @objc public protocol TabBarProtocol { + /// Should visually select the given tab index. + @objc func highlightTab(at index: Int) + /// Should select the tab index. As if the user selected it. + @objc func selectTab(at index: Int) } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 6ec63c24..92f26569 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -8,7 +8,7 @@ import UIKit -@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate { +@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate { @objc public var pageType: String? @objc public var loadObject: MVMCoreLoadObject? public var pageModel: MVMControllerModelProtocol? @@ -371,6 +371,27 @@ import UIKit MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self) } + // MARK: - MVMCoreLoadDelegateProtocol + // TODO: Move this function out of here after breaking down load operation into smaller tasks and remove protocol from base. + open func loadFinished(_ loadObject: MVMCoreLoadObject?, loadedViewController: (UIViewController & MVMCoreViewControllerProtocol)?, error: MVMCoreErrorObject?) { + + MVMCoreUILoggingHandler.log(withDelegateLoadFinished: loadObject, loadedViewController: loadedViewController, error: error) + + // Open the support panel + if error == nil, + loadObject?.requestParameters?.openSupportPanel ?? (loadObject?.systemParametersJSON?.boolForKey(KeyOpenSupport) ?? false) == true { + MVMCoreUISession.sharedGlobal()?.splitViewController?.showRightPanel(animated: true) + } + + // Selects the tab if needed. + if let tab: Int = loadObject?.pageJSON?["tabBarIndex"] as? Int { + MVMCoreUISplitViewController.main()?.tabBar.highlightTab(at: tab) + } else if let tab: Int = loadObject?.requestParameters?.actionMap?["tabBarIndex"] as? Int, + error == nil { + MVMCoreUISplitViewController.main()?.tabBar.highlightTab(at: tab) + } + } + // MARK: - MVMCoreActionDelegateProtocol open func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) { formValidator?.addFormParams(requestParameters: requestParameters)