Skip to content

Commit

Permalink
Add highlight styling to list style (#1919)
Browse files Browse the repository at this point in the history
# Summary

Added the ability to customize highlighted (tapped state) background
color of List Items. Previously, it was locked to the default OS value.

# What problem you’re solving

Unable to change the highlighted background color of list items.

# Your approach to fixing the problem

Added a style property to `ListItemStyle` - as an optional value,
because the default value is OS protected and can only be approximated.
This also means it won't result in any changes to existing
implementations.

# Any tests you wrote

As a highlighted state that only occurs on tapping, I did not see a way
to integrate with snapshot tests. Happy to add some if someone can point
me in the right direction.

# Release notes
<changed>
You can now highlight a list item by changing its background color when
the shopper selects it. To do this, use the new optional
`ListItemStyle.highlightedBackgroundColor` property.
</changed>
  • Loading branch information
nauaros authored Jan 6, 2025
2 parents 860ac8e + 64743ca commit cd1f1b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Adyen/UI/List/ListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public final class ListCell: UITableViewCell {
fatalError("init(coder:) has not been implemented")
}

override public func setHighlighted(_ highlighted: Bool, animated: Bool) {
super.setHighlighted(highlighted, animated: animated)

guard let highlightedBackgroundColor = item?.style.highlightedBackgroundColor else {
return
}

contentView.backgroundColor = highlighted ? highlightedBackgroundColor : item?.style.backgroundColor
}

// MARK: - Item

/// The item displayed in the cell cell.
Expand Down
3 changes: 3 additions & 0 deletions Adyen/UI/List/ListItemStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public struct ListItemStyle: ViewStyle {

public var backgroundColor = UIColor.Adyen.componentBackground

/// Background color when highlighted (tapped).
public var highlightedBackgroundColor: UIColor?

/// Initializes the list item style.
///
/// - Parameter title: The title style.
Expand Down

0 comments on commit cd1f1b1

Please sign in to comment.