Skip to content

Commit

Permalink
fix(ios): fix 'dateTimeColor' for iOS 14+ (#12167)
Browse files Browse the repository at this point in the history
Fixes TIMOB-28181
  • Loading branch information
hansemannn authored and sgtcoolguy committed Oct 23, 2020
1 parent 35f59c4 commit 88005a3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apidoc/Titanium/UI/Picker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ properties:
Applicable to <Titanium.UI.PICKER_TYPE_TIME> and <Titanium.UI.PICKER_TYPE_DATE_AND_TIME> picker types.
The picker type <Titanium.UI.PICKER_TYPE_DATE> does not support text customizing as stated in the
[UIKit User Interface Catalog](https://developer.apple.com/documentation/uikit/uidatepicker).
Important: On iOS 14+, you also have to set the <Titanium.UI.Picker.datePickerStyle> to <Titanium.UI.iOS.DATE_PICKER_STYLE_WHEELS>
in order to use this property.
type: [String, Titanium.UI.Color]
platforms: [iphone, ipad, macos]
since: "5.2.0"
Expand Down
14 changes: 13 additions & 1 deletion iphone/Classes/TiUIPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,19 @@ - (void)setBackgroundColor_:(id)value

- (void)setDateTimeColor_:(id)value
{
[[self proxy] replaceValue:value forKey:@"dateTimeColor" notification:NO];
// Guard date picker and iOS 14+ date picker style
if (![self isDatePicker]) {
return;
}
#if IS_SDK_IOS_13_4
if (((UIDatePicker *)[self picker]).preferredDatePickerStyle != UIDatePickerStyleWheels) {
return;
}
#endif

[[self proxy] replaceValue:value
forKey:@"dateTimeColor"
notification:NO];

if (picker != nil) {
[(UIDatePicker *)[self picker] setValue:[[TiUtils colorValue:value] _color] forKeyPath:@"textColor"];
Expand Down
39 changes: 39 additions & 0 deletions tests/Resources/ti.ui.picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,45 @@ describe('Titanium.UI.Picker', function () {
win.open();
});

it('DatePicker dateTimeColor (invalid "type" - TIMOB-28181)', function (finish) {
const dp = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_PLAIN,
dateTimeColor: 'red'
});

win = Ti.UI.createWindow();
win.addEventListener('open', function () {
try {
should(dp.dateTimeColor).be.eql('red');
finish();
} catch (err) {
return finish(err);
}
});
win.add(dp);
win.open();
});

it('DatePicker dateTimeColor (valid "type" + "datePickerStyle" - TIMOB-28181)', function (finish) {
const dp = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_DATE,
datePickerStyle: Ti.UI.iOS.DATE_PICKER_STYLE_WHEELS,
dateTimeColor: 'red'
});

win = Ti.UI.createWindow();
win.addEventListener('open', function () {
try {
should(dp.dateTimeColor).be.eql('red');
finish();
} catch (err) {
return finish(err);
}
});
win.add(dp);
win.open();
});

it('DatePicker postlayout event', function (finish) {
const dp = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_DATE
Expand Down

0 comments on commit 88005a3

Please sign in to comment.