Skip to content

fix(ios): time-picker and date-picker for iOS 14 #8876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions nativescript-core/ui/date-picker/date-picker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ 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;

public createNativeView() {
const picker = UIDatePicker.new();
picker.datePickerMode = UIDatePickerMode.Date;

if (SUPPORT_DATE_PICKER_STYLE) {
picker.preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
}
return picker;
}

Expand Down Expand Up @@ -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");
}
}
}

Expand Down
18 changes: 13 additions & 5 deletions nativescript-core/ui/time-picker/time-picker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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");
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tns-platform-declarations/ios/objc-x86_64/objc!UIKit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6101,6 +6101,8 @@ declare class UIDatePicker extends UIControl implements NSCoding {

minuteInterval: number;

preferredDatePickerStyle: number;

timeZone: NSTimeZone;

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