Navigation item improvements
This commit is contained in:
parent
13fc3adf09
commit
b49b45660c
@ -94,6 +94,14 @@ import UIKit
|
|||||||
try parsePageJSON()
|
try parsePageJSON()
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
self.handleNewDataAndUpdateUI()
|
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 {
|
} catch {
|
||||||
if let coreError = MVMCoreErrorObject.createErrorObject(for: error, location: "updateJSON for pageType: \(String(describing: pageType))") {
|
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,
|
/// Processes any new data. Called after the page is loaded the first time and on response updates for this page,
|
||||||
open func handleNewData() {
|
open func handleNewData() {
|
||||||
// Convert legacy to navigation model.
|
// TODO: remove legacy. Temporary, convert legacy to navigation model.
|
||||||
if pageModel?.navigationItem == nil {
|
var navigationModel = pageModel?.navigationItem ?? NavigationItemModel()
|
||||||
let navigationModel = NavigationItemModel()
|
navigationModel.title = pageModel?.screenHeading
|
||||||
if navigationModel.title == nil {
|
navigationModel.showLeftPanelButton = isMasterInitiallyAccessible()
|
||||||
navigationModel.title = pageModel?.screenHeading
|
navigationModel.showRightPanelButton = isSupportInitiallyAccessible()
|
||||||
}
|
if /*(self as? MVMCoreUITabBarPageControlViewController) != nil ||*/ manager != nil || loadObject?.requestParameters?.tabWasPressed ?? false == true {
|
||||||
if navigationModel.showLeftPanelButton == nil {
|
navigationModel.line = LineModel(type: .none)
|
||||||
navigationModel.showLeftPanelButton = isMasterInitiallyAccessible()
|
|
||||||
}
|
|
||||||
if navigationModel.showRightPanelButton == nil {
|
|
||||||
navigationModel.showRightPanelButton = isSupportInitiallyAccessible()
|
|
||||||
}
|
|
||||||
pageModel?.navigationItem = navigationModel
|
|
||||||
}
|
}
|
||||||
|
pageModel?.navigationItem = navigationModel
|
||||||
if self.formValidator == nil {
|
if self.formValidator == nil {
|
||||||
let rules = pageModel?.formRules
|
let rules = pageModel?.formRules
|
||||||
self.formValidator = FormValidator(rules)
|
self.formValidator = FormValidator(rules)
|
||||||
@ -183,30 +186,12 @@ import UIKit
|
|||||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.parent?.setNeedsStatusBarAppearanceUpdate()
|
MVMCoreUISession.sharedGlobal()?.splitViewController?.parent?.setNeedsStatusBarAppearanceUpdate()
|
||||||
return
|
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,
|
if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
|
||||||
MVMCoreUISplitViewController.main()?.getCurrentVisibleController() == self {
|
navigationController.topViewController == self {
|
||||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.setupPanels()
|
MVMCoreUISession.sharedGlobal()?.splitViewController?.setupPanels()
|
||||||
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton ?? false, for: self)
|
showBottomProgressBar()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eventually will be moved to server
|
// Eventually will be moved to server
|
||||||
|
|||||||
@ -39,4 +39,34 @@ import UIKit
|
|||||||
MVMCoreUISession.sharedGlobal()?.setup(asStandardLoadViewDelegate: navigationController)
|
MVMCoreUISession.sharedGlobal()?.setup(asStandardLoadViewDelegate: navigationController)
|
||||||
return 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 backgroundColor: Color? { get set }
|
||||||
var transparent: Bool { get set }
|
var transparent: Bool { get set }
|
||||||
var tintColor: Color { 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 showLeftPanelButton: Bool? { get set }
|
||||||
var showRightPanelButton: Bool? { get set }
|
var showRightPanelButton: Bool? { get set }
|
||||||
var additionalLeftItems: [NavigationItemButtonModel]? { get set }
|
var additionalLeftItems: [NavigationItemButtonModel]? { get set }
|
||||||
@ -60,7 +61,8 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
|||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var transparent: Bool
|
public var transparent: Bool
|
||||||
public var tintColor: Color
|
public var tintColor: Color
|
||||||
public var systemBackButton: Bool?
|
public var line: LineModel?
|
||||||
|
public var systemBackButton = false
|
||||||
public var showLeftPanelButton: Bool?
|
public var showLeftPanelButton: Bool?
|
||||||
public var showRightPanelButton: Bool?
|
public var showRightPanelButton: Bool?
|
||||||
public var additionalLeftItems: [NavigationItemButtonModel]?
|
public var additionalLeftItems: [NavigationItemButtonModel]?
|
||||||
@ -71,6 +73,7 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
|||||||
transparent = false
|
transparent = false
|
||||||
backgroundColor = Color(uiColor: .white)
|
backgroundColor = Color(uiColor: .white)
|
||||||
tintColor = Color(uiColor: .black)
|
tintColor = Color(uiColor: .black)
|
||||||
|
line = LineModel(type: .standard)
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -80,6 +83,7 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
|||||||
case backgroundColor
|
case backgroundColor
|
||||||
case transparent
|
case transparent
|
||||||
case tintColor
|
case tintColor
|
||||||
|
case line
|
||||||
case systemBackButton
|
case systemBackButton
|
||||||
case showLeftPanelButton
|
case showLeftPanelButton
|
||||||
case showRightPanelButton
|
case showRightPanelButton
|
||||||
@ -95,6 +99,7 @@ public class NavigationItemModel: NavigationItemModelProtocol {
|
|||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) ?? Color(uiColor: .white)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) ?? Color(uiColor: .white)
|
||||||
transparent = try typeContainer.decodeIfPresent(Bool.self, forKey: .transparent) ?? false
|
transparent = try typeContainer.decodeIfPresent(Bool.self, forKey: .transparent) ?? false
|
||||||
tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor) ?? Color(uiColor: .black)
|
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
|
systemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .systemBackButton) ?? false
|
||||||
showLeftPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showLeftPanelButton)
|
showLeftPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showLeftPanelButton)
|
||||||
showRightPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showRightPanelButton)
|
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(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encode(transparent, forKey: .transparent)
|
try container.encode(transparent, forKey: .transparent)
|
||||||
try container.encode(tintColor, forKey: .tintColor)
|
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(showLeftPanelButton, forKey: .showLeftPanelButton)
|
||||||
try container.encode(showRightPanelButton, forKey: .showRightPanelButton)
|
try container.encode(showRightPanelButton, forKey: .showRightPanelButton)
|
||||||
try container.encodeIfPresent(additionalLeftItems, forKey: .additionalLeftItems)
|
try container.encodeIfPresent(additionalLeftItems, forKey: .additionalLeftItems)
|
||||||
|
|||||||
@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
// Returns the margins for a view.
|
// Returns the margins for a view.
|
||||||
+ (UIEdgeInsets)getMarginsForView:(nullable UIView *)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
|
#pragma mark - Setters
|
||||||
|
|
||||||
+ (void)setMarginsForView:(nullable UIView *)view leading:(CGFloat)leading top:(CGFloat)top trailing:(CGFloat)trailing bottom:(CGFloat)bottom;
|
+ (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 "MVMCoreUIConstants.h"
|
||||||
#import "MVMCoreUISession.h"
|
#import "MVMCoreUISession.h"
|
||||||
#import "MVMCoreUISplitViewController.h"
|
#import "MVMCoreUISplitViewController.h"
|
||||||
|
#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||||
@import MVMCore.MVMCoreNavigationHandler;
|
@import MVMCore.MVMCoreNavigationHandler;
|
||||||
@import MVMCore.MVMCoreGetterUtility;
|
@import MVMCore.MVMCoreGetterUtility;
|
||||||
|
|
||||||
@ -60,6 +61,26 @@
|
|||||||
return UIEdgeInsetsMake(view.directionalLayoutMargins.top, view.directionalLayoutMargins.leading, view.directionalLayoutMargins.bottom, view.directionalLayoutMargins.trailing);
|
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
|
#pragma mark - Setters
|
||||||
|
|
||||||
+ (void)setMarginsForView:(nullable UIView *)view leading:(CGFloat)leading top:(CGFloat)top trailing:(CGFloat)trailing bottom:(CGFloat)bottom {
|
+ (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