diff --git a/src/ios/DatePicker.m b/src/ios/DatePicker.m index 1ada714..e2bf4b6 100644 --- a/src/ios/DatePicker.m +++ b/src/ios/DatePicker.m @@ -17,6 +17,7 @@ @interface DatePicker () @property (nonatomic) BOOL isVisible; @property (nonatomic) UIActionSheet* datePickerSheet; +@property (nonatomic) UIView* datePickerView; @property (nonatomic) UIDatePicker* datePicker; @property (nonatomic) UIPopoverController *datePickerPopover; @@ -37,7 +38,8 @@ - (void)show:(CDVInvokedUrlCommand*)command { - (BOOL)showForPhone:(NSMutableDictionary *)options { if(!self.isVisible){ - self.datePickerSheet = [self createActionSheet:options]; + + self.datePickerView = [self createDatePickerView:options]; self.isVisible = TRUE; } return true; @@ -53,7 +55,13 @@ - (BOOL)showForPad:(NSMutableDictionary *)options { - (void)hide { if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { - [self.datePickerSheet dismissWithClickedButtonIndex:0 animated:YES]; + [UIView animateWithDuration:0.3 animations:^{ + [self.datePickerView setFrame:CGRectOffset(self.datePickerView.frame, 0, 300)]; + } completion:^(BOOL finished) { + [self.datePickerView removeFromSuperview]; + self.isVisible = NO; + }]; + } else { [self.datePickerPopover dismissPopoverAnimated:YES]; } @@ -102,36 +110,48 @@ - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverControl #pragma mark - Factory methods -- (UIActionSheet *)createActionSheet:(NSMutableDictionary *)options { - UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil - delegate:self cancelButtonTitle:nil - destructiveButtonTitle:nil - otherButtonTitles:nil]; - [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; - // date picker - CGRect frame = CGRectMake(0, 40, 0, 0); - if(!self.datePicker){ - self.datePicker = [self createDatePicker: options frame:frame]; - } - [self updateDatePicker:options]; - [actionSheet addSubview: self.datePicker]; - // cancel button - UISegmentedControl *cancelButton = [self createCancelButton:options]; - [actionSheet addSubview:cancelButton]; - // done button - UISegmentedControl *doneButton = [self createDoneButton:options]; - [actionSheet addSubview:doneButton]; - // show UIActionSheet - [actionSheet showInView:self.webView.superview]; - [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; - - return actionSheet; +-(UIView *)createDatePickerView:(NSMutableDictionary *)options { + + float viewHeight = 240; + + // create view off screen + CGRect alertViewFrame = CGRectMake(0, self.webView.frame.size.height, self.webView.frame.size.width, viewHeight); + UIView *alertView = [[UIView alloc] initWithFrame:alertViewFrame]; + [alertView setBackgroundColor:[UIColor whiteColor]]; + [alertView setUserInteractionEnabled:YES]; + + CGRect frame = CGRectMake(0, 40, self.webView.frame.size.width, viewHeight); + + if(!self.datePicker){ + self.datePicker = [self createDatePicker: options frame:frame]; + [self.datePicker setBackgroundColor:[UIColor whiteColor]]; + [self.datePicker addTarget:self action:@selector(dateChangedAction:) forControlEvents:UIControlEventValueChanged]; + } + [self updateDatePicker:options]; + [alertView addSubview:self.datePicker]; + + // cancel button + UISegmentedControl *cancelButton = [self createCancelButton:options]; + [alertView addSubview:cancelButton]; + // done button + UISegmentedControl *doneButton = [self createDoneButton:options]; + [alertView addSubview:doneButton]; + + [self.viewController.view insertSubview:alertView aboveSubview:self.webView]; + + // animate veiw into view + [UIView animateWithDuration:0.3 animations:^{ + [alertView setFrame:CGRectMake(0, self.webView.frame.size.height - viewHeight, frame.size.width, frame.size.height)]; + }]; + + return alertView; + } - (UIPopoverController *)createPopover:(NSMutableDictionary *)options { - CGFloat pickerViewWidth = 320.0f; + CGFloat pickerViewWidth = self.webView.frame.size.width; CGFloat pickerViewHeight = 216.0f; UIView *datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, pickerViewWidth, pickerViewHeight)]; @@ -249,7 +269,7 @@ - (UISegmentedControl *)createDoneButton:(NSMutableDictionary *)options { CGSize size = button.bounds.size; CGFloat width = size.width; CGFloat height = size.height; - CGFloat xPos = 320 - width - 5; // 320 == width of DatePicker, 5 == offset to right side hand + CGFloat xPos = self.webView.frame.size.width - width - 5; // 320 == width of DatePicker, 5 == offset to right side hand button.frame = CGRectMake(xPos, 7.0f, width, height); [button addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventValueChanged]; @@ -267,4 +287,4 @@ - (UIColor *)colorFromHexString:(NSString *)hexString { return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0]; } -@end \ No newline at end of file +@end