navigation bar changes

This commit is contained in:
Pfeil, Scott Robert 2021-07-16 20:54:33 -04:00
parent bcf810d5cb
commit d00897cf75
5 changed files with 18 additions and 38 deletions

View File

@ -20,16 +20,9 @@
} }
/// 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?, model: MoleculeModelProtocol & NavigationButtonModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
let button = create(with: image) let button = create(with: image)
button.set(with: actionModel, delegateObject: delegateObject, additionalData: additionalData) button.set(with: model, delegateObject: delegateObject, additionalData: additionalData)
return button
}
/// 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 {
let button = create(with: image)
button.set(with: actionMap, delegateObject: delegateObject, additionalData: additionalData)
return button return button
} }

View File

@ -21,16 +21,9 @@
} }
/// Creates the item with the passed in action. /// Creates the item with the passed in action.
public static func create(with title: String?, actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self { public static func create(with title: String?, model: NavigationLabelButtonModel, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
let button = create(with: title) let button = create(with: title)
button.set(with: actionModel, delegateObject: delegateObject, additionalData: additionalData) button.set(with: model, delegateObject: delegateObject, additionalData: additionalData)
return button
}
/// Creates the item with the passed in action map.
public static func create(with title: String?, actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
let button = create(with: title)
button.set(with: actionMap, delegateObject: delegateObject, additionalData: additionalData)
return button return button
} }

View File

@ -67,7 +67,7 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
/// Convenience function that creates a BarButtonItem for the model. /// Convenience function that creates a BarButtonItem for the model.
public func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> UIBarButtonItem { public func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> UIBarButtonItem {
let uiImage = MVMCoreCache.shared()?.getImageFromRegisteredBundles(image) let uiImage = MVMCoreCache.shared()?.getImageFromRegisteredBundles(image)
let buttonItem = ImageBarButtonItem.create(with: uiImage, actionModel: action, delegateObject: delegateObject, additionalData: additionalData) let buttonItem = ImageBarButtonItem.create(with: uiImage, model: self, delegateObject: delegateObject, additionalData: additionalData)
buttonItem.accessibilityIdentifier = accessibilityIdentifier ?? image buttonItem.accessibilityIdentifier = accessibilityIdentifier ?? image
if let accessibilityString = accessibilityText { if let accessibilityString = accessibilityText {
buttonItem.accessibilityLabel = accessibilityString buttonItem.accessibilityLabel = accessibilityString

View File

@ -7,16 +7,16 @@
// //
public class NavigationLabelButtonModel: NavigationButtonModelProtocol, MoleculeModelProtocol { open class NavigationLabelButtonModel: NavigationButtonModelProtocol, MoleculeModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
public var backgroundColor: Color? open var backgroundColor: Color?
public static var identifier: String = "navigationLabelButton" open class var identifier: String { "navigationLabelButton" }
public var accessibilityIdentifier: String? open var accessibilityIdentifier: String?
public var title: String open var title: String
public var action: ActionModelProtocol open var action: ActionModelProtocol
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
@ -62,7 +62,7 @@ public class NavigationLabelButtonModel: NavigationButtonModelProtocol, Molecule
//-------------------------------------------------- //--------------------------------------------------
/// Convenience function that creates a BarButtonItem for the model. /// Convenience function that creates a BarButtonItem for the model.
public func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> UIBarButtonItem { open func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> UIBarButtonItem {
return LabelBarButtonItem.create(with: title, actionModel: action, delegateObject: delegateObject, additionalData: additionalData) return LabelBarButtonItem.create(with: title, model: self, delegateObject: delegateObject, additionalData: additionalData)
} }
} }

View File

@ -20,7 +20,7 @@ public typealias BarButtonAction = (BarButtonItem) -> ()
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Delegate // MARK: - Delegate
//-------------------------------------------------- //--------------------------------------------------
open var model: (MoleculeModelProtocol & NavigationButtonModelProtocol)?
open weak var buttonDelegate: ButtonDelegateProtocol? open weak var buttonDelegate: ButtonDelegateProtocol?
var actionDelegate: ActionDelegate? var actionDelegate: ActionDelegate?
@ -28,18 +28,12 @@ public typealias BarButtonAction = (BarButtonItem) -> ()
// MARK: - Methods // MARK: - Methods
//-------------------------------------------------- //--------------------------------------------------
open func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { open func set(with model: MoleculeModelProtocol & NavigationButtonModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
self.model = model
buttonDelegate = delegateObject?.buttonDelegate buttonDelegate = delegateObject?.buttonDelegate
actionDelegate?.buttonAction = { sender in actionDelegate?.buttonAction = { sender in
Button.performButtonAction(with: actionModel, button: sender, delegateObject: delegateObject, additionalData: additionalData) let additionalDataWithSource = additionalData.dictionaryAdding(key: KeySourceModel, value: model)
} Button.performButtonAction(with: model.action, button: sender, delegateObject: delegateObject, additionalData: additionalDataWithSource)
}
open func set(with actionMap: [AnyHashable : Any], delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
buttonDelegate = delegateObject?.buttonDelegate
actionDelegate?.buttonAction = { sender in
guard delegateObject?.buttonDelegate?.button?(sender, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true else { return }
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
} }
} }
} }