Skip to content
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

(^) fix ios 14 #69

Merged
merged 3 commits into from
Sep 28, 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
44 changes: 27 additions & 17 deletions src/modal-datetimepicker.android.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* tslint:disable */
// 第三方的套件,在別人修正前先臨時用
import * as app from "tns-core-modules/application";

export class ModalDatetimepicker {
datePicker: android.app.DatePickerDialog;
timePicker;
constructor() {}

public pickDate(options: PickerOptions = {}) {
public pickDate(options: PickerOptions = {}): Promise<DateResponse> {
return new Promise((resolve, reject) => {
if (
options.startingDate &&
Expand All @@ -22,7 +24,9 @@ export class ModalDatetimepicker {

// let now = Calendar.getInstance();
let startDate = new Date();
if (options.startingDate) startDate = options.startingDate;
if (options.startingDate) {
startDate = options.startingDate;
}

try {
this.datePicker = new android.app.DatePickerDialog(
Expand All @@ -43,18 +47,22 @@ export class ModalDatetimepicker {
);

if (options.maxDate || options.minDate) {
let datePickerInstance = this.datePicker.getDatePicker();
if (options.maxDate)
const datePickerInstance = this.datePicker.getDatePicker();
if (options.maxDate) {
datePickerInstance.setMaxDate(options.maxDate.getTime());
if (options.minDate)
}
if (options.minDate) {
datePickerInstance.setMinDate(options.minDate.getTime());
}
}

this.datePicker.setOnCancelListener(new android.content.DialogInterface.OnCancelListener({
onCancel: () => {
resolve();
}
}));
this.datePicker.setOnCancelListener(
new android.content.DialogInterface.OnCancelListener({
onCancel: () => {
resolve();
}
})
);

this.datePicker.show();
} catch (err) {
Expand All @@ -74,10 +82,10 @@ export class ModalDatetimepicker {
}
}

public pickTime(options: PickerOptions = {}) {
public pickTime(options: PickerOptions = {}): Promise<TimeResponse> {
options.is24HourView = options.is24HourView || false;
return new Promise((resolve, reject) => {
let now = java.util.Calendar.getInstance();
const now = java.util.Calendar.getInstance();
const hour =
options.startingHour !== undefined && options.startingHour >= 0
? +options.startingHour
Expand All @@ -103,11 +111,13 @@ export class ModalDatetimepicker {
options.is24HourView
);

this.timePicker.setOnCancelListener(new android.content.DialogInterface.OnCancelListener({
onCancel: () => {
resolve();
}
}));
this.timePicker.setOnCancelListener(
new android.content.DialogInterface.OnCancelListener({
onCancel: () => {
resolve();
}
})
);

this.timePicker.show();

Expand Down
8 changes: 8 additions & 0 deletions src/modal-datetimepicker.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as frame from "tns-core-modules/ui/frame";
import { Label } from "tns-core-modules/ui/label/";
import { Page } from "tns-core-modules/ui/page";
import { Color } from "tns-core-modules/ui/frame";
import { device } from "tns-core-modules/platform";

class ButtonHandler extends NSObject {
public close(nativeButton: UIButton, nativeEvent: _UIEvent) {
Expand Down Expand Up @@ -44,6 +45,10 @@ let titleLabel: UILabel;
// let minMaxLabel: UILabel;
let datePickerView: UIDatePicker;

const SUPPORT_DATE_PICKER_STYLE = parseFloat(device.osVersion) >= 14.0;
const SUPPORT_TEXT_COLOR = parseFloat(device.osVersion) < 14.0;
const DEFAULT_DATE_PICKER_STYLE = 1;

export class ModalDatetimepicker {
constructor() {}

Expand Down Expand Up @@ -281,6 +286,9 @@ export class ModalDatetimepicker {
);
datePickerView.datePickerMode =
options.type === "date" ? UIDatePickerMode.Date : UIDatePickerMode.Time;
if (SUPPORT_DATE_PICKER_STYLE) {
(datePickerView as any).preferredDatePickerStyle = DEFAULT_DATE_PICKER_STYLE;
}
datePickerView.autoresizingMask = UIViewAutoresizing.FlexibleWidth;
datePickerView.date = startingDate;
if (options.minDate) datePickerView.minimumDate = options.minDate;
Expand Down
Loading