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

Blackout #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Blackout #1

wants to merge 5 commits into from

Conversation

minimusic
Copy link

Probably a mess, but tried to minimize customizing changes (but there are a few, like commenting out the "de-select" code to turn off that feature).

selectedIndexPaths.remove(at: index)
selectedDates.remove(at: index)
// We want to prevent deselecting ship date
// delegate?.calendar(self, didDeselectDate: date)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could make this more mergeable with another delegate method:

if delegate?.calendar(self, canDeselectDate: date) ?? false {
  delegate?.calendar(self, didDeselectDate: date)
  selectedIndexPaths.remove(at: index)
  selectedDates.remove(at: index)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another "too big of a refactor" where I think the correct generalization would be a SelectionMode enum with an .alwaysOneSelectedDay option. The delegate method rings false since everything CAN be deselected, but only by selecting something else.

@@ -117,7 +117,7 @@ extension CalendarView: UICollectionViewDataSource {
}
if let delegate = self.delegate, let dateBeingSelected = self.dateFromIndexPath(indexPath) {
if delegate.calendar(self, canSelectDate: dateBeingSelected) == false {
dayCell.isWeekend = true
dayCell.isBlackout = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to add backwards compatibility for isWeekend?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally trying to re-purpose isWeekend to give us our blackout behavior, and this is actually un-doing that. isWeekend should be back to normal now, and un-used by our app. We set .marksWeekends to false now.

@@ -81,7 +81,7 @@ public class CalendarView: UIView {

public lazy var calendar: Calendar = {
var gregorian = Calendar(identifier: .gregorian)
gregorian.timeZone = TimeZone(abbreviation: "UTC")!
//gregorian.timeZone = TimeZone(abbreviation: "UTC")!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the Calendar should always be in the user's current time zone?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in the timezone of the shipping facility, if known, but this fixes an off-by-one error since it handles day-dates as "midnight". There is a lot of clean-up that could improve this, but it'd be a large refactor on the pod.

@@ -118,6 +118,17 @@ public class CalendarView: UIView {
return calFlowLayout
}

// var startOfMonth = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed? Can a shim be used for backwards compatibility?

@@ -329,8 +340,10 @@ extension CalendarView {
function: - scroll calendar at date (month/year) passed as parameter.
*/
public func setDisplayDate(_ date: Date, animated: Bool = false) {

guard (date >= startDateCache) && (date <= endDateCache) else { return }
print("startOfMonthCache = \(startOfMonthCache)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray print statements

public func isLastMonth() -> Bool {
var dateComponents = DateComponents()
dateComponents.month = 1
print("isLastMonth")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray print statements

@@ -380,6 +408,18 @@ extension CalendarView {
goToMonthWithOffet(-1)
}

public func isFirstMonth() -> Bool {
var dateComponents = DateComponents()
dateComponents.month = -1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My favorite month of the year is -1

@chrisballinger
Copy link

Looks good! Main cleanup is just a few stray comments and print statements. Thoughts on upstreaming this code would be good but not necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants