modifying image rendering changes in navigation bar
This commit is contained in:
parent
0c54273066
commit
d10332b372
@ -12,17 +12,16 @@
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
|
||||
public static func create(with image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic) -> Self {
|
||||
public static func create(with image: UIImage?) -> Self {
|
||||
let actionObject = ActionDelegate()
|
||||
let button = self.init(image: image?.withRenderingMode(renderingMode), style: .plain, target: actionObject, action: #selector(actionObject.callActionBlock))
|
||||
let button = self.init(image: image, style: .plain, target: actionObject, action: #selector(actionObject.callActionBlock))
|
||||
button.actionDelegate = actionObject
|
||||
return button
|
||||
}
|
||||
|
||||
/// Creates the item with the passed in action.
|
||||
public static func create(with image: UIImage?, model: MoleculeModelProtocol & NavigationButtonModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self {
|
||||
let imageModel = model as? NavigationImageButtonModel
|
||||
let button = create(with: image, renderingMode: imageModel?.imageRenderingMode ?? .alwaysTemplate)
|
||||
let button = create(with: image)
|
||||
button.set(with: model, delegateObject: delegateObject, additionalData: additionalData)
|
||||
return button
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
|
||||
public var image: String
|
||||
public var action: ActionModelProtocol
|
||||
public var accessibilityText: String?
|
||||
public var imageRenderingMode: UIImage.RenderingMode?
|
||||
public var imageRenderingMode: UIImage.RenderingMode = .automatic
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
@ -53,7 +53,9 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
|
||||
image = try typeContainer.decode(String.self, forKey: .image)
|
||||
action = try typeContainer.decodeModel(codingKey: .action)
|
||||
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
||||
imageRenderingMode = try typeContainer.decodeIfPresent(UIImage.RenderingMode.self, forKey: .imageRenderingMode)
|
||||
if let mode = try typeContainer.decodeIfPresent(UIImage.RenderingMode.self, forKey: .imageRenderingMode) {
|
||||
imageRenderingMode = mode
|
||||
}
|
||||
}
|
||||
|
||||
open func encode(to encoder: Encoder) throws {
|
||||
@ -72,7 +74,7 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
|
||||
|
||||
/// Convenience function that creates a BarButtonItem for the model.
|
||||
public func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> UIBarButtonItem {
|
||||
let uiImage = MVMCoreCache.shared()?.getImageFromRegisteredBundles(image)
|
||||
let uiImage = MVMCoreCache.shared()?.getImageFromRegisteredBundles(image)?.withRenderingMode(imageRenderingMode)
|
||||
let buttonItem = ImageBarButtonItem.create(with: uiImage, model: self, delegateObject: delegateObject, additionalData: additionalData)
|
||||
buttonItem.accessibilityIdentifier = accessibilityIdentifier ?? image
|
||||
if let accessibilityString = accessibilityText {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user