Skip to content

Commit 0db420b

Browse files
ivanvorobeiclaude
andcommitted
Simplify image dimming to pure tintColorDidChange swap
The previous approach tried to detect original vs desaturated images by comparing references in updateImageDimming(), which broke on undim: the method read the desaturated image back from contentConfiguration and overwrote the stored original with it. Now tintColorDidChange simply saves the original on dim and restores it on undim — no separate method, no flags, no heuristics. Cell providers no longer need to call updateImageDimming() manually. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0990bec commit 0db420b

File tree

3 files changed

+8
-27
lines changed

3 files changed

+8
-27
lines changed

Sources/DiffableKit/Table/Cells/DiffableButtonTableViewCell.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ open class DiffableButtonTableViewCell: DiffableTableViewCell {
1616
super.init(coder: coder)
1717
}
1818

19-
override func updateImageDimming() {
19+
open override func tintColorDidChange() {
20+
super.tintColorDidChange()
2021
guard var content = contentConfiguration as? UIListContentConfiguration else { return }
21-
let dimmed = tintAdjustmentMode == .dimmed
22-
let color: UIColor = dimmed ? .secondaryLabel : tintColor
23-
if content.textProperties.color != color {
24-
content.textProperties.color = color
25-
contentConfiguration = content
26-
}
27-
super.updateImageDimming()
22+
content.textProperties.color = tintAdjustmentMode == .dimmed ? .secondaryLabel : tintColor
23+
contentConfiguration = content
2824
}
2925

3026
open override func setHighlighted(_ highlighted: Bool, animated: Bool) {

Sources/DiffableKit/Table/Cells/DiffableTableViewCell.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,13 @@ open class DiffableTableViewCell: UITableViewCell {
2727

2828
open override func tintColorDidChange() {
2929
super.tintColorDidChange()
30-
updateImageDimming()
31-
}
32-
33-
func updateImageDimming() {
3430
guard var content = contentConfiguration as? UIListContentConfiguration else { return }
35-
if content.image !== originalImage {
31+
if tintAdjustmentMode == .dimmed {
3632
originalImage = content.image
37-
}
38-
let dimmed = tintAdjustmentMode == .dimmed
39-
if dimmed {
40-
guard let desaturated = originalImage?.desaturated() else { return }
41-
content.image = desaturated
42-
} else {
43-
guard let original = originalImage else { return }
33+
content.image = originalImage?.desaturated()
34+
} else if let original = originalImage {
4435
content.image = original
36+
originalImage = nil
4537
}
4638
contentConfiguration = content
4739
}

Sources/DiffableKit/Table/DataSource/DiffableTableDataSource+CellProvider.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ extension DiffableTableDataSource {
5151
content.image = item.icon
5252
applyImageLayout(&content)
5353
cell.contentConfiguration = content
54-
cell.updateImageDimming()
5554
cell.accessoryType = item.accessoryType
5655
cell.selectionStyle = item.selectionStyle
5756
return cell
@@ -68,7 +67,6 @@ extension DiffableTableDataSource {
6867
content.image = item.icon
6968
applyImageLayout(&content)
7069
cell.contentConfiguration = content
71-
cell.updateImageDimming()
7270
cell.accessoryType = item.accessoryType
7371
cell.selectionStyle = item.selectionStyle
7472
return cell
@@ -87,7 +85,6 @@ extension DiffableTableDataSource {
8785
let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
8886
content.textProperties.font = UIFont.systemFont(ofSize: descriptor.pointSize, weight: .medium)
8987
cell.contentConfiguration = content
90-
cell.updateImageDimming()
9188
cell.accessoryType = item.accessoryType
9289
return cell
9390
}
@@ -102,8 +99,6 @@ extension DiffableTableDataSource {
10299
content.image = item.icon
103100
applyImageLayout(&content)
104101
cell.contentConfiguration = content
105-
cell.updateImageDimming()
106-
107102
if let control = cell.accessoryView as? DiffableSwitch {
108103
control.action = item.action
109104
control.isOn = item.isOn
@@ -127,8 +122,6 @@ extension DiffableTableDataSource {
127122
content.image = item.icon
128123
applyImageLayout(&content)
129124
cell.contentConfiguration = content
130-
cell.updateImageDimming()
131-
132125
if let control = cell.accessoryView as? DiffableStepper {
133126
control.action = item.action
134127
control.stepValue = item.stepValue

0 commit comments

Comments
 (0)