Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection issue in xCode13 / iOS15 #145

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions KDCalendar/CalendarView/CalendarDayCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ open class CalendarDayCell: UICollectionViewCell {
}

func updateTextColor() {
if isPicked {
if isSelected {
self.textLabel.textColor = style.cellSelectedTextColor
}
else if isToday {
Expand Down Expand Up @@ -104,9 +104,9 @@ open class CalendarDayCell: UICollectionViewCell {
}
}

open var isPicked : Bool = false {
open override var isSelected : Bool {
didSet {
switch isPicked {
switch isSelected {
case true:
self.bgView.layer.borderColor = style.cellSelectedBorderColor.cgColor
self.bgView.layer.borderWidth = style.cellSelectedBorderWidth
Expand Down
6 changes: 5 additions & 1 deletion KDCalendar/CalendarView/CalendarView+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ extension CalendarView: UICollectionViewDataSource {
dayCell.isToday = (idx.section == indexPath.section && idx.item + firstDayIndex == indexPath.item)
}

dayCell.isPicked = selectedIndexPaths.contains(indexPath)
dayCell.isSelected = selectedIndexPaths.contains(indexPath)
// Here is why: https://stackoverflow.com/a/31387259
if dayCell.isSelected {
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)
}

if self.marksWeekends {
let we = indexPath.item % 7
Expand Down
3 changes: 2 additions & 1 deletion KDCalendar/CalendarView/CalendarView+Delegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ extension CalendarView: UICollectionViewDelegateFlowLayout {

selectedIndexPaths.append(indexPath)
selectedDates.append(date)
currentCell.isPicked = true
currentCell.isSelected = true
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)

let eventsForDaySelected = eventsByIndexPath[indexPath] ?? []
delegate?.calendar(self, didSelectDate: date, withEvents: eventsForDaySelected)
Expand Down