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

Added ability to select a date range #73

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion Example/RSDayFlowExample/RSDFDatePickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ - (NSDateFormatter *)dateFormatter
- (RSDFDatePickerView *)datePickerView
{
if (!_datePickerView) {
_datePickerView = [[RSDFDatePickerView alloc] initWithFrame:self.view.bounds calendar:self.calendar];
_datePickerView = [[RSDFDatePickerView alloc] initWithFrame:self.view.bounds calendar:self.calendar startDate:[NSDate date] endDate:nil];
_datePickerView.delegate = self;
_datePickerView.dataSource = self;
_datePickerView.selectionMode = RSDFSelectionModeRange;
_datePickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
return _datePickerView;
Expand Down Expand Up @@ -214,6 +215,11 @@ - (void)datePickerView:(RSDFDatePickerView *)view didSelectDate:(NSDate *)date
[[[UIAlertView alloc] initWithTitle:@"Picked Date" message:[self.dateFormatter stringFromDate:date] delegate:nil cancelButtonTitle:@":D" otherButtonTitles:nil] show];
}

- (void)datePickerView:(RSDFDatePickerView *)view didSelectStartDate:(NSDate *)startDate endDate:(NSDate *)endDate
{
NSLog(@"Picked Date Range (%@ - %@)", startDate, endDate);
}

#pragma mark - RSDFDatePickerViewDataSource

- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldHighlightDate:(NSDate *)date
Expand Down
80 changes: 63 additions & 17 deletions RSDayFlow/RSDFDatePickerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
@protocol RSDFDatePickerViewDelegate;
@protocol RSDFDatePickerViewDataSource;

typedef NS_ENUM (NSUInteger, RSDFSelectionMode) {

/// Allows selecting a single date
RSDFSelectionModeSingle,

/// Allows selecting a date range (start range & end range)
RSDFSelectionModeRange
};

/**
The `RSDFDatePickerView` is a calendar view with infinity scrolling.
*/
Expand All @@ -39,7 +48,7 @@
@param frame The frame rectangle for the view, measured in points.
@param calendar The calendar for the date picker view.
*/
- (instancetype)initWithFrame:(CGRect)frame calendar:(NSCalendar *)calendar;
- (nonnull instancetype)initWithFrame:(CGRect)frame calendar:(NSCalendar * __nonnull)calendar;


/**
Expand All @@ -50,7 +59,7 @@
@param startDate First selectable date
@param endDate Last selectable date
*/
- (instancetype)initWithFrame:(CGRect)frame calendar:(NSCalendar *)calendar startDate:(NSDate *)startDate endDate:(NSDate *)endDate;
- (nonnull instancetype)initWithFrame:(CGRect)frame calendar:(NSCalendar * __nonnull)calendar startDate:(NSDate * __nullable)startDate endDate:(NSDate * __nullable)endDate;

///-----------------------------
/// @name Accessing the Delegate
Expand All @@ -61,7 +70,7 @@

@discussion A `RSDFDatePickerView` delegate responds to message sent by tapping on date in the date picker view.
*/
@property (nonatomic, readwrite, weak) id<RSDFDatePickerViewDelegate> delegate;
@property (nonatomic, readwrite, weak) id<RSDFDatePickerViewDelegate> __nullable delegate;

///--------------------------------
/// @name Accessing the Data Source
Expand All @@ -73,7 +82,20 @@
@discussion A `RSDFDatePickerView` data source provides dates to mark in the date picker view.
*/

@property (nonatomic, readwrite, weak) id<RSDFDatePickerViewDataSource> dataSource;
@property (nonatomic, readwrite, weak) id<RSDFDatePickerViewDataSource> __nullable dataSource;

///------------------
/// @name Selection Mode
/// -----------------

/**
Am enum that determines date selection type

@discussion Default values is RSDFSelectionModeSingle
If 'RSDFSelectionModeSingle' only allows a single date to be selected
If 'RSDFSelectionModeRange' allows selecting a date range (start date and end date)
*/
@property (nonatomic, readwrite, assign) RSDFSelectionMode selectionMode;

///------------------
/// @name Paging Mode
Expand Down Expand Up @@ -104,7 +126,7 @@
@param animated YES if you want to animate the change in position, NO if it should be immediate.
*/

- (void)scrollToDate:(NSDate *)date animated:(BOOL)animated;
- (void)scrollToDate:(NSDate * __nonnull)date animated:(BOOL)animated;

/// ------------------------
/// @name Selecting the Date
Expand All @@ -120,7 +142,19 @@
@param date The date to select. Specifying nil for this parameter clears the current selection.
*/

- (void)selectDate:(NSDate *)date;
- (void)selectDate:(NSDate * __nullable)date;

/**
Selects dates in range.

If there is an existing selection of a different date, calling this method replaces the previous selection.

This method does not cause any selection-related delegate methods to be called.

@param firstDate The start range date to select.
@param lastDate The end range date to select.
*/
- (void)selectDateRange:(NSDate * __nullable)firstDate lastDate:(NSDate * __nullable)lastDate;

///-------------------------
/// @name Reloading the Data
Expand All @@ -142,35 +176,35 @@

@discussion Can be overridden in subclasses for customization.
*/
- (Class)daysOfWeekViewClass;
- (Class __nonnull)daysOfWeekViewClass;

/**
The class of the collection view which used to display days and months in the date picker view. Default value is `RSDFDatePickerCollectionView`.

@discussion Can be overridden in subclasses for customization.
*/
- (Class)collectionViewClass;
- (Class __nonnull)collectionViewClass;

/**
The class of the layout of the collection view which used the date picker. Default value is `RSDFDatePickerCollectionViewLayout`.

@discussion Can be overridden in subclasses for customization.
*/
- (Class)collectionViewLayoutClass;
- (Class __nonnull)collectionViewLayoutClass;

/**
The class of the reusable view which used to display a month and year in the date picker view. Default value is `RSDFDatePickerMonthHeader`.

@discussion Can be overridden in subclasses for customization.
*/
- (Class)monthHeaderClass;
- (Class __nonnull)monthHeaderClass;

/**
The class of the cell which used to display a day in the date picker view. Default value is `RSDFDatePickerDayCell`.

@discussion Can be overridden in subclasses for customization.
*/
- (Class)dayCellClass;
- (Class __nonnull)dayCellClass;

@end

Expand All @@ -197,7 +231,7 @@

@return YES if the date should be highlighted or NO if it should not.
*/
- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldHighlightDate:(NSDate *)date;
- (BOOL)datePickerView:(RSDFDatePickerView * __nonnull)view shouldHighlightDate:(NSDate * __nonnull)date;

/**
Asks the delegate if the specified date should be selected.
Expand All @@ -211,7 +245,7 @@

@return YES if the date should be selected or NO if it should not.
*/
- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldSelectDate:(NSDate *)date;
- (BOOL)datePickerView:(RSDFDatePickerView * __nonnull)view shouldSelectDate:(NSDate * __nonnull)date;

/**
Tells the delegate that the user did select a date.
Expand All @@ -222,7 +256,19 @@
@param view The view whose date was selected.
@param date The selected date.
*/
- (void)datePickerView:(RSDFDatePickerView *)view didSelectDate:(NSDate *)date;
- (void)datePickerView:(RSDFDatePickerView * __nonnull)view didSelectDate:(NSDate * __nonnull)date;

/**
Tells the delegate that the user did select a date in RSDFSelectionModeRange.

The date picker view calls this method when the user successfully selects a date in the date picker view.
It does not call this method when you programmatically set the selection.

@param view The view whose date was selected.
@param startDate The selected start date for range.
@param endDate The selected end date for range.
*/
- (void)datePickerView:(RSDFDatePickerView * __nonnull)view didSelectStartDate:(NSDate * __nullable)startDate endDate:(NSDate * __nullable)endDate;

@end

Expand All @@ -244,7 +290,7 @@

@return YES if the date should be marked or NO if it should not.
*/
- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldMarkDate:(NSDate *)date;
- (BOOL)datePickerView:(RSDFDatePickerView * __nonnull)view shouldMarkDate:(NSDate * __nonnull)date;

/**
Asks the data source about the color of the default mark image for the specified date.
Expand All @@ -255,7 +301,7 @@

@discussion Will be ignored if the method `datePickerView:markImageForDate:` is implemented.
*/
- (UIColor *)datePickerView:(RSDFDatePickerView *)view markImageColorForDate:(NSDate *)date;
- (UIColor * __nonnull)datePickerView:(RSDFDatePickerView * __nonnull)view markImageColorForDate:(NSDate * __nonnull)date;

/**
Asks the data source about the mark image for the specified date.
Expand All @@ -264,6 +310,6 @@

@return The mark image for the specified date.
*/
- (UIImage *)datePickerView:(RSDFDatePickerView *)view markImageForDate:(NSDate *)date;
- (UIImage * __nonnull)datePickerView:(RSDFDatePickerView * __nonnull)view markImageForDate:(NSDate * __nonnull)date;

@end