Skip to content

Commit 45fb6c4

Browse files
authored
fix(ios): time-picker and date-picker for iOS 14 (NativeScript#8877)
1 parent 313f476 commit 45fb6c4

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

packages/core/ui/date-picker/index.ios.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import { DatePickerBase, yearProperty, monthProperty, dayProperty, dateProperty, maxDateProperty, minDateProperty } from './date-picker-common';
22
import { colorProperty } from '../styling/style-properties';
33
import { Color } from '../../color';
4+
import { Device } from '../../platform';
45

56
export * from './date-picker-common';
67

8+
const SUPPORT_DATE_PICKER_STYLE = parseFloat(Device.os) >= 14.0;
9+
const SUPPORT_TEXT_COLOR = parseFloat(Device.os) < 14.0;
10+
const DEFAULT_DATE_PICKER_STYLE = 1;
11+
712
export class DatePicker extends DatePickerBase {
813
private _changeHandler: NSObject;
914
public nativeViewProtected: UIDatePicker;
1015

1116
public createNativeView() {
1217
const picker = UIDatePicker.new();
1318
picker.datePickerMode = UIDatePickerMode.Date;
14-
19+
if (SUPPORT_DATE_PICKER_STYLE) {
20+
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
21+
}
1522
return picker;
1623
}
1724

@@ -74,11 +81,13 @@ export class DatePicker extends DatePickerBase {
7481
}
7582

7683
[colorProperty.getDefault](): UIColor {
77-
return this.nativeViewProtected.valueForKey('textColor');
84+
return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey('textColor') : UIColor.new();
7885
}
7986
[colorProperty.setNative](value: Color | UIColor) {
80-
const picker = this.nativeViewProtected;
81-
picker.setValueForKey(value instanceof Color ? value.ios : value, 'textColor');
87+
if (SUPPORT_TEXT_COLOR) {
88+
const picker = this.nativeViewProtected;
89+
picker.setValueForKey(value instanceof Color ? value.ios : value, 'textColor');
90+
}
8291
}
8392
}
8493

packages/core/ui/time-picker/index.ios.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { TimePickerBase, timeProperty, minuteIntervalProperty, minuteProperty, minMinuteProperty, maxMinuteProperty, hourProperty, minHourProperty, maxHourProperty } from './time-picker-common';
22
import { Color } from '../../color';
33
import { colorProperty } from '../styling/style-properties';
4+
import { Device } from '../../platform';
45

56
export * from './time-picker-common';
67

8+
const SUPPORT_DATE_PICKER_STYLE = parseFloat(Device.os) >= 14.0;
9+
const SUPPORT_TEXT_COLOR = parseFloat(Device.os) < 14.0;
10+
const DEFAULT_DATE_PICKER_STYLE = 1;
11+
712
function getDate(hour: number, minute: number): Date {
813
let components = NSDateComponents.alloc().init();
914
components.hour = hour;
@@ -30,7 +35,9 @@ export class TimePicker extends TimePickerBase {
3035
createNativeView() {
3136
const picker = UIDatePicker.new();
3237
picker.datePickerMode = UIDatePickerMode.Time;
33-
38+
if (SUPPORT_DATE_PICKER_STYLE) {
39+
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
40+
}
3441
return picker;
3542
}
3643

@@ -106,11 +113,13 @@ export class TimePicker extends TimePickerBase {
106113
}
107114

108115
[colorProperty.getDefault](): UIColor {
109-
return this.nativeViewProtected.valueForKey('textColor');
116+
return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey('textColor') : UIColor.new();
110117
}
111118
[colorProperty.setNative](value: Color | UIColor) {
112-
const color = value instanceof Color ? value.ios : value;
113-
this.nativeViewProtected.setValueForKey(color, 'textColor');
119+
if (SUPPORT_TEXT_COLOR) {
120+
const color = value instanceof Color ? value.ios : value;
121+
this.nativeViewProtected.setValueForKey(color, 'textColor');
122+
}
114123
}
115124
}
116125

packages/types-ios/src/lib/ios/objc-x86_64/objc!UIKit.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6101,6 +6101,8 @@ declare class UIDatePicker extends UIControl implements NSCoding {
61016101

61026102
minuteInterval: number;
61036103

6104+
preferredDatePickerStyle: number;
6105+
61046106
timeZone: NSTimeZone;
61056107

61066108
constructor(o: { coder: NSCoder; }); // inherited from NSCoding

0 commit comments

Comments
 (0)