tab bar selection logic

This commit is contained in:
Pfeil, Scott Robert 2020-06-01 11:45:47 -04:00
parent 8fcc9463c8
commit d6761c055e
3 changed files with 38 additions and 1 deletions

View File

@ -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 {

View File

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

View File

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