navigation item button fixes

This commit is contained in:
Pfeil, Scott Robert 2020-05-18 21:10:50 -04:00
parent d293b93adc
commit cde8218e43
7 changed files with 139 additions and 24 deletions

View File

@ -269,9 +269,9 @@
D236E5B4241FEB1000C38625 /* ListTwoColumnPriceDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = D236E5B2241FEB1000C38625 /* ListTwoColumnPriceDescription.swift */; };
D236E5B5241FEB1000C38625 /* ListTwoColumnPriceDescriptionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D236E5B3241FEB1000C38625 /* ListTwoColumnPriceDescriptionModel.swift */; };
D236E5B7242007C500C38625 /* MVMControllerModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D236E5B6242007C500C38625 /* MVMControllerModelProtocol.swift */; };
D23EA7E82473654300D60C34 /* PanelNavigationItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23EA7E72473654300D60C34 /* PanelNavigationItemModelProtocol.swift */; };
D243859923A16B1800332775 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = D243859823A16B1800332775 /* Container.swift */; };
D2509ED12472ED9B001BFB9D /* NavigationItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2509ED02472ED9B001BFB9D /* NavigationItemModelProtocol.swift */; };
D2509ED32472EDC8001BFB9D /* PanelNavigationItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2509ED22472EDC8001BFB9D /* PanelNavigationItemModelProtocol.swift */; };
D2509ED62472EE2F001BFB9D /* NavigationItemButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2509ED52472EE2F001BFB9D /* NavigationItemButtonModel.swift */; };
D253BB8A24574CC5002DE544 /* StackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D260106423D0CEA700764D80 /* StackModel.swift */; };
D253BB9C245874F8002DE544 /* BGImageMolecule.swift in Sources */ = {isa = PBXBuildFile; fileRef = D253BB9B245874F8002DE544 /* BGImageMolecule.swift */; };
@ -296,6 +296,7 @@
D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01EB368A23609801006832FA /* MoleculeStackItemModel.swift */; };
D268C70E238C22D7007F2C1C /* DropDownFilterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */; };
D26C5A6B23F4A40D007AEECE /* ListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D26C5A6A23F4A40D007AEECE /* ListItemModel.swift */; };
D272F5F92473163100BD1A8F /* BarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D272F5F82473163100BD1A8F /* BarButtonItem.swift */; };
D274CA332236A78900B01B62 /* FooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274CA322236A78900B01B62 /* FooterView.swift */; };
D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2755D7A23689C7500485468 /* TableViewCell.swift */; };
D27CD40E2322EEAF00C1DC07 /* TabsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */; };
@ -689,9 +690,9 @@
D236E5B2241FEB1000C38625 /* ListTwoColumnPriceDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListTwoColumnPriceDescription.swift; sourceTree = "<group>"; };
D236E5B3241FEB1000C38625 /* ListTwoColumnPriceDescriptionModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListTwoColumnPriceDescriptionModel.swift; sourceTree = "<group>"; };
D236E5B6242007C500C38625 /* MVMControllerModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMControllerModelProtocol.swift; sourceTree = "<group>"; };
D23EA7E72473654300D60C34 /* PanelNavigationItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanelNavigationItemModelProtocol.swift; sourceTree = "<group>"; };
D243859823A16B1800332775 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = "<group>"; };
D2509ED02472ED9B001BFB9D /* NavigationItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationItemModelProtocol.swift; sourceTree = "<group>"; };
D2509ED22472EDC8001BFB9D /* PanelNavigationItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanelNavigationItemModelProtocol.swift; sourceTree = "<group>"; };
D2509ED52472EE2F001BFB9D /* NavigationItemButtonModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationItemButtonModel.swift; sourceTree = "<group>"; };
D253BB9B245874F8002DE544 /* BGImageMolecule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BGImageMolecule.swift; sourceTree = "<group>"; };
D253BB9D2458751F002DE544 /* BGImageMoleculeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BGImageMoleculeModel.swift; sourceTree = "<group>"; };
@ -715,6 +716,7 @@
D264FAAB2441009400D98315 /* RadioBoxCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioBoxCollectionViewCell.swift; sourceTree = "<group>"; };
D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropDownFilterTableViewCell.swift; sourceTree = "<group>"; };
D26C5A6A23F4A40D007AEECE /* ListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemModel.swift; sourceTree = "<group>"; };
D272F5F82473163100BD1A8F /* BarButtonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarButtonItem.swift; sourceTree = "<group>"; };
D274CA322236A78900B01B62 /* FooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterView.swift; sourceTree = "<group>"; };
D2755D7A23689C7500485468 /* TableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = "<group>"; };
D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsTableViewCell.swift; sourceTree = "<group>"; };
@ -871,7 +873,7 @@
D2E2A9A223E096B1000B42E6 /* DisableableModelProtocol.swift */,
D2092354244FA0FD0044AD09 /* ThreeLayerTemplateModelProtocol.swift */,
D2509ED02472ED9B001BFB9D /* NavigationItemModelProtocol.swift */,
D2509ED22472EDC8001BFB9D /* PanelNavigationItemModelProtocol.swift */,
D23EA7E72473654300D60C34 /* PanelNavigationItemModelProtocol.swift */,
);
path = ModelProtocols;
sourceTree = "<group>";
@ -1803,6 +1805,7 @@
D264FAA92440F97600D98315 /* CollectionView.swift */,
0A5D59C323AD488600EFD9E9 /* Protocols */,
0A7918F423F5E7EA00772FF4 /* ImageView.swift */,
D272F5F82473163100BD1A8F /* BarButtonItem.swift */,
);
path = BaseClasses;
sourceTree = "<group>";
@ -1988,6 +1991,7 @@
D21B7F602437C5BC00051ABF /* MoleculeStackView.swift in Sources */,
0A6682A42434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift in Sources */,
AA2AD116244EE46800BBFFE3 /* ListDeviceComplexLinkMedium.swift in Sources */,
D272F5F92473163100BD1A8F /* BarButtonItem.swift in Sources */,
0A9D09202433796500D2E6C0 /* BarsIndicatorView.swift in Sources */,
D2E2A99423D8CCBC000B42E6 /* HeadlineBodyLinkModel.swift in Sources */,
01004F3022721C3800991ECC /* RadioButton.swift in Sources */,
@ -2104,6 +2108,7 @@
01509D952327ED1900EF99AA /* HeadlineBodyLinkToggle.swift in Sources */,
31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */,
D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */,
D23EA7E82473654300D60C34 /* PanelNavigationItemModelProtocol.swift in Sources */,
94F6516D2437954100631BF9 /* Tabs.swift in Sources */,
5248BFEC23F12E350059236A /* ListThreeColumnPlanDataDivider.swift in Sources */,
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */,
@ -2166,7 +2171,6 @@
D2509ED12472ED9B001BFB9D /* NavigationItemModelProtocol.swift in Sources */,
8D448E5524050A46006211BB /* ListOneColumnFullWidthTextAllTextAndLinksModel.swift in Sources */,
94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */,
D2509ED32472EDC8001BFB9D /* PanelNavigationItemModelProtocol.swift in Sources */,
944589212385D6E900DE9FD4 /* DashLineModel.swift in Sources */,
D2E2A99623D8CF85000B42E6 /* HeadlineBodyLinkToggleModel.swift in Sources */,
C6FA7D5323C77A4A00A3614A /* StringAndMoleculeStack.swift in Sources */,

View File

@ -19,12 +19,14 @@ public class NavigationItemModel: NavigationItemModelProtocol, PanelNavigationIt
public var translucent: Bool
public var tintColor: Color
public var line: LineModel?
public var showLeftPanelButton: Bool
public var showRightPanelButton: Bool
public var backButton: NavigationItemButtonModel?
public var additionalLeftButtons: [NavigationItemButtonModel]?
public var additionalRightButtons: [NavigationItemButtonModel]?
// Legacy, will remove once menu is gone.
public var showLeftPanelButton: Bool
public var showRightPanelButton: Bool
public init() {
hidden = false
translucent = false

View File

@ -0,0 +1,14 @@
//
// PanelNavigationItemModelProtocol.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 5/18/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
public protocol PanelNavigationItemModelProtocol {
var showLeftPanelButton: Bool { get set }
var showRightPanelButton: Bool { get set }
}

View File

@ -6,4 +6,73 @@
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
public typealias BarButtonAction = (BarButtonItem) -> ()
@objcMembers open class BarButtonItem: UIBarButtonItem, MFButtonProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
private var buttonAction: BarButtonAction?
//--------------------------------------------------
// MARK: - Delegate
//--------------------------------------------------
open weak var buttonDelegate: ButtonDelegateProtocol?
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
/// Creates the item with the passed in action.
public static func create(with image: UIImage, actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
let button = self.init(image: image, style: .plain, target: self, action: #selector(callActionBlock))
button.set(with: actionModel, delegateObject: delegateObject, additionalData: additionalData)
return button
}
/// Creates the item with the passed in action map.
public static func create(with image: UIImage, actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
let button = self.init(image: image, style: .plain, target: self, action: #selector(callActionBlock))
button.set(with: actionMap, delegateObject: delegateObject, additionalData: additionalData)
return button
}
/// Creates the item with the passed in action.
public static func create(with image: UIImage, action: @escaping BarButtonAction) -> Self {
let button = self.init(image: image, style: .plain, target: self, action: #selector(callActionBlock))
button.buttonAction = action
return button
}
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
@objc func callActionBlock(_ sender: BarButtonItem) {
buttonAction?(self)
}
open func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
buttonDelegate = delegateObject?.buttonDelegate
buttonAction = { [weak self] sender in
guard let self = self else { return }
if let data = try? actionModel.encode(using: JSONEncoder()),
let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any],
delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
}
}
}
open func set(with actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
buttonDelegate = delegateObject?.buttonDelegate
buttonAction = { [weak self] sender in
guard let self = self,
delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true else { return }
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
}
}
}

View File

@ -158,18 +158,26 @@ import UIKit
needsUpdateUI = true
view.setNeedsLayout()
}
/// Processes any new data. Called after the page is loaded the first time and on response updates for this page,
open func handleNewData() {
// TODO: remove legacy. Temporary, convert legacy to navigation model.
var navigationModel = pageModel?.navigationItem ?? NavigationItemModel()
/// Creates a legacy navigation model.
open func createDefaultLegacyNavigationModel() -> NavigationItemModel {
let navigationModel = 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
return navigationModel
}
/// Processes any new data. Called after the page is loaded the first time and on response updates for this page,
open func handleNewData() {
// TODO: remove legacy. Temporary, convert legacy to navigation model.
if pageModel?.navigationItem == nil {
pageModel?.navigationItem = createDefaultLegacyNavigationModel()
}
if formValidator == nil {
let rules = pageModel?.formRules
formValidator = FormValidator(rules)

View File

@ -63,10 +63,13 @@ import UIKit
// Update icons if main navigation controller.
if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
navigationController.topViewController == viewController {
// Update Panels
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton , for: viewController)
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton , for: viewController)
MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint)
// Update Panels
if let model = navigationItemModel as? PanelNavigationItemModelProtocol {
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(model.showLeftPanelButton, for: viewController)
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(model.showRightPanelButton, for: viewController)
}
}
}
}

View File

@ -12,6 +12,7 @@
@import MVMCore.MVMCoreViewManagerProtocol;
@import MVMCore.MVMCoreObject;
@import MVMCore.MVMCoreActionUtility;
@import MVMCore.NSDictionary_MFConvenience;
#import "MVMCoreUIUtility.h"
#import "UIColor+MFConvenience.h"
#import "NSLayoutConstraint+MFConvenience.h"
@ -106,17 +107,31 @@ CGFloat const PanelAnimationDuration = 0.2;
return (width > 2000 ? MFTwoDrawer : (width > 1000 ? MFOneDrawer : MFNoDrawer));
}
- (nullable NSArray <UIBarButtonItem *>*)additionalLeftButtonsForViewController:(nonnull UIViewController *)viewController {
if (![viewController conformsToProtocol:@protocol(MVMCoreViewControllerProtocol)]) {
return nil;
- (nullable NSArray <UIBarButtonItem *>*)createNavigationItemsFrom:(nonnull NSArray <NSDictionary *>*)JSONlist delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject {
if (JSONlist.count == 0) { return nil; }
NSMutableArray *items = [NSMutableArray arrayWithCapacity:JSONlist.count];
for (NSDictionary *itemData in JSONlist) {
UIImage *image = [UIImage imageNamed:[itemData string:@"imageName"] inBundle:[[MVMCoreCache sharedCache] bundleToUseForImages] compatibleWithTraitCollection:nil];
BarButtonItem *item = [BarButtonItem createWith:image actionMap:[itemData dict:@"action"] delegateObject:delegateObject additionalData:nil];
[items addObject:item];
}
return items;
}
- (nullable NSArray <UIBarButtonItem *>*)additionalLeftButtonsForViewController:(nonnull UIViewController *)viewController {
if (![viewController conformsToProtocol:@protocol(MVMCoreViewControllerProtocol)]) { return nil; }
UIViewController <MVMCoreViewControllerProtocol>*controller = (UIViewController <MVMCoreViewControllerProtocol>*)viewController;
controller.page
return nil;
NSArray *items = [controller.loadObject.pageJSON arrayForChainOfKeysOrIndexes:@[@"navigationItem",@"additionalLeftButtons"]];
DelegateObject *delegate = [controller delegateObject];
return [self createNavigationItemsFrom:items delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
}
- (nullable NSArray <UIBarButtonItem *>*)additionalRightButtonsForViewController:(nonnull UIViewController *)viewController {
return nil;
if (![viewController conformsToProtocol:@protocol(MVMCoreViewControllerProtocol)]) { return nil; }
UIViewController <MVMCoreViewControllerProtocol>*controller = (UIViewController <MVMCoreViewControllerProtocol>*)viewController;
NSArray *items = [controller.loadObject.pageJSON arrayForChainOfKeysOrIndexes:@[@"navigationItem",@"additionalRightButtons"]];
DelegateObject *delegate = [controller delegateObject];
return [self createNavigationItemsFrom:items delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
}
- (CGFloat)leftPanelExtendedWidth {
@ -244,7 +259,7 @@ CGFloat const PanelAnimationDuration = 0.2;
if ((accessible && !extended) && self.leftPanelButton) {
[leftBarButtonItems addObject:self.leftPanelButton];
}
NSArray *extraButtons = [self additionalLeftButtonsForViewController:(nonnull UIViewController *)viewController];
NSArray *extraButtons = [self additionalLeftButtonsForViewController:viewController];
if (extraButtons) {
[leftBarButtonItems addObjectsFromArray:extraButtons];
}
@ -415,7 +430,7 @@ CGFloat const PanelAnimationDuration = 0.2;
if ((accessible && !extended) && self.rightPanelButton) {
[navigationItems addObject:self.rightPanelButton];
}
NSArray *extraButtons = [self additionalRightButtonsForViewController:(nonnull UIViewController *)viewController];
NSArray *extraButtons = [self additionalRightButtonsForViewController:viewController];
if (extraButtons) {
[navigationItems addObjectsFromArray:extraButtons];
}