Merge branch 'feature/tab_bar_scoping' into 'feature/develop_mvp_3'

Feature/tab bar scoping

See merge request BPHV_MIPS/mvm_core_ui!848
This commit is contained in:
Bruce, Matt R 2022-05-05 16:54:07 +00:00
commit 7f47177c7d
4 changed files with 72 additions and 46 deletions

View File

@ -43,9 +43,6 @@ import UIKit
public var selectedField: UIView?
// Stores the previous tab bar index.
public var tabBarIndex: Int?
/// Checks if the screen width has changed
open func screenSizeChanged() -> Bool {
!MVMCoreGetterUtility.cgfequalwiththreshold(previousScreenSize.width, view.bounds.size.width, 0.1)
@ -244,12 +241,6 @@ import UIKit
view.backgroundColor = backgroundColor.uiColor
}
// Update splitview properties
if self == MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() {
MVMCoreUISplitViewController.main()?.setBottomProgressBarProgress(bottomProgress() ?? 0)
updateTabBar()
}
// Notify the manager of new data
manager?.newDataReceived?(in: self)
}
@ -267,34 +258,6 @@ import UIKit
return model?.navigationBar
}
//--------------------------------------------------
// MARK: - TabBar
//--------------------------------------------------
open func updateTabBar() {
guard MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() == self else { return }
MVMCoreUISplitViewController.main()?.tabBar?.delegateObject = delegateObjectIVar
if let index = (model as? TabPageModelProtocol)?.tabBarIndex {
MVMCoreUISplitViewController.main()?.tabBar?.highlightTab(at: index)
} else if let index = loadObject?.requestParameters?.actionMap?["tabBarIndex"] as? Int {
MVMCoreUISplitViewController.main()?.tabBar?.highlightTab(at: index)
} else if let index = self.tabBarIndex {
MVMCoreUISplitViewController.main()?.tabBar?.highlightTab(at: index)
} else if let index = MVMCoreUISplitViewController.main()?.tabBar?.currentTabIndex() {
// Store current tab index for cases like back button.
self.tabBarIndex = index
}
if let hidden = (model as? TabPageModelProtocol)?.tabBarHidden {
MVMCoreUISplitViewController.main()?.updateTabBarShowing(!hidden)
} else if let hidden = loadObject?.requestParameters?.actionMap?["tabBarHidden"] as? Bool {
MVMCoreUISplitViewController.main()?.updateTabBarShowing(!hidden)
} else {
MVMCoreUISplitViewController.main()?.updateTabBarShowing(true)
}
}
//--------------------------------------------------
// MARK: - View Lifecycle
//--------------------------------------------------
@ -349,12 +312,6 @@ import UIKit
}
open func pageShown() {
// Update split view properties if this is the current detail controller.
if self == MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() {
MVMCoreUISplitViewController.main()?.setBottomProgressBarProgress(bottomProgress() ?? 0)
updateTabBar()
}
// Track.
MVMCoreUISession.sharedGlobal()?.currentPageType = pageType
MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self)

View File

@ -12,6 +12,64 @@ import UIKit
// Navigation bar update functions
public extension MVMCoreUISplitViewController {
/// Updates the state for various controls (navigation, tab, progress) for the controller.
func updateState(with viewController: UIViewController) {
guard let navigationController = navigationController,
navigationController.isDisplayed(viewController: viewController) else { return }
updateNavigationBarFor(viewController: viewController)
updateProgressBar(for: viewController)
updateTabBar(for: viewController)
}
// MARK: - Progress Bar
/// Updates the progress bar based on the page json for the view controller.
func updateProgressBar(for viewController: UIViewController) {
guard let viewController = viewController as? MVMCoreViewControllerProtocol else { return }
var progress: Float = 0.0
if let progressString = viewController.loadObject??.pageJSON?.optionalStringForKey(KeyProgressPercent),
let floatValue = Float(progressString) {
progress = floatValue/100
}
setBottomProgressBarProgress(progress)
}
// MARK: - Tab Bar
/// Updates the tab bar based on the page json for the view controller.
func updateTabBar(for viewController: UIViewController) {
let mvmViewController = viewController as? MVMCoreViewControllerProtocol
tabBar?.delegateObject = mvmViewController?.delegateObject?() as? MVMCoreUIDelegateObject
let navigationIndex = (MVMCoreNavigationHandler.shared()?.getViewControllers(for: navigationController)?.count ?? 1) - 1
// Set the highlighted index. In terms of priority, Page > Action > Previous.
if let index = ((viewController as? PageProtocol)?.pageModel as? TabPageModelProtocol)?.tabBarIndex {
tabBar?.highlightTab(at: index)
} else if let index = mvmViewController?.loadObject??.requestParameters?.actionMap?["tabBarIndex"] as? Int {
tabBar?.highlightTab(at: index)
} else if navigationIndex < tabBarIndices.count {
let index = (tabBarIndices[navigationIndex] as! NSNumber).intValue
tabBar?.highlightTab(at: index)
}
// Store current tab index, so we can switch back when going back in hierarchy.
if tabBarIndices.count > 0 {
tabBarIndices.removeObjects(in: NSRange(location: navigationIndex, length: tabBarIndices.count - navigationIndex))
}
if let currentIndex = tabBar?.currentTabIndex() {
tabBarIndices.add(NSNumber(integerLiteral: currentIndex))
}
// Show/Hide. In terms of priority, Page > Action > Always Show.
if let hidden = ((viewController as? PageProtocol)?.pageModel as? TabPageModelProtocol)?.tabBarHidden {
updateTabBarShowing(!hidden)
} else if let hidden = mvmViewController?.loadObject??.requestParameters?.actionMap?["tabBarHidden"] as? Bool {
updateTabBarShowing(!hidden)
} else {
updateTabBarShowing(true)
}
}
// MARK: - Navigation Bar
/// Convenience function. Sets the navigation and split view properties for the view controller. Panel access is determined if view controller is a detail view protocol.
func setNavigationBar(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol) {
guard navigationController == self.navigationController,
@ -122,6 +180,7 @@ public extension MVMCoreUISplitViewController {
setStatusBarForCurrentViewController()
}
// MARK: - Status Bar
/// Returns the bar style for the background color. Light if on a dark background, otherwise default.
func getStatusBarStyle(for backgroundColor: UIColor?) -> UIStatusBarStyle {
var greyScale: CGFloat = 0
@ -155,10 +214,10 @@ extension MVMCoreUISplitViewController: MVMCoreViewManagerProtocol {
public func willDisplay(_ viewController: UIViewController) {
setupPanels()
updateNavigationBarFor(viewController: viewController)
updateState(with: viewController)
}
public func newDataReceived(in viewController: UIViewController) {
updateNavigationBarFor(viewController: viewController)
updateState(with: viewController)
}
}

View File

@ -55,6 +55,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
/// Reference to the tabbar.
@property (nullable, weak, nonatomic) UIView <TabBarProtocol>*tabBar;
/// Tab bar index history.
@property (nonnull, strong, nonatomic) NSMutableArray <NSNumber *>*tabBarIndices;
// Convenience getter
+ (nullable instancetype)mainSplitViewController;

View File

@ -93,13 +93,20 @@ CGFloat const PanelAnimationDuration = 0.2;
}
- (nullable instancetype)initWithLeftPanel:(nullable UIViewController <MVMCoreUIPanelProtocol> *)leftPanel rightPanel:(nullable UIViewController <MVMCoreUIPanelProtocol> *)rightPanel {
if (self = [super init]) {
if (self = [self init]) {
self.globalLeftPanel = leftPanel;
self.globalRightPanel = rightPanel;
}
return self;
}
- (nullable instancetype)init {
if (self = [super init]) {
self.tabBarIndices = [NSMutableArray array];
}
return self;
}
#pragma mark - Main Subclassables
- (MFNumberOfDrawers)numberOfDrawersShouldShow:(NSNumber *)forWidth {