Skip to content

Commit cf894d5

Browse files
authored
fix(datetimepicker): spinner & calendar ipads display issue (#173)
closes #128
1 parent f97a07c commit cf894d5

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

apps/demo-angular/src/plugin-demos/datetimepicker.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<DatePickerField minDate="2020/02/02" maxDate="2021/02/02" hint="tap to select"></DatePickerField>
1818
<StackLayout class="hr-light m-10" android:visibility="collapse"></StackLayout>
1919

20+
<!-- iOS 14+ defaults to calendar type so show example of spinner type also. -->
21+
<Label text="Spinner type" class="content" *ngIf="isIOS14plus"></Label>
22+
<DatePickerField hint="select date" iosPreferredDatePickerStyle="1" *ngIf="isIOS14plus"></DatePickerField>
23+
<StackLayout class="hr-light m-10" android:visibility="collapse" *ngIf="isIOS14plus"></StackLayout>
24+
2025
<Label text="modified picker texts" class="content"></Label>
2126
<DatePickerField hint="tap to choose" pickerOkText="Approve" pickerCancelText="Reject" pickerTitle="Confirm predefined date selection" pickerDefaultDate="2019/05/15"></DatePickerField>
2227
<StackLayout class="hr-light m-10" android:visibility="collapse"></StackLayout>

apps/demo-angular/src/plugin-demos/datetimepicker.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, NgZone, ViewChild, ElementRef } from '@angular/core';
2-
import { EventData, Button } from '@nativescript/core';
2+
import { Device, EventData, isIOS, Button } from '@nativescript/core';
33
import { DateTimePicker } from '@nativescript/datetimepicker';
44

55
@Component({
@@ -73,6 +73,7 @@ export class DatetimepickerComponent {
7373
public timeVisibility: string;
7474
public dateTimeVisibility: string;
7575
public customVisibility: string;
76+
public isIOS14plus = isIOS && parseFloat(Device.osVersion) >= 14.0;
7677
private _expandedId: string;
7778

7879
@ViewChild('scrollView', { static: false }) scrollView: ElementRef;

apps/demo/src/plugin-demos/datetimepicker.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
navigatingTo="navigatingTo"
33
xmlns="http://schemas.nativescript.org/tns.xsd"
44
xmlns:datetime="@nativescript/datetimepicker">
5-
5+
66
<ActionBar class="action-bar">
77
<Label class="action-bar-title" text="DateTimePicker Demo TS"></Label>
88
</ActionBar>
@@ -23,6 +23,11 @@
2323
<datetime:DatePickerField minDate="2020/02/02" maxDate="2021/02/02" hint="tap to select"/>
2424
<StackLayout class="hr-light m-10" android:visibility="collapse"/>
2525

26+
<!-- iOS 14+ defaults to calendar type so show example of spinner type also. -->
27+
<Label text="Spinner type" class="content" visibility="{{ isIOS14plus ? 'visible' : 'collapsed' }}"/>
28+
<datetime:DatePickerField hint="select date" iosPreferredDatePickerStyle="1" visibility="{{ isIOS14plus ? 'visible' : 'collapsed' }}"/>
29+
<StackLayout class="hr-light m-10" android:visibility="collapse" visibility="{{ isIOS14plus ? 'visible' : 'collapsed' }}"/>
30+
2631
<Label text="modified picker texts" class="content"/>
2732
<datetime:DatePickerField hint="tap to choose" pickerOkText="Approve" pickerCancelText="Reject"
2833
pickerTitle="Confirm predefined date selection" pickerDefaultDate="2019/05/15"/>

packages/datetimepicker/index.ios.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class DateTimePicker extends DateTimePickerBase {
1111
private static readonly SUPPORT_TEXT_COLOR = parseFloat(Device.osVersion) < 14.0;
1212
private static readonly DEFAULT_DATE_PICKER_STYLE = parseFloat(Device.osVersion) >= 14.0 ? 3 : 1;
1313
private static readonly DEFAULT_TIME_PICKER_STYLE = 1;
14+
private static readonly _isTablet = Device.deviceType === 'Tablet';
1415

1516
public static PICKER_DEFAULT_MESSAGE_HEIGHT = parseFloat(Device.osVersion) >= 14.0 ? 300 : 192;
1617
public static PICKER_WIDTH_INSETS = 16;
@@ -103,14 +104,18 @@ export class DateTimePicker extends DateTimePickerBase {
103104
DateTimePicker._applyDialogSpinnersColors(nativePicker, pickerContainer, spinnersTextColor, spinnersBackgroundColor);
104105

105106
const pickerView = nativePicker;
106-
const left = (alertController.view.frame.size.width - pickerViewWidth) / 2 - DateTimePicker.PICKER_WIDTH_INSETS;
107+
const left = this._isTablet ? 0 : (alertController.view.frame.size.width - pickerViewWidth) / 2 - DateTimePicker.PICKER_WIDTH_INSETS;
107108
pickerView.frame = CGRectMake(left, 0, pickerViewWidth, pickerViewHeight);
108109
pickerContainer.addSubview(pickerView);
109110
DateTimePicker._clearVibrancyEffects(alertController.view);
110111

111112
const messageLabel = DateTimePicker._findLabelWithText(alertController.view, DateTimePicker.PICKER_DEFAULT_MESSAGE);
112113
const messageLabelContainer = DateTimePicker._getLabelContainer(messageLabel);
113-
messageLabelContainer.clipsToBounds = true;
114+
if (this._isTablet) {
115+
messageLabelContainer.clipsToBounds = false;
116+
} else {
117+
messageLabelContainer.clipsToBounds = true;
118+
}
114119
messageLabelContainer.addSubview(pickerContainer);
115120

116121
pickerContainer.translatesAutoresizingMaskIntoConstraints = false;

tools/demo/datetimepicker/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventData, ScrollView, Button } from '@nativescript/core';
1+
import { Device, EventData, isIOS, ScrollView, Button } from '@nativescript/core';
22
import { DemoSharedBase } from '../utils';
33
import { DateTimePicker } from '@nativescript/datetimepicker';
44

@@ -12,6 +12,7 @@ export class DemoSharedDatetimepicker extends DemoSharedBase {
1212
enabled1 = true;
1313
enabled2 = true;
1414
enabled3 = true;
15+
isIOS14plus = isIOS && parseFloat(Device.osVersion) >= 14.0;
1516
private scrollView: ScrollView;
1617

1718
constructor() {

0 commit comments

Comments
 (0)