tab bar selection logic
This commit is contained in:
parent
8fcc9463c8
commit
d6761c055e
@ -73,6 +73,18 @@ import Foundation
|
|||||||
public func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
|
public func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
|
||||||
Button.performButtonAction(with: model.tabs[item.tag].action, button: item, delegateObject: delegateObject, additionalData: nil)
|
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 {
|
extension UITabBarItem: MFButtonProtocol {
|
||||||
|
|||||||
@ -9,5 +9,9 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objc public protocol TabBarProtocol {
|
@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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import UIKit
|
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 pageType: String?
|
||||||
@objc public var loadObject: MVMCoreLoadObject?
|
@objc public var loadObject: MVMCoreLoadObject?
|
||||||
public var pageModel: MVMControllerModelProtocol?
|
public var pageModel: MVMControllerModelProtocol?
|
||||||
@ -371,6 +371,27 @@ import UIKit
|
|||||||
MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self)
|
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
|
// MARK: - MVMCoreActionDelegateProtocol
|
||||||
open func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
|
open func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
|
||||||
formValidator?.addFormParams(requestParameters: requestParameters)
|
formValidator?.addFormParams(requestParameters: requestParameters)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user