Skip to content

fix(ios) Fixed iOS 14 display error #76

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 3 commits into from
Oct 2, 2020
Merged
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
17 changes: 15 additions & 2 deletions src/datetimepicker.ios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Color } from "tns-core-modules/color";
import { View, ios as iosView } from "tns-core-modules/ui/core/view";
import { device } from "tns-core-modules/platform";
import {
DateTimePickerBase, DateTimePickerStyleBase, getCurrentPage,
DatePickerOptions, TimePickerOptions, PickerOptions
Expand All @@ -11,6 +12,10 @@ export class DateTimePickerStyle extends DateTimePickerStyleBase {
}

export class DateTimePicker extends DateTimePickerBase {
private static readonly SUPPORT_DATE_PICKER_STYLE = parseFloat(device.osVersion) >= 14.0;
private static readonly SUPPORT_TEXT_COLOR = parseFloat(device.osVersion) < 14.0;
private static readonly DEFAULT_DATE_PICKER_STYLE = 1;

public static PICKER_DEFAULT_MESSAGE_HEIGHT = 192;
public static PICKER_WIDTH_INSETS = 16;
public static PICKER_WIDTH_PAD = 304;
Expand Down Expand Up @@ -43,6 +48,9 @@ export class DateTimePicker extends DateTimePickerBase {
static _createNativeDatePicker(options: DatePickerOptions): UIDatePicker {
const pickerView = UIDatePicker.alloc().initWithFrame(CGRectZero);
pickerView.datePickerMode = UIDatePickerMode.Date;
if (this.SUPPORT_DATE_PICKER_STYLE) {
(pickerView as any).preferredDatePickerStyle = this.DEFAULT_DATE_PICKER_STYLE;
}
const date = options.date ? options.date : getDateToday();
pickerView.date = date;
if (options.maxDate) {
Expand All @@ -60,6 +68,9 @@ export class DateTimePicker extends DateTimePickerBase {
static _createNativeTimePicker(options: TimePickerOptions): UIDatePicker {
const pickerView = UIDatePicker.alloc().initWithFrame(CGRectZero);
pickerView.datePickerMode = UIDatePickerMode.Time;
if (this.SUPPORT_DATE_PICKER_STYLE) {
(pickerView as any).preferredDatePickerStyle = this.DEFAULT_DATE_PICKER_STYLE;
}
const time = options.time ? options.time : getDateNow();
pickerView.date = time;
if (options.locale) {
Expand Down Expand Up @@ -177,7 +188,9 @@ export class DateTimePicker extends DateTimePickerBase {
nativeContainer.backgroundColor = backgroundColor.ios;
}
if (color) {
nativePicker.setValueForKey(color.ios, "textColor");
if (this.SUPPORT_TEXT_COLOR) {
nativePicker.setValueForKey(color, 'textColor');
}
nativePicker.setValueForKey(false, "highlightsToday");
}
}
Expand Down Expand Up @@ -243,4 +256,4 @@ export class DateTimePicker extends DateTimePickerBase {
}
return null;
}
}
}