Skip to content

Commit

Permalink
Remove SelectionTypeLeading and SelectionTypeTrailing and group t…
Browse files Browse the repository at this point in the history
…hat highlighting logic under `wholeMonthSelection`.
  • Loading branch information
Gerardo Garrido committed Jun 20, 2022
1 parent 38f08f8 commit 2130e77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
13 changes: 8 additions & 5 deletions Backpack/Calendar/Classes/BPKCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -682,19 +682,22 @@ - (void)configureCell:(FSCalendarCell *)cell forDate:(NSDate *)date atMonthPosit
if (monthPosition == FSCalendarMonthPositionCurrent) {
SelectionType selectionType = SelectionTypeNone;
RowType rowType = RowTypeMiddle;
BOOL wholeMonthSelection = NO;

if (self.isSelectingWholeMonth) {
rowType = [self rowTypeForDate:date amongRangeOfDates:sortedSelectedDates];
selectionType = [self selectionTypeForDate:date amongRangeOfDates:sortedSelectedDates withBorder:NO];
selectionType = [self selectionTypeForDate:date amongRangeOfDates:sortedSelectedDates];
wholeMonthSelection = [self isDate:date betweenRangeOfDates:sortedSelectedDates];
} else if (!self.sameDayRange && sortedSelectedDates.count > 1 && self.selectionConfiguration.isRangeStyleSelection) {
rowType = [self rowTypeForDate:date amongRangeOfDates:sortedSelectedDates];
selectionType = [self selectionTypeForDate:date amongRangeOfDates:sortedSelectedDates withBorder:YES];
selectionType = [self selectionTypeForDate:date amongRangeOfDates:sortedSelectedDates];
} else if ([sortedSelectedDates containsObject:date]) {
selectionType = self.sameDayRange ? SelectionTypeSameDay : SelectionTypeSingle;
}

calendarCell.selectionType = selectionType;
calendarCell.rowType = rowType;
calendarCell.wholeMonthSelection = wholeMonthSelection;
NSString *baseAccessibilityLabel = [calendarCell defaultAccessibilityLabelForDate:date formatter:self.dateFormatter];
calendarCell.accessibilityLabel = [self.selectionConfiguration accessibilityLabelForDate:date
selectedDates:sortedSelectedDates
Expand Down Expand Up @@ -806,17 +809,17 @@ - (RowType)rowTypeForDate:(NSDate *)date amongRangeOfDates:(NSArray<NSDate *> *)
}
}

- (SelectionType)selectionTypeForDate:(NSDate *)date amongRangeOfDates:(NSArray<NSDate *> *)datesRange withBorder:(BOOL)hasBorder {
- (SelectionType)selectionTypeForDate:(NSDate *)date amongRangeOfDates:(NSArray<NSDate *> *)datesRange {
if ([self isDate:date betweenRangeOfDates:datesRange]) {
NSDate *minDate = [datesRange firstObject];
NSDate *maxDate = [datesRange lastObject];
BOOL isMinDate = [date isEqualToDate:minDate];
BOOL isMaxDate = [date isEqualToDate:maxDate];

if (isMinDate) {
return hasBorder ? SelectionTypeLeadingBorder : SelectionTypeLeading;
return SelectionTypeLeadingBorder;
} else if (isMaxDate) {
return hasBorder ? SelectionTypeTrailingBorder : SelectionTypeTrailing;
return SelectionTypeTrailingBorder;
} else {
return SelectionTypeMiddle;
}
Expand Down
3 changes: 1 addition & 2 deletions Backpack/Calendar/Classes/BPKCalendarCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
typedef NS_ENUM(NSUInteger, SelectionType) {
SelectionTypeNone,
SelectionTypeSingle,
SelectionTypeLeading,
SelectionTypeLeadingBorder,
SelectionTypeMiddle,
SelectionTypeTrailing,
SelectionTypeTrailingBorder,
SelectionTypeSameDay
};
Expand All @@ -35,6 +33,7 @@ typedef NS_ENUM(NSUInteger, RowType) { RowTypeMiddle, RowTypeStart, RowTypeEnd,

@property(nonatomic, assign) SelectionType selectionType;
@property(nonatomic, assign) RowType rowType;
@property(nonatomic, assign) BOOL wholeMonthSelection;

/**
* Applies the given data to the cell.
Expand Down
26 changes: 14 additions & 12 deletions Backpack/Calendar/Classes/BPKCalendarCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
[self.contentView.layer insertSublayer:selectionLayer below:samedayLayer];
self.selectionLayer = selectionLayer;
self.samedayLayer = samedayLayer;
self.wholeMonthSelection = NO;
}

return self;
Expand Down Expand Up @@ -94,20 +95,20 @@ - (void)layoutSubviews {

switch (self.rowType) {
case RowTypeStart:
if (self.selectionType != SelectionTypeLeadingBorder && self.selectionType != SelectionTypeLeading) {
if (self.selectionType != SelectionTypeLeadingBorder) {
underflow = overflowLength;
}
break;
case RowTypeEnd:
if (self.selectionType != SelectionTypeTrailingBorder && self.selectionType != SelectionTypeTrailing) {
if (self.selectionType != SelectionTypeTrailingBorder) {
overflow = overflowLength;
}
break;
case RowTypeBoth:
if (self.selectionType != SelectionTypeLeadingBorder && self.selectionType != SelectionTypeLeading) {
if (self.selectionType != SelectionTypeLeadingBorder) {
underflow = overflowLength;
}
if (self.selectionType != SelectionTypeTrailingBorder && self.selectionType != SelectionTypeTrailing) {
if (self.selectionType != SelectionTypeTrailingBorder) {
overflow = overflowLength;
}
break;
Expand All @@ -130,7 +131,6 @@ - (void)layoutSubviews {
}
break;

case SelectionTypeTrailing:
case SelectionTypeTrailingBorder:
if (!isRTL) {
corners |= UIRectCornerTopRight | UIRectCornerBottomRight;
Expand All @@ -142,7 +142,6 @@ - (void)layoutSubviews {
cornerRadii = CGSizeMake(height / 2.0, height / 2.0);
break;

case SelectionTypeLeading:
case SelectionTypeLeadingBorder:
if (!isRTL) {
corners |= UIRectCornerTopLeft | UIRectCornerBottomLeft;
Expand Down Expand Up @@ -186,6 +185,15 @@ - (void)configureAppearance {
UIColor *rangeTitleColor = [self colorForCurrentStateInDictionary:self.appearance.titleColors];

if (self.titleLabel.text) {
if (self.wholeMonthSelection) {
self.titleLabel.attributedText = [BPKFont attributedStringWithFontStyle:BPKFontStyleTextHeading5
content:self.titleLabel.text
textColor:rangeTitleColor];
[self setSelected:NO];

return;
}

switch (self.selectionType) {
case SelectionTypeLeadingBorder:
case SelectionTypeTrailingBorder:
Expand All @@ -195,8 +203,6 @@ - (void)configureAppearance {
content:self.titleLabel.text
textColor:selectedColor];
break;
case SelectionTypeLeading:
case SelectionTypeTrailing:
case SelectionTypeMiddle:
self.titleLabel.attributedText = [BPKFont attributedStringWithFontStyle:BPKFontStyleTextHeading5
content:self.titleLabel.text
Expand All @@ -210,10 +216,6 @@ - (void)configureAppearance {
break;
}
}

if (self.isSelected && (self.selectionType == SelectionTypeLeading || self.selectionType == SelectionTypeTrailing)) {
[self setSelected:NO];
}
}

- (void)setSelectionType:(SelectionType)selectionType {
Expand Down

0 comments on commit 2130e77

Please sign in to comment.