mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
fix(ios): time-picker and date-picker for iOS 14 (#8877)
This commit is contained in:
@ -1,9 +1,14 @@
|
|||||||
import { DatePickerBase, yearProperty, monthProperty, dayProperty, dateProperty, maxDateProperty, minDateProperty } from './date-picker-common';
|
import { DatePickerBase, yearProperty, monthProperty, dayProperty, dateProperty, maxDateProperty, minDateProperty } from './date-picker-common';
|
||||||
import { colorProperty } from '../styling/style-properties';
|
import { colorProperty } from '../styling/style-properties';
|
||||||
import { Color } from '../../color';
|
import { Color } from '../../color';
|
||||||
|
import { Device } from '../../platform';
|
||||||
|
|
||||||
export * from './date-picker-common';
|
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;
|
||||||
|
|
||||||
export class DatePicker extends DatePickerBase {
|
export class DatePicker extends DatePickerBase {
|
||||||
private _changeHandler: NSObject;
|
private _changeHandler: NSObject;
|
||||||
public nativeViewProtected: UIDatePicker;
|
public nativeViewProtected: UIDatePicker;
|
||||||
@ -11,7 +16,9 @@ export class DatePicker extends DatePickerBase {
|
|||||||
public createNativeView() {
|
public createNativeView() {
|
||||||
const picker = UIDatePicker.new();
|
const picker = UIDatePicker.new();
|
||||||
picker.datePickerMode = UIDatePickerMode.Date;
|
picker.datePickerMode = UIDatePickerMode.Date;
|
||||||
|
if (SUPPORT_DATE_PICKER_STYLE) {
|
||||||
|
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
|
||||||
|
}
|
||||||
return picker;
|
return picker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,11 +81,13 @@ export class DatePicker extends DatePickerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[colorProperty.getDefault](): UIColor {
|
[colorProperty.getDefault](): UIColor {
|
||||||
return this.nativeViewProtected.valueForKey('textColor');
|
return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey('textColor') : UIColor.new();
|
||||||
}
|
}
|
||||||
[colorProperty.setNative](value: Color | UIColor) {
|
[colorProperty.setNative](value: Color | UIColor) {
|
||||||
const picker = this.nativeViewProtected;
|
if (SUPPORT_TEXT_COLOR) {
|
||||||
picker.setValueForKey(value instanceof Color ? value.ios : value, 'textColor');
|
const picker = this.nativeViewProtected;
|
||||||
|
picker.setValueForKey(value instanceof Color ? value.ios : value, 'textColor');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import { TimePickerBase, timeProperty, minuteIntervalProperty, minuteProperty, minMinuteProperty, maxMinuteProperty, hourProperty, minHourProperty, maxHourProperty } from './time-picker-common';
|
import { TimePickerBase, timeProperty, minuteIntervalProperty, minuteProperty, minMinuteProperty, maxMinuteProperty, hourProperty, minHourProperty, maxHourProperty } from './time-picker-common';
|
||||||
import { Color } from '../../color';
|
import { Color } from '../../color';
|
||||||
import { colorProperty } from '../styling/style-properties';
|
import { colorProperty } from '../styling/style-properties';
|
||||||
|
import { Device } from '../../platform';
|
||||||
|
|
||||||
export * from './time-picker-common';
|
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;
|
||||||
|
|
||||||
function getDate(hour: number, minute: number): Date {
|
function getDate(hour: number, minute: number): Date {
|
||||||
let components = NSDateComponents.alloc().init();
|
let components = NSDateComponents.alloc().init();
|
||||||
components.hour = hour;
|
components.hour = hour;
|
||||||
@ -30,7 +35,9 @@ export class TimePicker extends TimePickerBase {
|
|||||||
createNativeView() {
|
createNativeView() {
|
||||||
const picker = UIDatePicker.new();
|
const picker = UIDatePicker.new();
|
||||||
picker.datePickerMode = UIDatePickerMode.Time;
|
picker.datePickerMode = UIDatePickerMode.Time;
|
||||||
|
if (SUPPORT_DATE_PICKER_STYLE) {
|
||||||
|
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
|
||||||
|
}
|
||||||
return picker;
|
return picker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,11 +113,13 @@ export class TimePicker extends TimePickerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[colorProperty.getDefault](): UIColor {
|
[colorProperty.getDefault](): UIColor {
|
||||||
return this.nativeViewProtected.valueForKey('textColor');
|
return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey('textColor') : UIColor.new();
|
||||||
}
|
}
|
||||||
[colorProperty.setNative](value: Color | UIColor) {
|
[colorProperty.setNative](value: Color | UIColor) {
|
||||||
const color = value instanceof Color ? value.ios : value;
|
if (SUPPORT_TEXT_COLOR) {
|
||||||
this.nativeViewProtected.setValueForKey(color, 'textColor');
|
const color = value instanceof Color ? value.ios : value;
|
||||||
|
this.nativeViewProtected.setValueForKey(color, 'textColor');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6101,6 +6101,8 @@ declare class UIDatePicker extends UIControl implements NSCoding {
|
|||||||
|
|
||||||
minuteInterval: number;
|
minuteInterval: number;
|
||||||
|
|
||||||
|
preferredDatePickerStyle: number;
|
||||||
|
|
||||||
timeZone: NSTimeZone;
|
timeZone: NSTimeZone;
|
||||||
|
|
||||||
constructor(o: { coder: NSCoder; }); // inherited from NSCoding
|
constructor(o: { coder: NSCoder; }); // inherited from NSCoding
|
||||||
|
Reference in New Issue
Block a user