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

Code cleanup for your pull request #1

Merged
merged 4 commits into from
Oct 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions Pickers/AbstractActionSheetPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Author

Choose a reason for hiding this comment

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

по поводу integerValue: Конечно typedef int NSInteger;
Но лучше всегда использовать родные типы данных. Тем более "вдруг" измениться архитектура и NSInteger станет уже long int (к примеру)?

По поводу каста к типу ActionType - это нужно для проверок на этапе компиляции. AppCode такие вещи сразу подсвечивает и при курсоре на этих участках и нажатии Alt + Enter сразу правит.

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];
Expand All @@ -310,16 +310,16 @@ - (IBAction)customButtonPressed:(id)sender

case Block: {
ActionBlock actionBlock = buttonDetails[kButtonValue];
[self hidePickerWithCancelAction];
[self dismissPicker];
Copy link
Author

Choose a reason for hiding this comment

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

Возможно у человека висит некоторый специфичный cancelBock, который он не хотел бы выполнять при нажатии на кнопку. Так что лучше просто скрывать пикер.

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 (
Expand Down
13 changes: 4 additions & 9 deletions Pickers/ActionSheetDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down
12 changes: 3 additions & 9 deletions Pickers/ActionSheetLocalePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -385,16 +385,10 @@ - (void)customButtonPressed:(id)sender {
break;
}

case Block: {
case Block:
case Selector:
Copy link
Author

Choose a reason for hiding this comment

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

Лучше писать так, когда нужно сделать одно действие для нескольких кейсов.

[super customButtonPressed:sender];
break;
}

case Selector: {
[super customButtonPressed:sender];
break;
}

default:
NSAssert(false, @"Unknown action type");
break;
Expand Down
2 changes: 1 addition & 1 deletion Pickers/SWActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

static const float delay = 0.f;

static const float duration = .3f;
static const float duration = .25f;

Copy link
Author

Choose a reason for hiding this comment

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

Это моя правка, осталась от еще незапушеного комита.

static const enum UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseIn;

Expand Down