Skip to content

Commit

Permalink
- Fixed crash in iOS 14.0
Browse files Browse the repository at this point in the history
- Added iOS 14 DatePickerStyle Support
  • Loading branch information
Noor ul Ain Ali committed Jul 8, 2020
1 parent be29dab commit 764a79a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
50 changes: 32 additions & 18 deletions Pickers/ActionSheetDatePicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,45 @@ typedef void(^ActionDateCancelBlock)(ActionSheetDatePicker *picker);
@property (nonatomic, copy) ActionDateDoneBlock onActionSheetDone;
@property (nonatomic, copy) ActionDateCancelBlock onActionSheetCancel;

+ (instancetype)showPickerWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate target:(id)target action:(SEL)action origin:(id)origin;

+ (instancetype)showPickerWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction;
+ (instancetype)showPickerWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
target:(id)target
action:(SEL)action
origin:(id)origin;

+ (instancetype)showPickerWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate
minimumDate:(NSDate *)minimumDate maximumDate:(NSDate *)maximumDate
target:(id)target action:(SEL)action origin:(id)origin;
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
target:(id)target
action:(SEL)action
origin:(id)origin
cancelAction:(SEL)cancelAction;

+ (instancetype)showPickerWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
doneBlock:(ActionDateDoneBlock)doneBlock
cancelBlock:(ActionDateCancelBlock)cancelBlock
origin:(UIView*)view;
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
minimumDate:(NSDate *)minimumDate
maximumDate:(NSDate *)maximumDate
target:(id)target
action:(SEL)action
origin:(id)origin;

+ (instancetype)showPickerWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
minimumDate:(NSDate *)minimumDate
maximumDate:(NSDate *)maximumDate
doneBlock:(ActionDateDoneBlock)doneBlock
cancelBlock:(ActionDateCancelBlock)cancelBlock
origin:(UIView*)view;
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
doneBlock:(ActionDateDoneBlock)doneBlock
cancelBlock:(ActionDateCancelBlock)cancelBlock
origin:(UIView*)view;

+ (instancetype)showPickerWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
minimumDate:(NSDate *)minimumDate
maximumDate:(NSDate *)maximumDate
doneBlock:(ActionDateDoneBlock)doneBlock
cancelBlock:(ActionDateCancelBlock)cancelBlock
origin:(UIView*)view;

- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate target:(id)target action:(SEL)action origin:(id)origin;

Expand Down
17 changes: 13 additions & 4 deletions Pickers/ActionSheetDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
#import <objc/message.h>

@interface ActionSheetDatePicker()

@property (nonatomic, assign) UIDatePickerMode datePickerMode;
@property (nonatomic, strong) NSDate *selectedDate;
@property (nonatomic, assign) UIDatePickerStyle datePickerStyle API_AVAILABLE(ios(13.4));

@end

@implementation ActionSheetDatePicker
Expand Down Expand Up @@ -147,6 +150,9 @@ - (instancetype)initWithTitle:(NSString *)title
origin:(UIView*)origin
{
self = [self initWithTitle:title datePickerMode:datePickerMode selectedDate:selectedDate target:nil action:nil origin:origin];
if (@available(iOS 13.4, *)) {
self.datePickerStyle = UIDatePickerStyleAutomatic;
}
if (self) {
self.onActionSheetDone = doneBlock;
self.onActionSheetCancel = cancelBlock;
Expand All @@ -164,10 +170,13 @@ - (UIView *)configuredPickerView {
datePicker.calendar = self.calendar;
datePicker.timeZone = self.timeZone;
datePicker.locale = self.locale;

UIColor *textColor = [self.pickerTextAttributes valueForKey:NSForegroundColorAttributeName];
if (textColor) {
[datePicker setValue:textColor forKey:@"textColor"]; // use ObjC runtime to set value for property that is not exposed publicly
if (@available(iOS 13.4, *)) {
datePicker.preferredDatePickerStyle = self.datePickerStyle;
} else {
UIColor *textColor = [self.pickerTextAttributes valueForKey:NSForegroundColorAttributeName];
if (textColor) {
[datePicker setValue:textColor forKey:@"textColor"]; // use ObjC runtime to set value for property that is not exposed publicly
}
}

// if datepicker is set with a date in countDownMode then
Expand Down

0 comments on commit 764a79a

Please sign in to comment.