Skip to content

Commit 20dcf95

Browse files
ivanvorobeiclaude
andcommitted
Fix image dimming stuck after modal dismiss
tintColorDidChange could overwrite originalImage with an already desaturated version on repeated calls while dimmed, so restoring the "original" on undim produced a grey icon. Split write/read paths: only cell providers save the original image, tintColorDidChange only reads it. Keep originalImage alive across dimmed/normal transitions until prepareForReuse. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 31baa7e commit 20dcf95

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

Sources/DiffableKit/Table/Cells/DiffableButtonTableViewCell.swift

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

19-
override func updateImageDimming() {
19+
override func updateImageDimming(saveOriginal: Bool = false) {
2020
guard var content = contentConfiguration as? UIListContentConfiguration else { return }
2121
let dimmed = tintAdjustmentMode == .dimmed
2222
let color: UIColor = dimmed ? .secondaryLabel : tintColor
2323
if content.textProperties.color != color {
2424
content.textProperties.color = color
2525
contentConfiguration = content
2626
}
27-
super.updateImageDimming()
27+
super.updateImageDimming(saveOriginal: saveOriginal)
2828
}
2929

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

Sources/DiffableKit/Table/Cells/DiffableTableViewCell.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@ open class DiffableTableViewCell: UITableViewCell {
3030
updateImageDimming()
3131
}
3232

33-
func updateImageDimming() {
33+
func updateImageDimming(saveOriginal: Bool = false) {
3434
guard var content = contentConfiguration as? UIListContentConfiguration else { return }
35+
if saveOriginal { originalImage = content.image }
3536
let dimmed = tintAdjustmentMode == .dimmed
3637
if dimmed {
37-
let currentImage = content.image
38-
if currentImage !== originalImage { originalImage = currentImage }
3938
guard let desaturated = originalImage?.desaturated() else { return }
4039
content.image = desaturated
4140
} else {
4241
guard let original = originalImage else { return }
4342
content.image = original
44-
originalImage = nil
4543
}
4644
contentConfiguration = content
4745
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension DiffableTableDataSource {
5151
content.image = item.icon
5252
applyImageLayout(&content)
5353
cell.contentConfiguration = content
54-
cell.updateImageDimming()
54+
cell.updateImageDimming(saveOriginal: true)
5555
cell.accessoryType = item.accessoryType
5656
cell.selectionStyle = item.selectionStyle
5757
return cell
@@ -68,7 +68,7 @@ extension DiffableTableDataSource {
6868
content.image = item.icon
6969
applyImageLayout(&content)
7070
cell.contentConfiguration = content
71-
cell.updateImageDimming()
71+
cell.updateImageDimming(saveOriginal: true)
7272
cell.accessoryType = item.accessoryType
7373
cell.selectionStyle = item.selectionStyle
7474
return cell
@@ -87,7 +87,7 @@ extension DiffableTableDataSource {
8787
let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
8888
content.textProperties.font = UIFont.systemFont(ofSize: descriptor.pointSize, weight: .medium)
8989
cell.contentConfiguration = content
90-
cell.updateImageDimming()
90+
cell.updateImageDimming(saveOriginal: true)
9191
cell.accessoryType = item.accessoryType
9292
return cell
9393
}
@@ -102,7 +102,7 @@ extension DiffableTableDataSource {
102102
content.image = item.icon
103103
applyImageLayout(&content)
104104
cell.contentConfiguration = content
105-
cell.updateImageDimming()
105+
cell.updateImageDimming(saveOriginal: true)
106106

107107
if let control = cell.accessoryView as? DiffableSwitch {
108108
control.action = item.action
@@ -127,7 +127,7 @@ extension DiffableTableDataSource {
127127
content.image = item.icon
128128
applyImageLayout(&content)
129129
cell.contentConfiguration = content
130-
cell.updateImageDimming()
130+
cell.updateImageDimming(saveOriginal: true)
131131

132132
if let control = cell.accessoryView as? DiffableStepper {
133133
control.action = item.action

0 commit comments

Comments
 (0)