Skip to content

Commit

Permalink
Merge pull request #8958 from hansemannn/TIMOB-24574
Browse files Browse the repository at this point in the history
[TIMOB-24574] iOS: Fix picker-selection
  • Loading branch information
htbryant94 committed Apr 19, 2017
2 parents f10a9d2 + 47eaaf6 commit da74974
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
7 changes: 3 additions & 4 deletions apidoc/Titanium/UI/Picker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,10 @@ properties:
description: |
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.
On iOS 7 and later, the picker indicator is always shown and you cannot control it. Manually
setting the property is deprecated on iOS since 6.1.0 and will be ignored by the SDK.
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
{
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

0 comments on commit da74974

Please sign in to comment.