Centralize SoureModel
This commit is contained in:
parent
31169e318e
commit
78034bb8d0
@ -23,10 +23,8 @@ open class ActionPopupHandler: MVMCoreActionHandlerProtocol {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json!)
|
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json!)
|
||||||
Task {
|
Task { @MainActor in
|
||||||
_ = await MainActor.run {
|
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
||||||
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
|
||||||
}
|
|
||||||
continuation.resume()
|
continuation.resume()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -12,8 +12,6 @@ import MVMCore
|
|||||||
open class MVMCoreUIActionOpenPageHandler: ActionOpenPageHandler {
|
open class MVMCoreUIActionOpenPageHandler: ActionOpenPageHandler {
|
||||||
open override func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
open override func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
||||||
// Cleanup the source model data to prevent it from being accidentally auto-forwarded in openPage network requests by blind additionalData insertions. (https://onejira.verizon.com/browse/CXTDT-135642, https://onejira.verizon.com/browse/CXTDT-136001).
|
// Cleanup the source model data to prevent it from being accidentally auto-forwarded in openPage network requests by blind additionalData insertions. (https://onejira.verizon.com/browse/CXTDT-135642, https://onejira.verizon.com/browse/CXTDT-136001).
|
||||||
var additionalData = additionalData
|
try await super.performAction(with: JSON, model: model, delegateObject: delegateObject, additionalData: MVMCoreUIActionHandler.removeSourceModel(from: additionalData))
|
||||||
additionalData?.removeValue(forKey: KeySourceModel)
|
|
||||||
try await super.performAction(with: JSON, model: model, delegateObject: delegateObject, additionalData: additionalData)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -98,10 +98,6 @@ import MVMCore
|
|||||||
guard let baseDropdownEntryFieldModel = baseDropdownEntryFieldModel,
|
guard let baseDropdownEntryFieldModel = baseDropdownEntryFieldModel,
|
||||||
let actionModel = baseDropdownEntryFieldModel.action
|
let actionModel = baseDropdownEntryFieldModel.action
|
||||||
else { return }
|
else { return }
|
||||||
|
MVMCoreUIActionHandler.performActionUnstructured(with: actionModel, sourceModel: baseDropdownEntryFieldModel, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: baseDropdownEntryFieldModel)
|
|
||||||
Task(priority: .userInitiated) {
|
|
||||||
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionModel, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -389,10 +389,7 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
private func performCheckboxAction(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
let additionalDataToUpdate = (checkboxModel != nil) ? additionalData.dictionaryAdding(key: KeySourceModel, value: checkboxModel!) : additionalData
|
MVMCoreUIActionHandler.performActionUnstructured(with: actionModel, sourceModel: checkboxModel, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
Task(priority: .userInitiated) {
|
|
||||||
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]?) {
|
||||||
|
|||||||
@ -390,21 +390,16 @@ public typealias ActionBlockConfirmation = () -> (Bool)
|
|||||||
accessibilityLabel = accessibileString
|
accessibilityLabel = accessibileString
|
||||||
}
|
}
|
||||||
|
|
||||||
let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: model)
|
|
||||||
if model.action != nil || model.alternateAction != nil {
|
if model.action != nil || model.alternateAction != nil {
|
||||||
didToggleAction = { [weak self] in
|
didToggleAction = { [weak self] in
|
||||||
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 {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
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 {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: additionalDataWithSource, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -387,9 +387,7 @@ 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)) {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: actionAtt.action, sourceModel: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
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,9 +259,7 @@ 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 {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: tabsModel, additionalData: nil, delegateObject: delegateObject)
|
||||||
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,13 +46,9 @@ public class AccordionMoleculeTableViewCell: MoleculeTableViewCell {
|
|||||||
model.selected = accordionButton.isSelected
|
model.selected = accordionButton.isSelected
|
||||||
|
|
||||||
if accordionButton.isSelected {
|
if accordionButton.isSelected {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: AddMoleculesActionModel(.automatic), sourceModel: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: AddMoleculesActionModel(.automatic), additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: RemoveMoleculesActionModel(.automatic), sourceModel: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
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) {
|
||||||
@ -60,9 +56,7 @@ public class AccordionMoleculeTableViewCell: MoleculeTableViewCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let actionModel = accordionButton.isSelected ? accordionListItemModel?.expandAction : accordionListItemModel?.collapseAction {
|
if let actionModel = accordionButton.isSelected ? accordionListItemModel?.expandAction : accordionListItemModel?.collapseAction {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: actionModel, sourceModel: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionModel, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import UIKit
|
|||||||
let self = self,
|
let self = self,
|
||||||
let model = self.listItemModel as? DropDownListItemModel else { return }
|
let model = self.listItemModel as? DropDownListItemModel else { return }
|
||||||
|
|
||||||
let additionData = [KeySourceModel: model]
|
|
||||||
var actions: [ActionModelProtocol] = []
|
var actions: [ActionModelProtocol] = []
|
||||||
if let oldValue = oldValue,
|
if let oldValue = oldValue,
|
||||||
oldValue.count > 0 {
|
oldValue.count > 0 {
|
||||||
@ -37,9 +36,7 @@ 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
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: actionsModel, sourceModel: model, additionalData: nil, delegateObject: self.delegateObject)
|
||||||
try await (self.delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: actionsModel, additionalData: additionData, delegateObject: self.delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -57,9 +57,7 @@ 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 {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: RemoveMoleculesActionModel(indexPath.row < tabs.selectedIndex ? .right : .left), sourceModel: model, additionalData: nil, delegateObject: delegateObject)
|
||||||
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
|
||||||
@ -70,13 +68,9 @@ 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 {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: model.tabs, additionalData: nil, delegateObject: delegateObject)
|
||||||
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.performActionUnstructured(with: AddMoleculesActionModel(index < previousTabIndex ? .left : .right), sourceModel: model, additionalData: nil, delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,9 +12,7 @@ import MVMCore
|
|||||||
@objcMembers open class NotificationXButton: Button {
|
@objcMembers open class NotificationXButton: Button {
|
||||||
|
|
||||||
open func closeTopAlert(with delegateObject: MVMCoreUIDelegateObject?) {
|
open func closeTopAlert(with delegateObject: MVMCoreUIDelegateObject?) {
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: ActionDismissNotificationModel(), sourceModel: model, additionalData: nil, delegateObject: delegateObject)
|
||||||
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: ActionDismissNotificationModel(), additionalData: nil, delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
|
|||||||
@ -32,9 +32,7 @@ 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()
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
||||||
try await (self.delegateObject()?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,9 +29,7 @@ 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()
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
||||||
try await (self.delegateObject()?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,9 +27,7 @@ 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()
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
||||||
try await (self.delegateObject()?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObject())
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,9 +32,8 @@ public typealias BarButtonAction = (BarButtonItem) -> ()
|
|||||||
self.model = model
|
self.model = model
|
||||||
buttonDelegate = delegateObject?.buttonDelegate
|
buttonDelegate = delegateObject?.buttonDelegate
|
||||||
actionDelegate?.buttonAction = { sender in
|
actionDelegate?.buttonAction = { sender in
|
||||||
let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: model)
|
|
||||||
Task(priority: .userInitiated) {
|
Task(priority: .userInitiated) {
|
||||||
try await Button.performButtonAction(with: model.action, button: sender, delegateObject: delegateObject, additionalData: additionalDataWithSource)
|
try await Button.performButtonAction(with: model.action, button: sender, delegateObject: delegateObject, additionalData: additionalData, sourceModel: model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,11 +88,7 @@ public typealias ButtonAction = (Button) -> ()
|
|||||||
|
|
||||||
open class func performButtonAction(with model: ActionModelProtocol, button: MFButtonProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, sourceModel: MoleculeModelProtocol? = nil) async throws {
|
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 }
|
guard delegateObject?.buttonDelegate?.button?(button, shouldPerformActionWithMap: model.toJSON(), additionalData: additionalData) ?? true else { return }
|
||||||
var additionalData = additionalData
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: model, additionalData: MVMCoreUIActionHandler.add(sourceModel: sourceModel, to: additionalData), delegateObject: delegateObject)
|
||||||
if let sourceModel = sourceModel {
|
|
||||||
additionalData = additionalData.dictionaryAdding(key: KeySourceModel, value: sourceModel)
|
|
||||||
}
|
|
||||||
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: model, additionalData: additionalData, delegateObject: delegateObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK:- MoleculeViewProtocol
|
// MARK:- MoleculeViewProtocol
|
||||||
|
|||||||
@ -419,7 +419,7 @@ import MVMCore
|
|||||||
|
|
||||||
/// Override this method to avoid adding form params.
|
/// Override this method to avoid adding form params.
|
||||||
open func addFormParams(requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, additionalData: [AnyHashable: Any]?) {
|
open func addFormParams(requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, additionalData: [AnyHashable: Any]?) {
|
||||||
formValidator?.addFormParams(requestParameters: requestParameters, model: additionalData?[KeySourceModel] as? MoleculeModelProtocol & FormItemProtocol)
|
formValidator?.addFormParams(requestParameters: requestParameters, model: MVMCoreUIActionHandler.getSourceModel(from: additionalData) as? MoleculeModelProtocol & FormItemProtocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func handleFieldErrors(_ fieldErrors: [Any]?, loadObject: MVMCoreLoadObject) {
|
public func handleFieldErrors(_ fieldErrors: [Any]?, loadObject: MVMCoreLoadObject) {
|
||||||
|
|||||||
@ -93,7 +93,7 @@ public class AddRemoveMoleculesBehavior: PageCustomActionHandlerBehavior, PageMo
|
|||||||
public func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) async throws {
|
public func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?) async throws {
|
||||||
if let model = model as? AddMoleculesActionModel,
|
if let model = model as? AddMoleculesActionModel,
|
||||||
let list = delegate?.moleculeListDelegate,
|
let list = delegate?.moleculeListDelegate,
|
||||||
let sourceModel = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & AddMolecules),
|
let sourceModel = MVMCoreUIActionHandler.getSourceModel(from: additionalData) as? (ListItemModelProtocol & MoleculeModelProtocol & AddMolecules),
|
||||||
let moleculesToAdd = sourceModel.getRecursiveMoleculesToAdd(),
|
let moleculesToAdd = sourceModel.getRecursiveMoleculesToAdd(),
|
||||||
let indexPath = list.getAdjustedIndexPath(for: sourceModel, position: moleculesToAdd.1) {
|
let indexPath = list.getAdjustedIndexPath(for: sourceModel, position: moleculesToAdd.1) {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
@ -101,7 +101,7 @@ public class AddRemoveMoleculesBehavior: PageCustomActionHandlerBehavior, PageMo
|
|||||||
}
|
}
|
||||||
} else if let model = model as? RemoveMoleculesActionModel,
|
} else if let model = model as? RemoveMoleculesActionModel,
|
||||||
let list = delegate?.moleculeListDelegate,
|
let list = delegate?.moleculeListDelegate,
|
||||||
let sourceModel = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & RemoveMolecules),
|
let sourceModel = MVMCoreUIActionHandler.getSourceModel(from: additionalData) as? (ListItemModelProtocol & MoleculeModelProtocol & RemoveMolecules),
|
||||||
let moleculesToRemove = sourceModel.getRecursiveMoleculesToRemove() {
|
let moleculesToRemove = sourceModel.getRecursiveMoleculesToRemove() {
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
list.removeMolecules(moleculesToRemove, animation: model.animation)
|
list.removeMolecules(moleculesToRemove, animation: model.animation)
|
||||||
|
|||||||
@ -145,7 +145,9 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
|||||||
|
|
||||||
open func shouldContinue(toErrorPage loadObject: MVMCoreLoadObject, error: MVMCoreErrorObject?) -> Bool {
|
open func shouldContinue(toErrorPage loadObject: MVMCoreLoadObject, error: MVMCoreErrorObject?) -> Bool {
|
||||||
// Push error screens so they do not replace the tab page.
|
// Push error screens so they do not replace the tab page.
|
||||||
loadObject.requestParameters?.navigationController = navigationController
|
MVMCoreDispatchUtility.performSyncBlock(onMainThread: {
|
||||||
|
loadObject.requestParameters?.navigationController = self.navigationController
|
||||||
|
})
|
||||||
loadObject.requestParameters?.loadStyle = .push
|
loadObject.requestParameters?.loadStyle = .push
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -160,7 +162,7 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
|||||||
|
|
||||||
/// Allow override of additioonal data for tab press action
|
/// Allow override of additioonal data for tab press action
|
||||||
open func getAdditionalDataForNewTabLoad(indexPath: IndexPath) -> [AnyHashable: Any]? {
|
open func getAdditionalDataForNewTabLoad(indexPath: IndexPath) -> [AnyHashable: Any]? {
|
||||||
return ["tabBarPressed": true, KeySourceModel: tabsModel]
|
return MVMCoreUIActionHandler.add(sourceModel: tabsModel, to: ["tabBarPressed": true])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allows modification of requestParameters object for openPage request
|
/// Allows modification of requestParameters object for openPage request
|
||||||
@ -273,9 +275,7 @@ 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
|
||||||
Task(priority: .userInitiated) {
|
MVMCoreUIActionHandler.performActionUnstructured(with: action, sourceModel: tabsModel, additionalData: getAdditionalDataForNewTabLoad(indexPath: indexPath), delegateObject: delegateObject())
|
||||||
try await (delegateObjectIVar.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: getAdditionalDataForNewTabLoad(indexPath: indexPath), delegateObject: delegateObjectIVar)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,16 +12,38 @@ import SafariServices
|
|||||||
|
|
||||||
@objc open class MVMCoreUIActionHandler: MVMCoreActionHandler {
|
@objc open class MVMCoreUIActionHandler: MVMCoreActionHandler {
|
||||||
|
|
||||||
|
/// Adds the source model to the additionalData
|
||||||
|
public static func add(sourceModel: MoleculeModelProtocol?, to additionalData: [AnyHashable: Any]?) -> [AnyHashable: Any]? {
|
||||||
|
guard let sourceModel = sourceModel else { return additionalData }
|
||||||
|
return additionalData.dictionaryAdding(key: KeySourceModel, value: sourceModel)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the source model from the additionalData
|
||||||
|
public static func getSourceModel(from additionalData: [AnyHashable: Any]?) -> MoleculeModelProtocol? {
|
||||||
|
return additionalData?[KeySourceModel] as? MoleculeModelProtocol
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the source model to the additionalData
|
||||||
|
public static func removeSourceModel(from additionalData: [AnyHashable: Any]?) -> [AnyHashable: Any]? {
|
||||||
|
guard var additionalData = additionalData else { return nil }
|
||||||
|
additionalData.removeValue(forKey: KeySourceModel)
|
||||||
|
return additionalData
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Starts the action in a task, adding the source model.
|
||||||
|
public static func performActionUnstructured(with model: ActionModelProtocol, sourceModel: MoleculeModelProtocol? = nil, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||||
|
Task(priority: .userInitiated) {
|
||||||
|
try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: model, additionalData: MVMCoreUIActionHandler.add(sourceModel: sourceModel, to: additionalData), delegateObject: delegateObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Logs the error and shows a popup if the error is not silent.
|
/// Logs the error and shows a popup if the error is not silent.
|
||||||
open override func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable : Any]?) {
|
open override func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable : Any]?) {
|
||||||
super.defaultHandleActionError(error, additionalData: additionalData)
|
super.defaultHandleActionError(error, additionalData: additionalData)
|
||||||
guard !error.silentError else { return }
|
guard !error.silentError else { return }
|
||||||
Task(priority: .userInitiated) {
|
Task(priority: .userInitiated) { @MainActor in
|
||||||
await MainActor.run {
|
let alertObject = MVMCoreAlertObject.init(popupAlertWithError: error, isGreedy: false)!
|
||||||
// Show alert
|
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
||||||
let alertObject = MVMCoreAlertObject.init(popupAlertWithError: error, isGreedy: false)!
|
|
||||||
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user