Skip to content

Commit dbefc43

Browse files
authored
fix(ios): preferredDatePickerStyle property (NativeScript#8899)
1 parent 53488b5 commit dbefc43

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

packages/core/ui/date-picker/date-picker-common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class DatePickerBase extends View implements DatePickerDefinition {
1313
public maxDate: Date;
1414
public minDate: Date;
1515
public date: Date;
16+
public iosPreferredDatePickerStyle: number;
1617
}
1718

1819
DatePickerBase.prototype.recycleNativeView = 'auto';
@@ -60,3 +61,10 @@ export const dateProperty = new Property<DatePickerBase, Date>({
6061
valueConverter: (v) => new Date(v),
6162
});
6263
dateProperty.register(DatePickerBase);
64+
65+
export const iosPreferredDatePickerStyleProperty = new Property<DatePickerBase, number>({
66+
name: 'iosPreferredDatePickerStyle',
67+
defaultValue: 0,
68+
valueConverter: (v) => parseInt(v),
69+
});
70+
iosPreferredDatePickerStyleProperty.register(DatePickerBase);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const dayProperty: Property<DatePicker, number>;
77
export const dateProperty: Property<DatePicker, Date>;
88
export const maxDate: Property<DatePicker, Date>;
99
export const minDate: Property<DatePicker, Date>;
10+
export const iosPreferredDatePickerStyleProperty: Property<DatePicker, number>;
1011

1112
/**
1213
* Represents an date picker.
@@ -51,4 +52,14 @@ export class DatePicker extends View {
5152
* Gets or sets the min date.
5253
*/
5354
minDate: Date;
55+
56+
/**
57+
* Gets or set the UIDatePickerStyle of the date picker in iOS 13.4+. Defaults to 0.
58+
* Valid values are numbers:
59+
* - 0: automatic (system picks the concrete style based on the current platform and date picker mode)
60+
* - 1: wheels (the date picker displays as a wheel picker)
61+
* - 2: compact (the date picker displays as a label that when tapped displays a calendar-style editor)
62+
* - 3: inline (the date pickers displays as an inline, editable field)
63+
*/
64+
iosPreferredDatePickerStyle: number;
5465
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { Device } from '../../platform';
55

66
export * from './date-picker-common';
77

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;
8+
const SUPPORT_DATE_PICKER_STYLE = parseFloat(Device.osVersion) >= 13.4;
9+
const SUPPORT_TEXT_COLOR = parseFloat(Device.osVersion) < 14.0;
1110

1211
export class DatePicker extends DatePickerBase {
1312
private _changeHandler: NSObject;
@@ -17,7 +16,7 @@ export class DatePicker extends DatePickerBase {
1716
const picker = UIDatePicker.new();
1817
picker.datePickerMode = UIDatePickerMode.Date;
1918
if (SUPPORT_DATE_PICKER_STYLE) {
20-
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
19+
picker.preferredDatePickerStyle = this.iosPreferredDatePickerStyle;
2120
}
2221
return picker;
2322
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ export class TimePicker extends View {
5454
* Gets or sets the minute interval.
5555
*/
5656
minuteInterval: number;
57+
58+
/**
59+
* Gets or set the UIDatePickerStyle of the date picker in iOS 13.4+. Defaults to 0.
60+
* Valid values are numbers:
61+
* - 0: automatic (system picks the concrete style based on the current platform and date picker mode)
62+
* - 1: wheels (the date picker displays as a wheel picker)
63+
* - 2: compact (the date picker displays as a label that when tapped displays a calendar-style editor)
64+
* - 3: inline (the date pickers displays as an inline, editable field)
65+
*/
66+
iosPreferredDatePickerStyle: number;
5767
}
5868

5969
export const hourProperty: Property<TimePicker, number>;
@@ -66,3 +76,5 @@ export const minMinuteProperty: Property<TimePicker, number>;
6676

6777
export const timeProperty: Property<TimePicker, Date>;
6878
export const minuteIntervalProperty: Property<TimePicker, number>;
79+
80+
export const iosPreferredDatePickerStyleProperty: Property<TimePicker, number>;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { Device } from '../../platform';
55

66
export * from './time-picker-common';
77

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;
8+
const SUPPORT_DATE_PICKER_STYLE = parseFloat(Device.osVersion) >= 13.4;
9+
const SUPPORT_TEXT_COLOR = parseFloat(Device.osVersion) < 14.0;
1110

1211
function getDate(hour: number, minute: number): Date {
1312
let components = NSDateComponents.alloc().init();
@@ -36,7 +35,7 @@ export class TimePicker extends TimePickerBase {
3635
const picker = UIDatePicker.new();
3736
picker.datePickerMode = UIDatePickerMode.Time;
3837
if (SUPPORT_DATE_PICKER_STYLE) {
39-
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
38+
picker.preferredDatePickerStyle = this.iosPreferredDatePickerStyle;
4039
}
4140
return picker;
4241
}

packages/core/ui/time-picker/time-picker-common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export abstract class TimePickerBase extends View implements TimePickerDefinitio
9898
public maxHour: number;
9999
public minMinute: number;
100100
public maxMinute: number;
101+
public iosPreferredDatePickerStyle: number;
101102
}
102103

103104
TimePickerBase.prototype.recycleNativeView = 'auto';
@@ -204,3 +205,10 @@ export const timeProperty = new Property<TimePickerBase, Date>({
204205
},
205206
});
206207
timeProperty.register(TimePickerBase);
208+
209+
export const iosPreferredDatePickerStyleProperty = new Property<TimePickerBase, number>({
210+
name: 'iosPreferredDatePickerStyle',
211+
defaultValue: 0,
212+
valueConverter: (v) => parseInt(v),
213+
});
214+
iosPreferredDatePickerStyleProperty.register(TimePickerBase);

0 commit comments

Comments
 (0)