Skip to content

Commit

Permalink
Only toggle the checkmark for CollapsableHeaderCollectionViewCells an…
Browse files Browse the repository at this point in the history
…d remove the selection when dismissing the preview view.
  • Loading branch information
twstokes committed May 4, 2022
1 parent d37f4e4 commit 8b0e649
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class CollapsableHeaderCollectionViewCell: UICollectionViewCell {
}
}

/// Set to `true` to disable showing visual decorations like a checkmark or border when a cell is selected.
var selectionDecorationsHidden = false
var showsCheckMarkWhenSelected = true

override func prepareForReuse() {
super.prepareForReuse()
Expand Down Expand Up @@ -95,12 +94,6 @@ class CollapsableHeaderCollectionViewCell: UICollectionViewCell {
}

private func styleSelectedBorder(animated: Bool = false) {
guard !selectionDecorationsHidden else {
imageView.layer.borderColor = borderColor.cgColor
imageView.layer.borderWidth = borderWith
return
}

let imageBorderColor = isSelected ? accentColor.cgColor : borderColor.cgColor
let imageBorderWidth = isSelected ? 2 : borderWith
guard animated else {
Expand All @@ -126,7 +119,7 @@ class CollapsableHeaderCollectionViewCell: UICollectionViewCell {
}

private func checkmarkHidden(_ isHidden: Bool, animated: Bool = false) {
guard !selectionDecorationsHidden else {
guard showsCheckMarkWhenSelected else {
checkmarkContainerView.isHidden = true
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class CategorySectionTableViewCell: UITableViewCell {
}

var isGhostCell: Bool = false
/// Set to `true` to disable showing visual decorations like a checkmark or border when a cell is selected.
var selectionDecorationsHidden = false
var showsCheckMarkWhenSelected = true

override func prepareForReuse() {
section?.scrollOffset = collectionView.contentOffset
Expand Down Expand Up @@ -92,6 +91,7 @@ extension CategorySectionTableViewCell: UICollectionViewDelegate {
deselectItem(indexPath)
return false
}

return true
}

Expand Down Expand Up @@ -128,7 +128,7 @@ extension CategorySectionTableViewCell: UICollectionViewDataSource {

let thumbnail = thumbnails[indexPath.row]
cell.previewURL = thumbnailUrl(forThumbnail: thumbnail)
cell.selectionDecorationsHidden = selectionDecorationsHidden
cell.showsCheckMarkWhenSelected = showsCheckMarkWhenSelected
cell.isAccessibilityElement = true
cell.accessibilityLabel = thumbnail.slug
return cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extension SiteDesignContentCollectionViewController: UITableViewDataSource {
cell.selectionStyle = UITableViewCell.SelectionStyle.none
cell.section = isLoading ? nil : sections[indexPath.row]
cell.isGhostCell = isLoading
cell.selectionDecorationsHidden = true
cell.showsCheckMarkWhenSelected = false
cell.layer.masksToBounds = false
cell.clipsToBounds = false
cell.collectionView.allowsSelection = !isLoading
Expand All @@ -182,6 +182,7 @@ extension SiteDesignContentCollectionViewController: CategorySectionTableViewCel
createsSite: createsSite,
onDismissWithDeviceSelected: { [weak self] device in
self?.previewViewSelectedPreviewDevice = device
cell.deselectItems()
},
completion: completion
)
Expand Down

0 comments on commit 8b0e649

Please sign in to comment.