From cb8fc9efa2681d7a29ad561ceb1515f639fd86ad Mon Sep 17 00:00:00 2001 From: Jarrod Courtney Date: Tue, 15 Oct 2024 14:52:39 -0500 Subject: [PATCH] Signed-off-by: Jarrod Courtney --- .../Atomic/Atoms/Buttons/ImageButton.swift | 6 ++++-- .../Atomic/Atoms/Views/ImageViewModel.swift | 2 ++ .../Atomic/Atoms/Views/LoadImageView.swift | 20 +++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift index dfce1882..ffbcf84f 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift @@ -7,6 +7,7 @@ // import Foundation +import VDSCoreTokens @objcMembers open class ImageButton: Button { @@ -24,6 +25,7 @@ import Foundation super.set(with: model, delegateObject, additionalData) return } + image.setOptional(with: castModel.image, delegateObject, additionalData) castModel.updateUI = { [weak self] in MVMCoreDispatchUtility.performBlock(onMainThread: { @@ -42,10 +44,10 @@ import Foundation } if castModel.enabled { if let enabledTintColor = castModel.enabledTintColor { - image.imageView.tintColor = enabledTintColor.uiColor + image.tintColor = enabledTintColor.uiColor } } else if let disabledTintColor = castModel.disabledTintColor { - image.imageView.tintColor = disabledTintColor.uiColor + image.tintColor = disabledTintColor.uiColor } if let traits = model?.accessibilityTraits { accessibilityTraits = traits diff --git a/MVMCoreUI/Atomic/Atoms/Views/ImageViewModel.swift b/MVMCoreUI/Atomic/Atoms/Views/ImageViewModel.swift index e39c5b37..fb2d5127 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/ImageViewModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/ImageViewModel.swift @@ -30,6 +30,7 @@ public var clipsImage: Bool? public var allowServerParameters: Bool? public var shouldMaskRecordedView: Bool? = false + public var tintColor: Color? //-------------------------------------------------- // MARK: - Initializer @@ -62,6 +63,7 @@ case clipsImage case shouldMaskRecordedView case allowServerParameters + case tintColor } public func isEqual(to model: any ModelComparisonProtocol) -> Bool { diff --git a/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift b/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift index 780f8829..8d47cabd 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift @@ -36,6 +36,7 @@ private var currentImageHeight: CGFloat? private var currentImageName: String? private var isFallbackImage: Bool = false + private var renderingMode: UIImage.RenderingMode = .automatic private var containerHelper = ContainerHelper() @@ -44,6 +45,12 @@ set { imageView.accessibilityLabel = newValue } } + open override var tintColor: UIColor! { + didSet { + renderingMode = tintColor != nil ? .alwaysTemplate : .automatic + } + } + //-------------------------------------------------- // MARK: - Constraint Properties //-------------------------------------------------- @@ -127,12 +134,13 @@ open func defaultCompletionBlock() -> MVMCoreGetImageBlock { return { image, gifData,_ in MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in + guard let self else { return } if let image = image { - self?.imageView.image = image - self?.layoutIfNeeded() + imageView.image = image.withRenderingMode(renderingMode) + layoutIfNeeded() } else if let gifData = gifData { - self?.imageView.loadGifWithData(gifData) - self?.layoutIfNeeded() + imageView.loadGifWithData(gifData) + layoutIfNeeded() } })} } @@ -274,6 +282,10 @@ imageView.isAccessibilityElement = true } + if let color = imageModel.tintColor?.uiColor { + tintColor = color + } + let width = imageModel.width ?? imageWidth let height = imageModel.height ?? imageHeight