From 29ae36662e02cb4e4040ee2f33945713e73c6559 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 21 Oct 2014 10:13:07 +0300 Subject: [PATCH 1/3] increase animation speed (similar to UIActionSheet) --- Pickers/SWActionSheet.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pickers/SWActionSheet.m b/Pickers/SWActionSheet.m index 2869d53ab..6179c5824 100644 --- a/Pickers/SWActionSheet.m +++ b/Pickers/SWActionSheet.m @@ -9,7 +9,7 @@ static const float delay = 0.f; -static const float duration = .3f; +static const float duration = .25f; static const enum UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseIn; From f176272588d79b8ab3c3d0f2efe8d8202c61f28a Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 22 Oct 2014 12:13:36 +0300 Subject: [PATCH 2/3] Code cleanup --- Pickers/AbstractActionSheetPicker.m | 10 +++++----- Pickers/ActionSheetDatePicker.m | 13 ++++--------- Pickers/ActionSheetLocalePicker.m | 12 +++--------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Pickers/AbstractActionSheetPicker.m b/Pickers/AbstractActionSheetPicker.m index 2d11102b2..20ff7bff8 100755 --- a/Pickers/AbstractActionSheetPicker.m +++ b/Pickers/AbstractActionSheetPicker.m @@ -293,10 +293,10 @@ - (IBAction)customButtonPressed:(id)sender NSDictionary *buttonDetails = (self.customButtons)[(NSUInteger) index]; NSAssert(buttonDetails != NULL, @"Custom button dictionary is invalid"); - ActionType actionType = [buttonDetails[kActionType] intValue]; + ActionType actionType = (ActionType) [buttonDetails[kActionType] integerValue]; switch (actionType) { case Value: { - NSInteger buttonValue = [buttonDetails[kButtonValue] intValue]; + NSInteger buttonValue = [buttonDetails[kButtonValue] integerValue]; UIPickerView *picker = (UIPickerView *) self.pickerView; NSAssert(picker != NULL, @"PickerView is invalid"); [picker selectRow:buttonValue inComponent:0 animated:YES]; @@ -310,16 +310,16 @@ - (IBAction)customButtonPressed:(id)sender case Block: { ActionBlock actionBlock = buttonDetails[kButtonValue]; - [self hidePickerWithCancelAction]; + [self dismissPicker]; if (actionBlock) actionBlock(); break; } - + case Selector: { SEL selector = [buttonDetails[kButtonValue] pointerValue]; id target = buttonDetails[kActionTarget]; - [self hidePickerWithCancelAction]; + [self dismissPicker]; if (target && [target respondsToSelector:selector]) { SuppressPerformSelectorLeakWarning ( diff --git a/Pickers/ActionSheetDatePicker.m b/Pickers/ActionSheetDatePicker.m index 33513071f..74be3135a 100755 --- a/Pickers/ActionSheetDatePicker.m +++ b/Pickers/ActionSheetDatePicker.m @@ -181,7 +181,7 @@ - (void)customButtonPressed:(id)sender { NSDictionary *buttonDetails = (self.customButtons)[(NSUInteger) index]; NSAssert(buttonDetails != NULL, @"Custom button dictionary is invalid"); - ActionType actionType = [buttonDetails[kActionType] intValue]; + ActionType actionType = (ActionType) [buttonDetails[kActionType] integerValue]; switch (actionType) { case Value: { NSDate *itemValue = buttonDetails[kButtonValue]; @@ -191,16 +191,11 @@ - (void)customButtonPressed:(id)sender { break; } - case Block: { + case Block: + case Selector: [super customButtonPressed:sender]; break; - } - - case Selector: { - [super customButtonPressed:sender]; - break; - } - + default: NSAssert(false, @"Unknown action type"); break; diff --git a/Pickers/ActionSheetLocalePicker.m b/Pickers/ActionSheetLocalePicker.m index 5c4ac5d43..30c7bd28c 100644 --- a/Pickers/ActionSheetLocalePicker.m +++ b/Pickers/ActionSheetLocalePicker.m @@ -371,7 +371,7 @@ - (void)customButtonPressed:(id)sender { NSDictionary *buttonDetails = (self.customButtons)[(NSUInteger) index]; NSAssert(buttonDetails != NULL, @"Custom button dictionary is invalid"); - ActionType actionType = [buttonDetails[kActionType] intValue]; + ActionType actionType = (ActionType) [buttonDetails[kActionType] intValue]; switch (actionType) { case Value: { id itemValue = buttonDetails[kButtonValue]; @@ -385,16 +385,10 @@ - (void)customButtonPressed:(id)sender { break; } - case Block: { + case Block: + case Selector: [super customButtonPressed:sender]; break; - } - - case Selector: { - [super customButtonPressed:sender]; - break; - } - default: NSAssert(false, @"Unknown action type"); break; From ab80aff5393831ebb4af6a75b7f4bb5f98106132 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 22 Oct 2014 13:56:40 +0300 Subject: [PATCH 3/3] added 2 tests for custom button with actionBlock --- .../AbstractActionSheetPickerTestCase.m | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ObjC-Example/ActionSheetPicker Tests/AbstractActionSheetPickerTestCase.m b/ObjC-Example/ActionSheetPicker Tests/AbstractActionSheetPickerTestCase.m index cabce51ba..7bd8bad56 100644 --- a/ObjC-Example/ActionSheetPicker Tests/AbstractActionSheetPickerTestCase.m +++ b/ObjC-Example/ActionSheetPicker Tests/AbstractActionSheetPickerTestCase.m @@ -74,5 +74,26 @@ - (void)testCustomFontNameWithAttributedTextAndTextAttributes XCTAssertNotNil(_sheetStringPicker); } +- (void)testPickerWithCustomActionBlockOnButton +{ + NSString *title = @"Custom label:"; + + [_sheetStringPicker addCustomButtonWithTitle:title actionBlock:^{ + NSLog(@"Test block invoked"); + }]; + + [_sheetStringPicker showActionSheetPicker]; + XCTAssertNotNil(_sheetStringPicker); +} + +- (void)testPickerWithCustomActionBlockOnButtonAndNilString +{ + [_sheetStringPicker addCustomButtonWithTitle:nil actionBlock:^{ + NSLog(@"Test block invoked"); + }]; + + [_sheetStringPicker showActionSheetPicker]; + XCTAssertNotNil(_sheetStringPicker); +} @end