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

[DON-715] Whole month in single date selection #2113

Merged
merged 6 commits into from
Nov 26, 2024

Conversation

novinfard
Copy link
Contributor

@novinfard novinfard commented Nov 22, 2024

This PR adds the whole month selection as one the single date selection mode states.

Demo

Simulator.Screen.Recording.-.iPhone.16.Pro.Max.-.2024-11-26.at.07.25.20.mp4

@novinfard novinfard changed the title [DRAFT] Initial change on whole month selection in single selection [DRAFT] Whole month in single date selection Nov 22, 2024
@novinfard novinfard changed the title [DRAFT] Whole month in single date selection [DON-715] Whole month in single date selection Nov 26, 2024
@novinfard novinfard added swiftui minor Non breaking change labels Nov 26, 2024
@novinfard novinfard marked this pull request as ready for review November 26, 2024 08:32
@novinfard novinfard requested a review from frugoman November 26, 2024 09:53
/// The `CalendarSingleSelectionState` enum represents the different states of a single selection.
public enum CalendarSingleSelectionState {
/// The state, with single date selection
case single(Date?)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should probably not be optional right? the optional would be on the enum itself, but not the date.
reasoning being:
if there's a single date selected, it makes no sense that that seleciton has no date

Copy link
Contributor Author

@novinfard novinfard Nov 26, 2024

Choose a reason for hiding this comment

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

In both calendar selection types (range/single), there is a use case for not having a date selected (e.g., when dates are cleared). Therefore, this optional date is still valid.

Single Range
Simulator Screenshot - iPhone SE (3rd generation) - 2024-11-26 at 10 38 16 Simulator Screenshot - iPhone SE (3rd generation) - 2024-11-26 at 10 38 10

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, bu the nil would be on the entire selection instance, not the date itself.

@State var selection: CalendarSingleSelectionState?
// so that would either be:
selection = .single(Date())
// or
selection = .wholeMonth(...)
// or
selection = nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. Right. I applied the change. ✅

if date == dayDate {
SingleSelectedCell(calendar: calendar, date: dayDate)
} else {
DefaultCalendarDayCell(calendar: calendar, date: dayDate)
Copy link
Contributor

Choose a reason for hiding this comment

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

if you appliy the above comment about optionality, I think this if let would be done on the selection itself, rather than the date.

switch selection {
  case single(let date): SingleSelectedCel(...)
  case wholeMonth(..): ....
  case nil: DefaultCalendarDayCell(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the optional, but we still need this statement to determine which date needs to be highlighted among other dates when a date has been selected date == dayDate.

When the tap action happens, we change the state, and the change of state helps us to render the changes.

)
),
calendar: calendar,
validRange: validRange,
initialMonthScroll: monthScroll
)
.monthAccessoryAction { _ in
return CalendarMonthAccessoryAction(
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the accessibility setting for this should be here instead, to avoid being possible to send nil to that, when you do have an action. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. 👍

I made this config as part whole month selection state. So if the consumer doesn't want to use the wholeMonth they don't have to provide this value. Removed this optional. ✅

Copy link
Contributor

@frugoman frugoman left a comment

Choose a reason for hiding this comment

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

Looks good!!

@frugoman frugoman merged commit 13c60ec into main Nov 26, 2024
14 checks passed
@frugoman frugoman deleted the donburi/DON-715-whole-month-single-selection branch November 26, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Non breaking change swiftui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants