44 lines
1.6 KiB
Swift
44 lines
1.6 KiB
Swift
//
|
|
// BarButtonItem.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 5/18/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
public typealias BarButtonAction = (BarButtonItem) -> ()
|
|
|
|
|
|
@objc class ActionDelegate: NSObject {
|
|
var buttonAction: BarButtonAction?
|
|
@objc func callActionBlock(_ sender: BarButtonItem) {
|
|
buttonAction?(sender)
|
|
}
|
|
}
|
|
|
|
@objcMembers open class BarButtonItem: UIBarButtonItem, MFButtonProtocol {
|
|
//--------------------------------------------------
|
|
// MARK: - Delegate
|
|
//--------------------------------------------------
|
|
open var model: (MoleculeModelProtocol & NavigationButtonModelProtocol)?
|
|
open weak var buttonDelegate: ButtonDelegateProtocol?
|
|
var actionDelegate: ActionDelegate?
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Methods
|
|
//--------------------------------------------------
|
|
|
|
open func set(with model: MoleculeModelProtocol & NavigationButtonModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
self.model = model
|
|
if let accessibilityIdentifier = model.accessibilityIdentifier {
|
|
self.accessibilityIdentifier = accessibilityIdentifier
|
|
}
|
|
buttonDelegate = delegateObject?.buttonDelegate
|
|
actionDelegate?.buttonAction = { sender in
|
|
Task(priority: .userInitiated) {
|
|
try await Button.performButtonAction(with: model.action, button: sender, delegateObject: delegateObject, additionalData: additionalData, sourceModel: model)
|
|
}
|
|
}
|
|
}
|
|
}
|