Drive through delegate up front. Remove some legacy delegate back and forth
This commit is contained in:
parent
d8bf3c9a08
commit
1f75221915
@ -100,6 +100,8 @@ import MVMCore
|
|||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: baseDropdownEntryFieldModel)
|
let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: baseDropdownEntryFieldModel)
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionModel, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionModel, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -389,9 +389,10 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
var additionalDataToUpdate = additionalData ?? [:]
|
let additionalDataToUpdate = (checkboxModel != nil) ? additionalData.dictionaryAdding(key: KeySourceModel, value: checkboxModel!) : additionalData
|
||||||
additionalDataToUpdate[KeySourceModel] = checkboxModel
|
Task(priority: .userInitiated) {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionModel, additionalData: additionalDataToUpdate, delegateObject: delegateObject)
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionModel, additionalData: additionalDataToUpdate, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
|
|||||||
@ -396,11 +396,15 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
if self.isOn {
|
if self.isOn {
|
||||||
if let action = model.action {
|
if let action = model.action {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let action = model.alternateAction ?? model.action {
|
if let action = model.alternateAction ?? model.action {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -387,7 +387,9 @@ public typealias ActionBlock = () -> ()
|
|||||||
}
|
}
|
||||||
case let actionAtt as LabelAttributeActionModel:
|
case let actionAtt as LabelAttributeActionModel:
|
||||||
addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) {
|
addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionAtt.action, additionalData: additionalData, delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionAtt.action, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addActionAttributes(range: range, string: attributedString)
|
addActionAttributes(range: range, string: attributedString)
|
||||||
|
|
||||||
|
|||||||
@ -259,7 +259,9 @@ extension Tabs: UICollectionViewDelegateFlowLayout {
|
|||||||
if let delegate = delegate {
|
if let delegate = delegate {
|
||||||
delegate.didSelectItem(indexPath, tabs: self)
|
delegate.didSelectItem(indexPath, tabs: self)
|
||||||
} else if let action = tabsModel.tabs[selectedIndex].action {
|
} else if let action = tabsModel.tabs[selectedIndex].action {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: [KeySourceModel: tabsModel], delegateObject:delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: [KeySourceModel: tabsModel], delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if UIAccessibility.isVoiceOverRunning {
|
if UIAccessibility.isVoiceOverRunning {
|
||||||
UIAccessibility.post(notification: .layoutChanged, argument: tabCell)
|
UIAccessibility.post(notification: .layoutChanged, argument: tabCell)
|
||||||
|
|||||||
@ -46,9 +46,13 @@ public class AccordionMoleculeTableViewCell: MoleculeTableViewCell {
|
|||||||
model.selected = accordionButton.isSelected
|
model.selected = accordionButton.isSelected
|
||||||
|
|
||||||
if accordionButton.isSelected {
|
if accordionButton.isSelected {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: AddMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: AddMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: RemoveMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: RemoveMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accordionListItemModel?.hideLineWhenExpanded ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) {
|
if (accordionListItemModel?.hideLineWhenExpanded ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) {
|
||||||
@ -56,7 +60,9 @@ public class AccordionMoleculeTableViewCell: MoleculeTableViewCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let actionModel = accordionButton.isSelected ? accordionListItemModel?.expandAction : accordionListItemModel?.collapseAction {
|
if let actionModel = accordionButton.isSelected ? accordionListItemModel?.expandAction : accordionListItemModel?.collapseAction {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionModel, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionModel, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,9 @@ import UIKit
|
|||||||
actions.append(AddMoleculesActionModel(.fade))
|
actions.append(AddMoleculesActionModel(.fade))
|
||||||
let actionsModel = ActionActionsModel(actions: actions)
|
let actionsModel = ActionActionsModel(actions: actions)
|
||||||
actionsModel.concurrent = false
|
actionsModel.concurrent = false
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: actionsModel, additionalData: additionData, delegateObject: self.delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (self.delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionsModel, additionalData: additionData, delegateObject: self.delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,9 @@ extension TabsTableViewCell: TabsDelegate {
|
|||||||
public func shouldSelectItem(_ indexPath: IndexPath, tabs: Tabs) -> Bool {
|
public func shouldSelectItem(_ indexPath: IndexPath, tabs: Tabs) -> Bool {
|
||||||
guard indexPath.row != tabs.selectedIndex else { return false }
|
guard indexPath.row != tabs.selectedIndex else { return false }
|
||||||
if let model = tabsListItemModel {
|
if let model = tabsListItemModel {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: RemoveMoleculesActionModel(indexPath.row < tabs.selectedIndex ? .right : .left), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: RemoveMoleculesActionModel(indexPath.row < tabs.selectedIndex ? .right : .left), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
previousTabIndex = tabs.selectedIndex
|
previousTabIndex = tabs.selectedIndex
|
||||||
return true
|
return true
|
||||||
@ -68,9 +70,13 @@ extension TabsTableViewCell: TabsDelegate {
|
|||||||
guard let model = tabsListItemModel,
|
guard let model = tabsListItemModel,
|
||||||
index < model.molecules.count else { return }
|
index < model.molecules.count else { return }
|
||||||
if let action = model.tabs.tabs[index].action {
|
if let action = model.tabs.tabs[index].action {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: [KeySourceModel: model.tabs], delegateObject:delegateObject)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: [KeySourceModel: model.tabs], delegateObject: delegateObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: AddMoleculesActionModel(index < previousTabIndex ? .left : .right), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: AddMoleculesActionModel(index < previousTabIndex ? .left : .right), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,10 @@ import MVMCore
|
|||||||
|
|
||||||
@objcMembers open class NotificationXButton: Button {
|
@objcMembers open class NotificationXButton: Button {
|
||||||
|
|
||||||
open func closeTopAlert() {
|
open func closeTopAlert(with delegateObject: MVMCoreUIDelegateObject?) {
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: ActionDismissNotificationModel(), additionalData: nil, delegateObject: nil)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: ActionDismissNotificationModel(), additionalData: nil, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
@ -35,7 +37,7 @@ import MVMCore
|
|||||||
// TODO: Temporary, consider action for dismissing top alert
|
// TODO: Temporary, consider action for dismissing top alert
|
||||||
if model.action.actionType == ActionNoopModel.identifier {
|
if model.action.actionType == ActionNoopModel.identifier {
|
||||||
addActionBlock(event: .touchUpInside) { (button) in
|
addActionBlock(event: .touchUpInside) { (button) in
|
||||||
(button as? NotificationXButton)?.closeTopAlert()
|
(button as? NotificationXButton)?.closeTopAlert(with: delegateObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
open class ModalMoleculeListTemplate: MoleculeListTemplate {
|
open class ModalMoleculeListTemplate: MoleculeListTemplate {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -32,7 +32,9 @@ open class ModalMoleculeListTemplate: MoleculeListTemplate {
|
|||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let closeAction = (self.templateModel as? ModalListPageTemplateModel)?.closeAction ??
|
let closeAction = (self.templateModel as? ModalListPageTemplateModel)?.closeAction ??
|
||||||
ActionBackModel()
|
ActionBackModel()
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (self.delegateObject()?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
open class ModalMoleculeStackTemplate: MoleculeStackTemplate {
|
open class ModalMoleculeStackTemplate: MoleculeStackTemplate {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -28,7 +29,9 @@ open class ModalMoleculeStackTemplate: MoleculeStackTemplate {
|
|||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let closeAction = (self.templateModel as? ModalStackPageTemplateModel)?.closeAction ??
|
let closeAction = (self.templateModel as? ModalStackPageTemplateModel)?.closeAction ??
|
||||||
ActionBackModel()
|
ActionBackModel()
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (self.delegateObject()?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
// Created by Scott Pfeil on 10/8/20.
|
// Created by Scott Pfeil on 10/8/20.
|
||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
open class ModalSectionListTemplate: SectionListTemplate {
|
open class ModalSectionListTemplate: SectionListTemplate {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -27,7 +27,9 @@ open class ModalSectionListTemplate: SectionListTemplate {
|
|||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let closeAction = (self.templateModel as? ModalSectionListTemplateModel)?.closeAction ??
|
let closeAction = (self.templateModel as? ModalSectionListTemplateModel)?.closeAction ??
|
||||||
ActionBackModel()
|
ActionBackModel()
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (self.delegateObject()?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public typealias ButtonAction = (Button) -> ()
|
|||||||
if let sourceModel = sourceModel {
|
if let sourceModel = sourceModel {
|
||||||
additionalData = additionalData.dictionaryAdding(key: KeySourceModel, value: sourceModel)
|
additionalData = additionalData.dictionaryAdding(key: KeySourceModel, value: sourceModel)
|
||||||
}
|
}
|
||||||
try await MVMCoreUIActionHandler.handleActionCheckingDelegate(with: model, additionalData: additionalData, delegateObject: delegateObject)
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK:- MoleculeViewProtocol
|
// MARK:- MoleculeViewProtocol
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, ActionDelegateProtocol, ActionOpenPageDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate, MVMCoreUIDetailViewProtocol, PageProtocol, PageBehaviorHandlerProtocol {
|
@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, ActionDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate, MVMCoreUIDetailViewProtocol, PageProtocol, PageBehaviorHandlerProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
@ -439,40 +439,41 @@ import MVMCore
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - MVMCoreActionDelegateProtocol
|
// MARK: - MVMCoreActionDelegateProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open func getRequestParameters(for model: ActionOpenPageModel, delegateObject: DelegateObject? = nil, additionalData: [AnyHashable : Any]? = nil) throws -> (MVMCoreRequestParameters,[AnyHashable : Any]?) {
|
|
||||||
let json = try MVMCoreActionHandler.convertActionToJSON(model)
|
|
||||||
let requestParameters = MVMCoreRequestParameters(actionMap: json)!
|
|
||||||
addFormParams(requestParameters: requestParameters, model: model, additionalData: additionalData)
|
|
||||||
requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType")
|
|
||||||
var pageForwardedData = additionalData ?? [:]
|
|
||||||
|
|
||||||
executeBehaviors { (behavior: PageLocalDataShareBehavior) in
|
|
||||||
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
|
|
||||||
pageForwardedData.merge(dataMap) { current, _ in current }
|
|
||||||
}
|
|
||||||
return (requestParameters, pageForwardedData)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func logAction(withActionInformation actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
|
open func logAction(withActionInformation actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
|
||||||
MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController: self, actionInformation: actionInformation, additionalData: additionalData)
|
MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController: self, actionInformation: actionInformation, additionalData: additionalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handlesUnknownAction(for model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> Bool {
|
open func performAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) async throws {
|
||||||
var handled = false
|
var additionalData = additionalData
|
||||||
executeBehaviors { (behavior: PageCustomActionHandlerBehavior) in
|
if let model = model as? ActionOpenPageModel {
|
||||||
if !handled {
|
addFormParams(requestParameters: model.requestParameters, model: model, additionalData: additionalData)
|
||||||
handled = behavior.handleAction(with: model, additionalData: additionalData)
|
model.requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType")
|
||||||
|
|
||||||
|
var pageForwardedData = additionalData ?? [:]
|
||||||
|
executeBehaviors { (behavior: PageLocalDataShareBehavior) in
|
||||||
|
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
|
||||||
|
pageForwardedData.merge(dataMap) { current, _ in current }
|
||||||
}
|
}
|
||||||
|
additionalData = pageForwardedData
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
if let behavior = behaviors?.compactMap({ $0 as? PageCustomActionHandlerBehavior }).first(where: { $0.canHandleAction(with: model, additionalData: additionalData) }) {
|
||||||
|
delegateObject?.actionDelegate?.logAction?(withActionInformation: model.toJSON(), additionalData: additionalData)
|
||||||
|
try await behavior.handleAction(with: model, additionalData: additionalData)
|
||||||
|
} else {
|
||||||
|
try await MVMCoreUIActionHandler.shared()?.handleAction(with: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
handleAction(error: error, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
return handled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open func performAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) async throws {
|
open func handleAction(error: Error, model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||||
do {
|
let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: model.actionType))!
|
||||||
try await MVMCoreUIActionHandler.shared()?.handleAction(with: model, additionalData: additionalData, delegateObject: delegateObject)
|
MVMCoreUIActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: additionalData)
|
||||||
} catch {
|
|
||||||
MVMCoreUIActionHandler.shared()?.defaultHandle(error: error, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
public enum AddMoleculesPosition {
|
public enum AddMoleculesPosition {
|
||||||
case above
|
case above
|
||||||
@ -85,28 +86,27 @@ public class AddRemoveMoleculesBehavior: PageCustomActionHandlerBehavior, PageMo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) -> Bool {
|
public func canHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) -> Bool {
|
||||||
if model.actionType == AddMoleculesActionModel.identifier {
|
return model.actionType == AddMoleculesActionModel.identifier || model.actionType == RemoveMoleculesActionModel.identifier
|
||||||
guard let model = model as? AddMoleculesActionModel,
|
}
|
||||||
let list = delegate?.moleculeListDelegate,
|
|
||||||
let sourceModel = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & AddMolecules),
|
public func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) async throws {
|
||||||
let moleculesToAdd = sourceModel.getRecursiveMoleculesToAdd(),
|
if let model = model as? AddMoleculesActionModel,
|
||||||
let indexPath = list.getAdjustedIndexPath(for: sourceModel, position: moleculesToAdd.1) else { return true }
|
let list = delegate?.moleculeListDelegate,
|
||||||
DispatchQueue.main.async {
|
let sourceModel = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & AddMolecules),
|
||||||
|
let moleculesToAdd = sourceModel.getRecursiveMoleculesToAdd(),
|
||||||
|
let indexPath = list.getAdjustedIndexPath(for: sourceModel, position: moleculesToAdd.1) {
|
||||||
|
await MainActor.run {
|
||||||
list.addMolecules(moleculesToAdd.0, indexPath: indexPath, animation: model.animation)
|
list.addMolecules(moleculesToAdd.0, indexPath: indexPath, animation: model.animation)
|
||||||
}
|
}
|
||||||
return true
|
} else if let model = model as? RemoveMoleculesActionModel,
|
||||||
} else if model.actionType == RemoveMoleculesActionModel.identifier {
|
|
||||||
guard let model = model as? RemoveMoleculesActionModel,
|
|
||||||
let list = delegate?.moleculeListDelegate,
|
let list = delegate?.moleculeListDelegate,
|
||||||
let sourceModel = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & RemoveMolecules),
|
let sourceModel = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & RemoveMolecules),
|
||||||
let moleculesToRemove = sourceModel.getRecursiveMoleculesToRemove() else { return true }
|
let moleculesToRemove = sourceModel.getRecursiveMoleculesToRemove() {
|
||||||
DispatchQueue.main.async {
|
await MainActor.run {
|
||||||
list.removeMolecules(moleculesToRemove, animation: model.animation)
|
list.removeMolecules(moleculesToRemove, animation: model.animation)
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
|
|
||||||
public protocol PageBehaviorProtocol: ModelHandlerProtocol {
|
public protocol PageBehaviorProtocol: ModelHandlerProtocol {
|
||||||
|
|
||||||
@ -65,12 +67,14 @@ public protocol PageLocalDataShareBehavior: PageBehaviorProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public protocol PageCustomActionHandlerBehavior: PageBehaviorProtocol {
|
public protocol PageCustomActionHandlerBehavior: PageBehaviorProtocol {
|
||||||
|
|
||||||
|
/// Returns if this behavior can handle the action.
|
||||||
|
func canHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) -> Bool
|
||||||
|
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - model: The action model.
|
/// - model: The action model.
|
||||||
/// - additionalData: Additional information of the
|
/// - additionalData: Additional information of the
|
||||||
/// - Returns: Boolean determines if the action has been handled.
|
func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) async throws
|
||||||
func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) -> Bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension MVMCoreUIDelegateObject {
|
public extension MVMCoreUIDelegateObject {
|
||||||
|
|||||||
@ -170,19 +170,15 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
|||||||
requestParameters.tabWasPressed = true
|
requestParameters.tabWasPressed = true
|
||||||
return requestParameters
|
return requestParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func getRequestParameters(for model: ActionOpenPageModel, delegateObject: DelegateObject? = nil, additionalData: [AnyHashable : Any]? = nil) throws -> (MVMCoreRequestParameters, [AnyHashable : Any]?) {
|
open override func performAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) async throws {
|
||||||
let value = try super.getRequestParameters(for: model, delegateObject: delegateObject, additionalData: additionalData)
|
if let model = model as? ActionOpenPageModel,
|
||||||
var requestParameters = value.0
|
let additionalData = additionalData,
|
||||||
let additionalData = value.1
|
additionalData.boolForKey("tabBarPressed") {
|
||||||
guard let additionalData = additionalData,
|
// Allow opportunity to modify parameters.
|
||||||
additionalData.boolForKey("tabBarPressed") else {
|
model.requestParameters = getRequestParametersForNewTabLoad(requestParameters: model.requestParameters, model: model, additionalData: additionalData)
|
||||||
// Pass to delegate
|
}
|
||||||
return try (viewController as? ActionOpenPageDelegateProtocol)?.getRequestParameters(for: model, delegateObject: delegateObject, additionalData: additionalData) ?? value
|
try await super.performAction(with: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
}
|
|
||||||
// Allow opportunity to modify parameters.
|
|
||||||
requestParameters = getRequestParametersForNewTabLoad(requestParameters: requestParameters, model: model, additionalData: additionalData)
|
|
||||||
return (requestParameters, additionalData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCorePresentationDelegateProtocol
|
// MARK: - MVMCorePresentationDelegateProtocol
|
||||||
@ -277,7 +273,9 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
|||||||
} else if let tabsModel = tabs.tabsModel,
|
} else if let tabsModel = tabs.tabsModel,
|
||||||
let action = tabsModel.tabs[indexPath.row].action {
|
let action = tabsModel.tabs[indexPath.row].action {
|
||||||
// Perform the tab action
|
// Perform the tab action
|
||||||
MVMCoreUIActionHandler.asyncHandleActionCheckingDelegate(with: action, additionalData: getAdditionalDataForNewTabLoad(indexPath: indexPath), delegateObject: delegateObjectIVar)
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObjectIVar.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: getAdditionalDataForNewTabLoad(indexPath: indexPath), delegateObject: delegateObjectIVar)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user