From d8bf3c9a086060997101d15237aaa72b747461f0 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 8 Aug 2022 17:45:28 -0400 Subject: [PATCH] Button -> Delegate -> ActionHandler. Components will go through delegate. Delegate will choose how to handle it. --- .../Atomic/Actions/ActionAlertHandler.swift | 2 +- .../ActionCollapseNotificationHandler.swift | 2 +- .../ActionDismissNotificationHandler.swift | 2 +- .../Actions/ActionOpenPanelHandler.swift | 2 +- .../Atomic/Actions/ActionPopupHandler.swift | 2 +- .../Actions/ActionTopAlertHandler.swift | 2 +- .../ActionTopNotificationHandler.swift | 2 +- .../Atomic/Atoms/FormFields/Tags/Tags.swift | 4 +++- .../BaseDropdownEntryField.swift | 2 +- .../Atomic/Atoms/Selectors/Checkbox.swift | 2 +- MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift | 4 +++- .../Atomic/Atoms/Selectors/RadioBox.swift | 4 +++- .../Atomic/Atoms/Selectors/RadioButton.swift | 4 +++- .../Atomic/Atoms/Selectors/RadioSwatch.swift | 4 +++- MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift | 4 ++-- .../Atomic/Atoms/Views/Label/Label.swift | 2 +- .../HorizontalCombinationViews/TabBar.swift | 5 +++- .../HorizontalCombinationViews/Tabs.swift | 2 +- .../AccordionMoleculeTableViewCell.swift | 10 ++++---- .../Items/DropDownFilterTableViewCell.swift | 2 +- .../Molecules/Items/TabsTableViewCell.swift | 6 ++--- .../CollapsableNotification.swift | 4 +++- .../TopNotification/NotificationXButton.swift | 2 +- .../Templates/ModalMoleculeListTemplate.swift | 2 +- .../ModalMoleculeStackTemplate.swift | 2 +- .../Templates/ModalSectionListTemplate.swift | 2 +- MVMCoreUI/BaseClasses/BarButtonItem.swift | 4 +++- MVMCoreUI/BaseClasses/Button.swift | 23 +++++++++---------- .../BaseClasses/CollectionViewCell.swift | 4 +++- MVMCoreUI/BaseClasses/TableViewCell.swift | 4 +++- .../BaseControllers/ViewController.swift | 8 +++++++ .../SubNav/SubNavManagerController.swift | 2 +- 32 files changed, 77 insertions(+), 49 deletions(-) diff --git a/MVMCoreUI/Atomic/Actions/ActionAlertHandler.swift b/MVMCoreUI/Atomic/Actions/ActionAlertHandler.swift index cc40b20b..0f4a11fa 100644 --- a/MVMCoreUI/Atomic/Actions/ActionAlertHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionAlertHandler.swift @@ -24,7 +24,7 @@ open class ActionAlertHandler: MVMCoreJSONActionHandlerProtocol { } } - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { let json = try MVMCoreActionHandler.convertActionToJSON(model) try await performAction(with: json, model: model, delegateObject: delegateObject, additionalData: additionalData) } diff --git a/MVMCoreUI/Atomic/Actions/ActionCollapseNotificationHandler.swift b/MVMCoreUI/Atomic/Actions/ActionCollapseNotificationHandler.swift index f12b2db9..069ee74f 100644 --- a/MVMCoreUI/Atomic/Actions/ActionCollapseNotificationHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionCollapseNotificationHandler.swift @@ -13,7 +13,7 @@ import MVMCore open class ActionCollapseNotificationHandler: MVMCoreActionHandlerProtocol { required public init() {} - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { CoreUIObject.sharedInstance()?.globalTopAlertDelegate?.getTopAlertView?().collapseNotification?() } } diff --git a/MVMCoreUI/Atomic/Actions/ActionDismissNotificationHandler.swift b/MVMCoreUI/Atomic/Actions/ActionDismissNotificationHandler.swift index 65db5455..a2e1f279 100644 --- a/MVMCoreUI/Atomic/Actions/ActionDismissNotificationHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionDismissNotificationHandler.swift @@ -13,7 +13,7 @@ import MVMCore open class ActionDismissNotificationHandler: MVMCoreActionHandlerProtocol { required public init() {} - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { await withCheckedContinuation { continuation in CoreUIObject.sharedInstance()?.globalTopAlertDelegate?.getTopAlertView?().hideAlertView?(true, completionHandler: { finished in continuation.resume() diff --git a/MVMCoreUI/Atomic/Actions/ActionOpenPanelHandler.swift b/MVMCoreUI/Atomic/Actions/ActionOpenPanelHandler.swift index 20853583..98287b27 100644 --- a/MVMCoreUI/Atomic/Actions/ActionOpenPanelHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionOpenPanelHandler.swift @@ -25,7 +25,7 @@ open class ActionOpenPanelHandler: MVMCoreJSONActionHandlerProtocol { } } - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { guard let model = model as? ActionOpenPanelModel else { return } let json = try MVMCoreActionHandler.convertActionToJSON(model) try await performAction(with: json, model: model, delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift b/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift index 2bafd60b..9fe86eef 100644 --- a/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionPopupHandler.swift @@ -13,7 +13,7 @@ import MVMCore open class ActionPopupHandler: MVMCoreActionHandlerProtocol { required public init() {} - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { guard let model = model as? ActionPopupModel else { return } try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in MVMCoreCache.shared()?.fetchJSON(forPageType: model.pageType, queue: nil, waitUntilFinished: true, completionHandler: { json in diff --git a/MVMCoreUI/Atomic/Actions/ActionTopAlertHandler.swift b/MVMCoreUI/Atomic/Actions/ActionTopAlertHandler.swift index b7d3d5eb..49ca8561 100644 --- a/MVMCoreUI/Atomic/Actions/ActionTopAlertHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionTopAlertHandler.swift @@ -13,7 +13,7 @@ import MVMCore open class ActionTopAlertHandler: MVMCoreActionHandlerProtocol { required public init() {} - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { guard let model = model as? ActionTopAlertModel else { return } try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in MVMCoreCache.shared()?.fetchJSON(forPageType: model.pageType, queue: nil, waitUntilFinished: true, completionHandler: { json in diff --git a/MVMCoreUI/Atomic/Actions/ActionTopNotificationHandler.swift b/MVMCoreUI/Atomic/Actions/ActionTopNotificationHandler.swift index 89762268..858c1d09 100644 --- a/MVMCoreUI/Atomic/Actions/ActionTopNotificationHandler.swift +++ b/MVMCoreUI/Atomic/Actions/ActionTopNotificationHandler.swift @@ -13,7 +13,7 @@ import MVMCore open class ActionTopNotificationHandler: MVMCoreActionHandlerProtocol { required public init() {} - open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { guard let model = model as? ActionTopNotificationModel else { return } await MVMCoreUITopAlertView.sharedGlobal()?.showTopAlert(with: model.topNotification) } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift index 4b1fa4f9..a112a723 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift @@ -100,6 +100,8 @@ extension Tags: UICollectionViewDelegate { open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let tagModel = tags?[indexPath.row], let tagAction = tagModel.action else { return } - Button.performButtonAction(with: tagAction, button: self, delegateObject: delegateObject, additionalData: nil) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: tagAction, button: self, delegateObject: delegateObject, additionalData: nil) + } } } diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift index c6b233a7..fdf80f29 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/Dropdown Fields/BaseDropdownEntryField.swift @@ -100,6 +100,6 @@ import MVMCore else { return } let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: baseDropdownEntryFieldModel) - MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: additionalDataWithSource, delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionModel, additionalData: additionalDataWithSource, delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index 4bd64c7c..bbbeec00 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -391,7 +391,7 @@ import MVMCore private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { var additionalDataToUpdate = additionalData ?? [:] additionalDataToUpdate[KeySourceModel] = checkboxModel - MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: additionalDataToUpdate, delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionModel, additionalData: additionalDataToUpdate, delegateObject: delegateObject) } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift index eb0b0b4c..1f22e328 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Heart.swift @@ -106,7 +106,9 @@ import UIKit guard isEnabled else { return } isSelected = !isSelected if let heartModel = heartModel { - Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel) + } } setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index 27323048..9fb6b354 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -142,7 +142,9 @@ open class RadioBox: Control, MFButtonProtocol { isSelected = true radioBoxModel?.selected = isSelected if let radioBoxModel = radioBoxModel, let actionModel = radioBoxModel.action { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioBoxModel) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioBoxModel) + } } layer.setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 1f82a63c..ddd155be 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -104,7 +104,9 @@ import VDSFormControlsTokens } if let radioModel = radioModel, let actionModel = radioModel.action, isSelected, !wasPreviouslySelected { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioModel) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioModel) + } } _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift index eb569810..50d9d9c5 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatch.swift @@ -124,7 +124,9 @@ open class RadioSwatch: Control, MFButtonProtocol { isSelected = true radioSwatchModel?.selected = isSelected if let radioSwatchModel = radioSwatchModel, let actionModel = radioSwatchModel.action { - Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioSwatchModel) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioSwatchModel) + } } layer.setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift index 04c34da2..dc16312e 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Toggle.swift @@ -396,11 +396,11 @@ public typealias ActionBlockConfirmation = () -> (Bool) guard let self = self else { return } if self.isOn { if let action = model.action { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject) } } else { if let action = model.alternateAction ?? model.action { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject) } } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 91bf44b8..d78d15d5 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -387,7 +387,7 @@ public typealias ActionBlock = () -> () } case let actionAtt as LabelAttributeActionModel: addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionAtt.action, additionalData: additionalData, delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionAtt.action, additionalData: additionalData, delegateObject: delegateObject) } addActionAttributes(range: range, string: attributedString) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift index 527ed054..e49006fa 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift @@ -69,7 +69,10 @@ import VDSColorTokens // MARK: - UITabBarDelegate public func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { model.selectedTab = item.tag - Button.performButtonAction(with: model.tabs[item.tag].action, button: item, delegateObject: delegateObject, additionalData: nil) + let action = model.tabs[item.tag].action + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: action, button: item, delegateObject: delegateObject, additionalData: nil) + } } // MARK: - TabBarProtocol diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift index f8e00ae6..42217612 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/Tabs.swift @@ -259,7 +259,7 @@ extension Tabs: UICollectionViewDelegateFlowLayout { if let delegate = delegate { delegate.didSelectItem(indexPath, tabs: self) } else if let action = tabsModel.tabs[selectedIndex].action { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: [KeySourceModel: tabsModel], delegateObject:delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: [KeySourceModel: tabsModel], delegateObject:delegateObject) } if UIAccessibility.isVoiceOverRunning { UIAccessibility.post(notification: .layoutChanged, argument: tabCell) diff --git a/MVMCoreUI/Atomic/Molecules/Items/AccordionMoleculeTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/AccordionMoleculeTableViewCell.swift index 6975f8cb..1a219840 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/AccordionMoleculeTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/AccordionMoleculeTableViewCell.swift @@ -6,8 +6,8 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // - -@objcMembers public class AccordionMoleculeTableViewCell: MoleculeTableViewCell { +import MVMCore +public class AccordionMoleculeTableViewCell: MoleculeTableViewCell { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -46,9 +46,9 @@ model.selected = accordionButton.isSelected if accordionButton.isSelected { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: AddMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: AddMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject) } else { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: RemoveMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: RemoveMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject) } if (accordionListItemModel?.hideLineWhenExpanded ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) { @@ -56,7 +56,7 @@ } if let actionModel = accordionButton.isSelected ? accordionListItemModel?.expandAction : accordionListItemModel?.collapseAction { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionModel, additionalData: [KeySourceModel: model], delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionModel, additionalData: [KeySourceModel: model], delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Atomic/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/DropDownFilterTableViewCell.swift index 58e9dfc4..0a845a92 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/DropDownFilterTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/DropDownFilterTableViewCell.swift @@ -37,7 +37,7 @@ import UIKit actions.append(AddMoleculesActionModel(.fade)) let actionsModel = ActionActionsModel(actions: actions) actionsModel.concurrent = false - MVMCoreActionHandler.shared()?.asyncHandleAction(with: actionsModel, additionalData: additionData, delegateObject: self.delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionsModel, additionalData: additionData, delegateObject: self.delegateObject) } } diff --git a/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift b/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift index d3b91b11..8e63cbd4 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/TabsTableViewCell.swift @@ -57,7 +57,7 @@ extension TabsTableViewCell: TabsDelegate { public func shouldSelectItem(_ indexPath: IndexPath, tabs: Tabs) -> Bool { guard indexPath.row != tabs.selectedIndex else { return false } if let model = tabsListItemModel { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: RemoveMoleculesActionModel(indexPath.row < tabs.selectedIndex ? .right : .left), additionalData: [KeySourceModel: model], delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: RemoveMoleculesActionModel(indexPath.row < tabs.selectedIndex ? .right : .left), additionalData: [KeySourceModel: model], delegateObject: delegateObject) } previousTabIndex = tabs.selectedIndex return true @@ -68,9 +68,9 @@ extension TabsTableViewCell: TabsDelegate { guard let model = tabsListItemModel, index < model.molecules.count else { return } if let action = model.tabs.tabs[index].action { - MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: [KeySourceModel: model.tabs], delegateObject:delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: [KeySourceModel: model.tabs], delegateObject:delegateObject) } - MVMCoreActionHandler.shared()?.asyncHandleAction(with: AddMoleculesActionModel(index < previousTabIndex ? .left : .right), additionalData: [KeySourceModel: model], delegateObject: delegateObject) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: AddMoleculesActionModel(index < previousTabIndex ? .left : .right), additionalData: [KeySourceModel: model], delegateObject: delegateObject) } } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift index 82983f4d..8c9416c0 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift @@ -60,7 +60,9 @@ import Foundation if let topAction = model.topAction, topAction.actionType == ActionNoopModel.identifier { topView.button.addActionBlock(event: .touchUpInside) { [weak self] (button) in - Button.performButtonAction(with: topAction, button: button, delegateObject: delegateObject, additionalData: additionalData) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: topAction, button: button, delegateObject: delegateObject, additionalData: additionalData) + } self?.expand(topViewShowing: model.alwaysShowTopLabel) } } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift index 560dcf23..698aedcd 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift @@ -12,7 +12,7 @@ import MVMCore @objcMembers open class NotificationXButton: Button { open func closeTopAlert() { - MVMCoreUIActionHandler.shared()?.asyncHandleAction(with: ActionDismissNotificationModel(), additionalData: nil, delegateObject: nil) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: ActionDismissNotificationModel(), additionalData: nil, delegateObject: nil) } open override func setupView() { diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift index 71c23c16..033bebb4 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift @@ -32,7 +32,7 @@ open class ModalMoleculeListTemplate: MoleculeListTemplate { guard let self = self else { return } let closeAction = (self.templateModel as? ModalListPageTemplateModel)?.closeAction ?? ActionBackModel() - MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) }) } diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift index 1c76b467..1531d35b 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift @@ -28,7 +28,7 @@ open class ModalMoleculeStackTemplate: MoleculeStackTemplate { guard let self = self else { return } let closeAction = (self.templateModel as? ModalStackPageTemplateModel)?.closeAction ?? ActionBackModel() - MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) }) } } diff --git a/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift index 3e4f3fc2..96052ee1 100644 --- a/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalSectionListTemplate.swift @@ -27,7 +27,7 @@ open class ModalSectionListTemplate: SectionListTemplate { guard let self = self else { return } let closeAction = (self.templateModel as? ModalSectionListTemplateModel)?.closeAction ?? ActionBackModel() - MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar) }) } } diff --git a/MVMCoreUI/BaseClasses/BarButtonItem.swift b/MVMCoreUI/BaseClasses/BarButtonItem.swift index b46647f2..c360b457 100644 --- a/MVMCoreUI/BaseClasses/BarButtonItem.swift +++ b/MVMCoreUI/BaseClasses/BarButtonItem.swift @@ -33,7 +33,9 @@ public typealias BarButtonAction = (BarButtonItem) -> () buttonDelegate = delegateObject?.buttonDelegate actionDelegate?.buttonAction = { sender in let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: model) - Button.performButtonAction(with: model.action, button: sender, delegateObject: delegateObject, additionalData: additionalDataWithSource) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: model.action, button: sender, delegateObject: delegateObject, additionalData: additionalDataWithSource) + } } } } diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index a94cafe8..ebda6af4 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -6,8 +6,9 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // -public typealias ButtonAction = (Button) -> () +import MVMCore +public typealias ButtonAction = (Button) -> () @objcMembers open class Button: UIButton, MFButtonProtocol, MoleculeViewProtocol { //-------------------------------------------------- @@ -79,21 +80,19 @@ public typealias ButtonAction = (Button) -> () addActionBlock(event: .touchUpInside) { [weak self] sender in guard let self = self, let actionModel = actionModel else { return } - Self.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: self.model) + Task(priority: .userInitiated) { + try await Self.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: self.model) + } } } - open class func performButtonAction(with model: ActionModelProtocol, button: MFButtonProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, sourceModel: MoleculeModelProtocol? = nil) { - if let data = try? model.encode(using: JSONEncoder()), - let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any], - delegateObject?.buttonDelegate?.button?(button, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { - if let sourceModel = sourceModel { - let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: sourceModel) - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalDataWithSource, delegateObject: delegateObject) - } else { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + open class func performButtonAction(with model: ActionModelProtocol, button: MFButtonProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, sourceModel: MoleculeModelProtocol? = nil) async throws { + guard delegateObject?.buttonDelegate?.button?(button, shouldPerformActionWithMap: model.toJSON(), additionalData: additionalData) ?? true else { return } + var additionalData = additionalData + if let sourceModel = sourceModel { + additionalData = additionalData.dictionaryAdding(key: KeySourceModel, value: sourceModel) } + try await MVMCoreUIActionHandler.handleActionCheckingDelegate(with: model, additionalData: additionalData, delegateObject: delegateObject) } // MARK:- MoleculeViewProtocol diff --git a/MVMCoreUI/BaseClasses/CollectionViewCell.swift b/MVMCoreUI/BaseClasses/CollectionViewCell.swift index cfbe4ac7..c57afd41 100644 --- a/MVMCoreUI/BaseClasses/CollectionViewCell.swift +++ b/MVMCoreUI/BaseClasses/CollectionViewCell.swift @@ -118,7 +118,9 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo open func shouldSelect(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Bool { if let action = model?.action { - Button.performButtonAction(with: action, button: self, delegateObject: delegateObject, additionalData: additionalData) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: action, button: self, delegateObject: delegateObject, additionalData: additionalData) + } } return false } diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index d90d0338..c21e2c49 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -256,7 +256,9 @@ import UIKit open func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { guard let action = listItemModel?.action else { return } - Button.performButtonAction(with: action, button: self, delegateObject: delegateObject, additionalData: additionalData) + Task(priority: .userInitiated) { + try await Button.performButtonAction(with: action, button: self, delegateObject: delegateObject, additionalData: additionalData) + } } open func didDeselectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 763028ff..bd62a3ad 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -467,6 +467,14 @@ import MVMCore return handled } + open func performAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) async throws { + do { + try await MVMCoreUIActionHandler.shared()?.handleAction(with: model, additionalData: additionalData, delegateObject: delegateObject) + } catch { + MVMCoreUIActionHandler.shared()?.defaultHandle(error: error, model: model, additionalData: additionalData, delegateObject: delegateObject) + } + } + //-------------------------------------------------- // MARK: - MoleculeDelegateProtocol //-------------------------------------------------- diff --git a/MVMCoreUI/Managers/SubNav/SubNavManagerController.swift b/MVMCoreUI/Managers/SubNav/SubNavManagerController.swift index 237fa71e..2d1ab302 100644 --- a/MVMCoreUI/Managers/SubNav/SubNavManagerController.swift +++ b/MVMCoreUI/Managers/SubNav/SubNavManagerController.swift @@ -277,7 +277,7 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol, } else if let tabsModel = tabs.tabsModel, let action = tabsModel.tabs[indexPath.row].action { // Perform the tab action - MVMCoreActionHandler.shared()?.asyncHandleAction(with: action, additionalData: getAdditionalDataForNewTabLoad(indexPath: indexPath), delegateObject: delegateObjectIVar) + MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: getAdditionalDataForNewTabLoad(indexPath: indexPath), delegateObject: delegateObjectIVar) } return false }