target issue fix
This commit is contained in:
parent
cbe1c04386
commit
bb50671711
@ -8,41 +8,51 @@
|
|||||||
|
|
||||||
public typealias BarButtonAction = (BarButtonItem) -> ()
|
public typealias BarButtonAction = (BarButtonItem) -> ()
|
||||||
|
|
||||||
@objcMembers open class BarButtonItem: UIBarButtonItem, MFButtonProtocol {
|
@objc fileprivate class ActionDelegate: NSObject {
|
||||||
//--------------------------------------------------
|
fileprivate var buttonAction: BarButtonAction?
|
||||||
// MARK: - Properties
|
@objc fileprivate func callActionBlock(_ sender: BarButtonItem) {
|
||||||
//--------------------------------------------------
|
buttonAction?(sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var buttonAction: BarButtonAction?
|
@objcMembers open class BarButtonItem: UIBarButtonItem, MFButtonProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Delegate
|
// MARK: - Delegate
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open weak var buttonDelegate: ButtonDelegateProtocol?
|
open weak var buttonDelegate: ButtonDelegateProtocol?
|
||||||
|
private var actionObject: ActionDelegate?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
public static func create(with image: UIImage) -> Self {
|
||||||
|
let actionObject = ActionDelegate()
|
||||||
|
let button = self.init(image: image, style: .plain, target: actionObject, action: #selector(actionObject.callActionBlock(_:)))
|
||||||
|
button.actionObject = actionObject
|
||||||
|
return button
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates the item with the passed in action.
|
/// Creates the item with the passed in action.
|
||||||
public static func create(with image: UIImage, actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
|
public static func create(with image: UIImage, actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
|
||||||
let button = self.init(image: image, style: .plain, target: self, action: #selector(callActionBlock(_:)))
|
let button = create(with: image)
|
||||||
button.set(with: actionModel, delegateObject: delegateObject, additionalData: additionalData)
|
button.set(with: actionModel, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the item with the passed in action map.
|
/// Creates the item with the passed in action map.
|
||||||
public static func create(with image: UIImage, actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
|
public static func create(with image: UIImage, actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
|
||||||
let button = self.init(image: image, style: .plain, target: self, action: #selector(callActionBlock(_:)))
|
let button = create(with: image)
|
||||||
button.set(with: actionMap, delegateObject: delegateObject, additionalData: additionalData)
|
button.set(with: actionMap, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the item with the passed in action.
|
/// Creates the item with the passed in action.
|
||||||
public static func create(with image: UIImage, action: @escaping BarButtonAction) -> Self {
|
public static func create(with image: UIImage, action: @escaping BarButtonAction) -> Self {
|
||||||
let button = self.init(image: image, style: .plain, target: self, action: #selector(callActionBlock(_:)))
|
let button = create(with: image)
|
||||||
button.buttonAction = action
|
button.actionObject?.buttonAction = action
|
||||||
return button
|
return button
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,13 +60,9 @@ public typealias BarButtonAction = (BarButtonItem) -> ()
|
|||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
@objc func callActionBlock(_ sender: BarButtonItem) {
|
|
||||||
buttonAction?(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
open func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
buttonDelegate = delegateObject?.buttonDelegate
|
buttonDelegate = delegateObject?.buttonDelegate
|
||||||
buttonAction = { [weak self] sender in
|
actionObject?.buttonAction = { [weak self] sender in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
if let data = try? actionModel.encode(using: JSONEncoder()),
|
if let data = try? actionModel.encode(using: JSONEncoder()),
|
||||||
let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any],
|
let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any],
|
||||||
@ -68,7 +74,7 @@ public typealias BarButtonAction = (BarButtonItem) -> ()
|
|||||||
|
|
||||||
open func set(with actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
open func set(with actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
buttonDelegate = delegateObject?.buttonDelegate
|
buttonDelegate = delegateObject?.buttonDelegate
|
||||||
buttonAction = { [weak self] sender in
|
actionObject?.buttonAction = { [weak self] sender in
|
||||||
guard let self = self,
|
guard let self = self,
|
||||||
delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true else { return }
|
delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true else { return }
|
||||||
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user