Navigation item improvements
This commit is contained in:
parent
13fc3adf09
commit
b49b45660c
@ -94,6 +94,14 @@ import UIKit
|
||||
try parsePageJSON()
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||
self.handleNewDataAndUpdateUI()
|
||||
// If the screen is showing, can update the navigation controller.
|
||||
if let navigationController = self.manager?.navigationController,
|
||||
self.manager!.getCurrentViewController() == self {
|
||||
self.set(navigationController: navigationController)
|
||||
} else if let navigationController = self.navigationController,
|
||||
self == MVMCoreUIUtility.getCurrentVisibleController() {
|
||||
self.set(navigationController: navigationController)
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
if let coreError = MVMCoreErrorObject.createErrorObject(for: error, location: "updateJSON for pageType: \(String(describing: pageType))") {
|
||||
@ -156,20 +164,15 @@ import UIKit
|
||||
|
||||
/// Processes any new data. Called after the page is loaded the first time and on response updates for this page,
|
||||
open func handleNewData() {
|
||||
// Convert legacy to navigation model.
|
||||
if pageModel?.navigationItem == nil {
|
||||
let navigationModel = NavigationItemModel()
|
||||
if navigationModel.title == nil {
|
||||
navigationModel.title = pageModel?.screenHeading
|
||||
}
|
||||
if navigationModel.showLeftPanelButton == nil {
|
||||
navigationModel.showLeftPanelButton = isMasterInitiallyAccessible()
|
||||
}
|
||||
if navigationModel.showRightPanelButton == nil {
|
||||
navigationModel.showRightPanelButton = isSupportInitiallyAccessible()
|
||||
}
|
||||
pageModel?.navigationItem = navigationModel
|
||||
// TODO: remove legacy. Temporary, convert legacy to navigation model.
|
||||
var navigationModel = pageModel?.navigationItem ?? NavigationItemModel()
|
||||
navigationModel.title = pageModel?.screenHeading
|
||||
navigationModel.showLeftPanelButton = isMasterInitiallyAccessible()
|
||||
navigationModel.showRightPanelButton = isSupportInitiallyAccessible()
|
||||
if /*(self as? MVMCoreUITabBarPageControlViewController) != nil ||*/ manager != nil || loadObject?.requestParameters?.tabWasPressed ?? false == true {
|
||||
navigationModel.line = LineModel(type: .none)
|
||||
}
|
||||
pageModel?.navigationItem = navigationModel
|
||||
if self.formValidator == nil {
|
||||
let rules = pageModel?.formRules
|
||||
self.formValidator = FormValidator(rules)
|
||||
@ -183,30 +186,12 @@ import UIKit
|
||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.parent?.setNeedsStatusBarAppearanceUpdate()
|
||||
return
|
||||
}
|
||||
navigationItem.title = navigationItemModel.title
|
||||
navigationItem.accessibilityLabel = navigationItemModel.title
|
||||
|
||||
navigationController.setNavigationBarHidden(navigationItemModel.hidden, animated: true)
|
||||
UIColor.setBackgroundColor(navigationItemModel.backgroundColor?.uiColor ?? .white, for: navigationController.navigationBar, isTransparent: navigationItemModel.transparent)
|
||||
|
||||
let tint = navigationItemModel.tintColor.uiColor
|
||||
navigationController.navigationBar.tintColor = tint
|
||||
|
||||
// Have the navigation title match the tint color
|
||||
navigationController.navigationBar.titleTextAttributes?.updateValue(tint, forKey: .foregroundColor)
|
||||
|
||||
// Update icons if main navigation controller.
|
||||
if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
|
||||
MVMCoreUISplitViewController.main()?.getCurrentVisibleController() == self {
|
||||
navigationController.topViewController == self {
|
||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.setupPanels()
|
||||
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton ?? false, for: self)
|
||||
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton ?? false, for: self)
|
||||
showBottomProgressBar()
|
||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint)
|
||||
|
||||
// Update separator.
|
||||
MVMCoreUISession.sharedGlobal()?.navigationController?.separatorView?.isHidden = /*self is MVMCoreUITabBarPageControlViewController ||*/ manager != nil || loadObject?.requestParameters?.tabWasPressed ?? false == true
|
||||
showBottomProgressBar()
|
||||
}
|
||||
NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: self)
|
||||
}
|
||||
|
||||
// Eventually will be moved to server
|
||||
|
||||
@ -39,4 +39,34 @@ import UIKit
|
||||
MVMCoreUISession.sharedGlobal()?.setup(asStandardLoadViewDelegate: navigationController)
|
||||
return navigationController
|
||||
}
|
||||
|
||||
public static func set(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: (UIViewController & MVMCoreViewControllerProtocol)) {
|
||||
viewController.navigationItem.title = navigationItemModel.title
|
||||
viewController.navigationItem.accessibilityLabel = navigationItemModel.title
|
||||
viewController.navigationItem.hidesBackButton = !navigationItemModel.systemBackButton
|
||||
|
||||
navigationController.setNavigationBarHidden(navigationItemModel.hidden, animated: true)
|
||||
UIColor.setBackgroundColor(navigationItemModel.backgroundColor?.uiColor ?? .white, for: navigationController.navigationBar, isTransparent: navigationItemModel.transparent)
|
||||
|
||||
let tint = navigationItemModel.tintColor.uiColor
|
||||
navigationController.navigationBar.tintColor = tint
|
||||
|
||||
// Have the navigation title match the tint color
|
||||
navigationController.navigationBar.titleTextAttributes?.updateValue(tint, forKey: .foregroundColor)
|
||||
|
||||
// Update icons if main navigation controller.
|
||||
if navigationController == MVMCoreUISession.sharedGlobal()?.navigationController,
|
||||
navigationController.topViewController == viewController {
|
||||
// Update line.
|
||||
MVMCoreUISession.sharedGlobal()?.navigationController?.separatorView?.set(with: navigationItemModel.line ?? LineModel(type: .standard), viewController.delegateObject?() as? MVMCoreUIDelegateObject, nil)
|
||||
}
|
||||
|
||||
if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
|
||||
navigationController.topViewController == viewController {
|
||||
// Update Panels
|
||||
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton ?? false, for: viewController)
|
||||
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton ?? false, for: viewController)
|
||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,8 @@ public protocol NavigationItemModelProtocol: MoleculeModelProtocol {
|
||||
var backgroundColor: Color? { get set }
|
||||
var transparent: Bool { get set }
|
||||
var tintColor: Color { get set }
|
||||
var systemBackButton: Bool? { get set }
|
||||
var line: LineModel? { get set }
|
||||
var systemBackButton: Bool { get set }
|
||||
var showLeftPanelButton: Bool? { get set }
|
||||
var showRightPanelButton: Bool? { get set }
|
||||
var additionalLeftItems: [NavigationItemButtonModel]? { get set }
|
||||
@ -60,7 +61,8 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
||||
public var backgroundColor: Color?
|
||||
public var transparent: Bool
|
||||
public var tintColor: Color
|
||||
public var systemBackButton: Bool?
|
||||
public var line: LineModel?
|
||||
public var systemBackButton = false
|
||||
public var showLeftPanelButton: Bool?
|
||||
public var showRightPanelButton: Bool?
|
||||
public var additionalLeftItems: [NavigationItemButtonModel]?
|
||||
@ -71,6 +73,7 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
||||
transparent = false
|
||||
backgroundColor = Color(uiColor: .white)
|
||||
tintColor = Color(uiColor: .black)
|
||||
line = LineModel(type: .standard)
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
@ -80,6 +83,7 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
||||
case backgroundColor
|
||||
case transparent
|
||||
case tintColor
|
||||
case line
|
||||
case systemBackButton
|
||||
case showLeftPanelButton
|
||||
case showRightPanelButton
|
||||
@ -95,6 +99,7 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) ?? Color(uiColor: .white)
|
||||
transparent = try typeContainer.decodeIfPresent(Bool.self, forKey: .transparent) ?? false
|
||||
tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor) ?? Color(uiColor: .black)
|
||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
||||
systemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .systemBackButton) ?? false
|
||||
showLeftPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showLeftPanelButton)
|
||||
showRightPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showRightPanelButton)
|
||||
@ -110,7 +115,8 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
||||
try container.encode(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(transparent, forKey: .transparent)
|
||||
try container.encode(tintColor, forKey: .tintColor)
|
||||
try container.encodeIfPresent(systemBackButton, forKey: .systemBackButton)
|
||||
try container.encodeIfPresent(line, forKey: .line)
|
||||
try container.encode(systemBackButton, forKey: .systemBackButton)
|
||||
try container.encode(showLeftPanelButton, forKey: .showLeftPanelButton)
|
||||
try container.encode(showRightPanelButton, forKey: .showRightPanelButton)
|
||||
try container.encodeIfPresent(additionalLeftItems, forKey: .additionalLeftItems)
|
||||
|
||||
@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
// Returns the margins for a view.
|
||||
+ (UIEdgeInsets)getMarginsForView:(nullable UIView *)view;
|
||||
|
||||
/// Gets the current visible view controller. Checks presented view controllers first, and then it checks on the NavigationController in the session object.
|
||||
+ (UIViewController *)getCurrentVisibleController;
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
+ (void)setMarginsForView:(nullable UIView *)view leading:(CGFloat)leading top:(CGFloat)top trailing:(CGFloat)trailing bottom:(CGFloat)bottom;
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#import "MVMCoreUIConstants.h"
|
||||
#import "MVMCoreUISession.h"
|
||||
#import "MVMCoreUISplitViewController.h"
|
||||
#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||
@import MVMCore.MVMCoreNavigationHandler;
|
||||
@import MVMCore.MVMCoreGetterUtility;
|
||||
|
||||
@ -60,6 +61,26 @@
|
||||
return UIEdgeInsetsMake(view.directionalLayoutMargins.top, view.directionalLayoutMargins.leading, view.directionalLayoutMargins.bottom, view.directionalLayoutMargins.trailing);
|
||||
}
|
||||
|
||||
+ (UIViewController *)getCurrentVisibleController {
|
||||
UIViewController *baseViewController = [MVMCoreNavigationHandler sharedNavigationHandler].viewControllerToPresentOn ?: [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
UIViewController *viewController = nil;
|
||||
while (baseViewController.presentedViewController && !baseViewController.presentedViewController.isBeingDismissed) {
|
||||
viewController = baseViewController.presentedViewController;
|
||||
baseViewController = viewController;
|
||||
}
|
||||
if ([viewController isKindOfClass:[UINavigationController class]]) {
|
||||
viewController = ((UINavigationController *)viewController).topViewController;
|
||||
}
|
||||
// if it is not presented viewcontroller, existing BAU logic will be working
|
||||
if (!viewController) {
|
||||
viewController = [MVMCoreUISession sharedGlobal].navigationController.topViewController;
|
||||
if ([viewController conformsToProtocol:@protocol(MVMCoreViewManagerProtocol)]) {
|
||||
viewController = [viewController performSelector:@selector(getCurrentViewController)];
|
||||
}
|
||||
}
|
||||
return viewController;
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
+ (void)setMarginsForView:(nullable UIView *)view leading:(CGFloat)leading top:(CGFloat)top trailing:(CGFloat)trailing bottom:(CGFloat)bottom {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user