fix(ios): preferredDatePickerStyle (#8906)

This commit is contained in:
André Sharghi
2020-09-26 08:05:12 +02:00
committed by GitHub
parent 57ac51421c
commit bd93060e8d
6 changed files with 45 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ export class DatePickerBase extends View implements DatePickerDefinition {
public maxDate: Date;
public minDate: Date;
public date: Date;
public iosPreferredDatePickerStyle: number;
}
DatePickerBase.prototype.recycleNativeView = "auto";
@@ -61,3 +62,10 @@ export const dateProperty = new Property<DatePickerBase, Date>({
valueConverter: v => new Date(v),
});
dateProperty.register(DatePickerBase);
export const iosPreferredDatePickerStyleProperty = new Property<DatePickerBase, number>({
name: 'iosPreferredDatePickerStyle',
defaultValue: 0,
valueConverter: (v) => parseInt(v),
});
iosPreferredDatePickerStyleProperty.register(DatePickerBase);

View File

@@ -11,6 +11,7 @@ export const dayProperty: Property<DatePicker, number>;
export const dateProperty: Property<DatePicker, Date>;
export const maxDate: Property<DatePicker, Date>;
export const minDate: Property<DatePicker, Date>;
export const iosPreferredDatePickerStyleProperty: Property<DatePicker, number>;
/**
* Represents an date picker.
@@ -55,4 +56,14 @@ export class DatePicker extends View {
* Gets or sets the min date.
*/
minDate: Date;
/**
* Gets or set the UIDatePickerStyle of the date picker in iOS 13.4+. Defaults to 0.
* Valid values are numbers:
* - 0: automatic (system picks the concrete style based on the current platform and date picker mode)
* - 1: wheels (the date picker displays as a wheel picker)
* - 2: compact (the date picker displays as a label that when tapped displays a calendar-style editor)
* - 3: inline (the date pickers displays as an inline, editable field)
*/
iosPreferredDatePickerStyle: number;
}

View File

@@ -5,9 +5,8 @@ import {
import { device } from '../../platform';
export * from "./date-picker-common";
const SUPPORT_DATE_PICKER_STYLE = parseFloat(device.os) >= 14.0;
const SUPPORT_TEXT_COLOR = parseFloat(device.os) < 14.0;
const DEFAULT_DATE_PICKER_STYLE = 1;
const SUPPORT_DATE_PICKER_STYLE = parseFloat(device.osVersion) >= 13.4;
const SUPPORT_TEXT_COLOR = parseFloat(device.osVersion) < 14.0;
export class DatePicker extends DatePickerBase {
private _changeHandler: NSObject;
@@ -17,7 +16,7 @@ export class DatePicker extends DatePickerBase {
const picker = UIDatePicker.new();
picker.datePickerMode = UIDatePickerMode.Date;
if (SUPPORT_DATE_PICKER_STYLE) {
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
picker.preferredDatePickerStyle = this.iosPreferredDatePickerStyle;
}
return picker;
}

View File

@@ -99,6 +99,7 @@ export abstract class TimePickerBase extends View implements TimePickerDefinitio
public maxHour: number;
public minMinute: number;
public maxMinute: number;
public iosPreferredDatePickerStyle: number;
}
TimePickerBase.prototype.recycleNativeView = "auto";
@@ -184,3 +185,10 @@ export const timeProperty = new Property<TimePickerBase, Date>({
}
});
timeProperty.register(TimePickerBase);
export const iosPreferredDatePickerStyleProperty = new Property<TimePickerBase, number>({
name: 'iosPreferredDatePickerStyle',
defaultValue: 0,
valueConverter: (v) => parseInt(v),
});
iosPreferredDatePickerStyleProperty.register(TimePickerBase);

View File

@@ -58,6 +58,16 @@ export class TimePicker extends View {
* Gets or sets the minute interval.
*/
minuteInterval: number;
/**
* Gets or set the UIDatePickerStyle of the date picker in iOS 13.4+. Defaults to 0.
* Valid values are numbers:
* - 0: automatic (system picks the concrete style based on the current platform and date picker mode)
* - 1: wheels (the date picker displays as a wheel picker)
* - 2: compact (the date picker displays as a label that when tapped displays a calendar-style editor)
* - 3: inline (the date pickers displays as an inline, editable field)
*/
iosPreferredDatePickerStyle: number;
}
export const hourProperty: Property<TimePicker, number>;
@@ -70,3 +80,5 @@ export const minMinuteProperty: Property<TimePicker, number>;
export const timeProperty: Property<TimePicker, Date>;
export const minuteIntervalProperty: Property<TimePicker, number>;
export const iosPreferredDatePickerStyleProperty: Property<TimePicker, number>;

View File

@@ -6,9 +6,8 @@ import {
import { device } from '../../platform';
export * from "./time-picker-common";
const SUPPORT_DATE_PICKER_STYLE = parseFloat(device.os) >= 14.0;
const SUPPORT_TEXT_COLOR = parseFloat(device.os) < 14.0;
const DEFAULT_DATE_PICKER_STYLE = 1;
const SUPPORT_DATE_PICKER_STYLE = parseFloat(device.osVersion) >= 13.4;
const SUPPORT_TEXT_COLOR = parseFloat(device.osVersion) < 14.0;
function getDate(hour: number, minute: number): Date {
let components = NSDateComponents.alloc().init();
@@ -37,7 +36,7 @@ export class TimePicker extends TimePickerBase {
const picker = UIDatePicker.new();
picker.datePickerMode = UIDatePickerMode.Time;
if (SUPPORT_DATE_PICKER_STYLE) {
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
picker.preferredDatePickerStyle = this.iosPreferredDatePickerStyle;
}
return picker;
}