mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(ios): time-picker and date-picker for iOS 14 (#8876)
This commit is contained in:
@@ -2,9 +2,13 @@ import {
|
||||
DatePickerBase, yearProperty, monthProperty, dayProperty,
|
||||
dateProperty, maxDateProperty, minDateProperty, colorProperty, Color
|
||||
} from "./date-picker-common";
|
||||
|
||||
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;
|
||||
|
||||
export class DatePicker extends DatePickerBase {
|
||||
private _changeHandler: NSObject;
|
||||
public nativeViewProtected: UIDatePicker;
|
||||
@@ -12,7 +16,9 @@ export class DatePicker extends DatePickerBase {
|
||||
public createNativeView() {
|
||||
const picker = UIDatePicker.new();
|
||||
picker.datePickerMode = UIDatePickerMode.Date;
|
||||
|
||||
if (SUPPORT_DATE_PICKER_STYLE) {
|
||||
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
|
||||
}
|
||||
return picker;
|
||||
}
|
||||
|
||||
@@ -75,11 +81,13 @@ export class DatePicker extends DatePickerBase {
|
||||
}
|
||||
|
||||
[colorProperty.getDefault](): UIColor {
|
||||
return this.nativeViewProtected.valueForKey("textColor");
|
||||
return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey("textColor") : UIColor.new();
|
||||
}
|
||||
[colorProperty.setNative](value: Color | UIColor) {
|
||||
const picker = this.nativeViewProtected;
|
||||
picker.setValueForKey(value instanceof Color ? value.ios : value, "textColor");
|
||||
if (SUPPORT_TEXT_COLOR) {
|
||||
const picker = this.nativeViewProtected;
|
||||
picker.setValueForKey(value instanceof Color ? value.ios : value, "textColor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,13 @@ import {
|
||||
minuteProperty, minMinuteProperty, maxMinuteProperty,
|
||||
hourProperty, minHourProperty, maxHourProperty, colorProperty, Color
|
||||
} from "./time-picker-common";
|
||||
|
||||
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;
|
||||
|
||||
function getDate(hour: number, minute: number): Date {
|
||||
let components = NSDateComponents.alloc().init();
|
||||
components.hour = hour;
|
||||
@@ -32,7 +36,9 @@ export class TimePicker extends TimePickerBase {
|
||||
createNativeView() {
|
||||
const picker = UIDatePicker.new();
|
||||
picker.datePickerMode = UIDatePickerMode.Time;
|
||||
|
||||
if (SUPPORT_DATE_PICKER_STYLE) {
|
||||
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
|
||||
}
|
||||
return picker;
|
||||
}
|
||||
|
||||
@@ -108,11 +114,13 @@ export class TimePicker extends TimePickerBase {
|
||||
}
|
||||
|
||||
[colorProperty.getDefault](): UIColor {
|
||||
return this.nativeViewProtected.valueForKey("textColor");
|
||||
return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey("textColor") : UIColor.new();
|
||||
}
|
||||
[colorProperty.setNative](value: Color | UIColor) {
|
||||
const color = value instanceof Color ? value.ios : value;
|
||||
this.nativeViewProtected.setValueForKey(color, "textColor");
|
||||
if (SUPPORT_TEXT_COLOR) {
|
||||
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;
|
||||
|
||||
preferredDatePickerStyle: number;
|
||||
|
||||
timeZone: NSTimeZone;
|
||||
|
||||
constructor(o: { coder: NSCoder; }); // inherited from NSCoding
|
||||
|
||||
Reference in New Issue
Block a user