modifying image rendering changes in navigation bar

This commit is contained in:
Sumanth Nadigadda 2022-04-04 22:24:50 +05:30
parent 0c54273066
commit d10332b372
2 changed files with 8 additions and 7 deletions

View File

@ -12,17 +12,16 @@
// MARK: - Initializers // 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 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 button.actionDelegate = actionObject
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?, model: MoleculeModelProtocol & NavigationButtonModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) -> Self { 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)
let button = create(with: image, renderingMode: imageModel?.imageRenderingMode ?? .alwaysTemplate)
button.set(with: model, delegateObject: delegateObject, additionalData: additionalData) button.set(with: model, delegateObject: delegateObject, additionalData: additionalData)
return button return button
} }

View File

@ -19,7 +19,7 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
public var image: String public var image: String
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var accessibilityText: String? public var accessibilityText: String?
public var imageRenderingMode: UIImage.RenderingMode? public var imageRenderingMode: UIImage.RenderingMode = .automatic
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
@ -53,7 +53,9 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
image = try typeContainer.decode(String.self, forKey: .image) image = try typeContainer.decode(String.self, forKey: .image)
action = try typeContainer.decodeModel(codingKey: .action) action = try typeContainer.decodeModel(codingKey: .action)
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) 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 { 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. /// 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)?.withRenderingMode(imageRenderingMode)
let buttonItem = ImageBarButtonItem.create(with: uiImage, model: self, 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 {