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

[TIMOB-24574] iOS: Fix picker-selection #8958

Merged
merged 4 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions apidoc/Titanium/UI/Picker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,9 @@ properties:
If `true`, selection indicator is enabled.

On iOS 7 and later, the picker indicator is always shown and you cannot control it.

On iOS 6 and prior, if enabled, a blue bar is displayed to indicate the current selection.
Manually setting the property was deprecated in 6.1.0 and will be ignored by the SDK.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is deprecated in iOS only. So iOS should be mentioned in above line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was written in the iOS-paragraph, so I hoped people will get it's iOS related, but I'll explicitly say it :-).

type: Boolean
default: true (Android), false (iPhone, iPad)
default: true
platforms: [android, iphone, ipad]

- name: selectionOpens
Expand Down
38 changes: 13 additions & 25 deletions iphone/Classes/TiUIPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,25 @@ -(UIControl*)picker
if ([shouldSize numberFromString:widthString] != nil) {
[[self proxy ]setValue:NUMDOUBLE(width) forKey:@"width"];
}

if ([shouldSize numberFromString:heightString] != nil) {
[[self proxy ]setValue:NUMDOUBLE(height) forKey:@"height"];
}

if (type == -1)
{
//TODO: this is not the way to abstract pickers, note the cast I had to add to the following line
picker = (UIControl*)[[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
((UIPickerView*)picker).delegate = self;
((UIPickerView*)picker).dataSource = self;
}
else
{
if (type == -1) {
picker = (UIControl *)[[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
[((UIPickerView *) picker) setDelegate:self];
[((UIPickerView *) picker) setDataSource:self];

// Required hack for iOS 10.x (TIMOB-24574), remove when Apple fixes it.
[(UIPickerView *) picker selectRow:0 inComponent:0 animated:YES];
} else {
picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, width, height)];
[(UIDatePicker*)picker setTimeZone:[NSTimeZone localTimeZone]];
[(UIDatePicker*)picker setDatePickerMode:type];
[(UIDatePicker *)picker setTimeZone:[NSTimeZone localTimeZone]];
[(UIDatePicker *)picker setDatePickerMode:type];
[picker addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
}

[picker setBackgroundColor:[UIColor whiteColor]];
[self addSubview:picker];
}
Expand Down Expand Up @@ -190,19 +191,6 @@ -(void)setType_:(id)type_
}
}

// We're order-dependent on type being set first, so we need to make sure that anything that relies
// on whether or not this is a date picker needs to be set AFTER the initial configuration.
-(void)setSelectionIndicator_:(id)value
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather deleting the method , we should deprecate it by giving message to developers. What you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was not used since iOS 7 anyway, so I decided to clean up the core directly. Having it or not does not have an effect to the developer - they cannot disable the selection indicator anyway.

{
if (picker == nil) {
[[self proxy] replaceValue:value forKey:@"selectionIndicator" notification:NO];
}
else if ([self isDatePicker]==NO)
{
[(UIPickerView*)[self picker] setShowsSelectionIndicator:[TiUtils boolValue:value]];
}
}

-(void)setMinDate_:(id)date
{
ENSURE_SINGLE_ARG_OR_NIL(date,NSDate);
Expand Down Expand Up @@ -471,4 +459,4 @@ -(void)valueChanged:(id)sender

@end

#endif
#endif