Skip to content

Commit f337369

Browse files
authored
Merge pull request #54 from NativeScript/tgpetrov/ios13-issue
fix: styles don't work with ios13
2 parents 6abfb35 + 4f4df05 commit f337369

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/datetimepicker.ios.ts

+32-3
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export class DateTimePicker extends DateTimePickerBase {
8181
pickerContainerFrameTop += DateTimePicker.PICKER_DEFAULT_TITLE_HEIGHT;
8282
}
8383
const pickerViewHeight = DateTimePicker.PICKER_DEFAULT_MESSAGE_HEIGHT;
84-
const pickerContainerFrame = CGRectMake(0, pickerContainerFrameTop, pickerViewWidth, pickerViewHeight);
85-
const pickerContainer = UIView.alloc().initWithFrame(pickerContainerFrame);
84+
const pickerContainer = UIView.alloc().init();
8685
let spinnersBackgroundColor = new Color("transparent");
8786
let spinnersTextColor = null;
8887
if (style) {
@@ -94,12 +93,22 @@ export class DateTimePicker extends DateTimePickerBase {
9493
const pickerView = nativePicker;
9594
pickerView.frame = CGRectMake(0, 0, pickerViewWidth, pickerViewHeight);
9695
pickerContainer.addSubview(pickerView);
96+
DateTimePicker._clearVibrancyEffects(alertController.view);
9797

9898
const messageLabel = DateTimePicker._findLabelWithText(alertController.view, DateTimePicker.PICKER_DEFAULT_MESSAGE);
99-
const messageLabelContainer = messageLabel.superview;
99+
const messageLabelContainer = DateTimePicker._getLabelContainer(messageLabel);
100100
messageLabelContainer.clipsToBounds = true;
101101
messageLabelContainer.addSubview(pickerContainer);
102102

103+
pickerContainer.translatesAutoresizingMaskIntoConstraints = false;
104+
pickerContainer.topAnchor.constraintEqualToAnchorConstant(alertController.view.topAnchor, pickerContainerFrameTop).active = true;
105+
pickerContainer.leftAnchor.constraintEqualToAnchor(alertController.view.leftAnchor).active = true;
106+
pickerContainer.rightAnchor.constraintEqualToAnchor(alertController.view.rightAnchor).active = true;
107+
pickerContainer.bottomAnchor.constraintEqualToAnchor(alertController.view.bottomAnchor).active = true;
108+
109+
pickerView.leftAnchor.constraintLessThanOrEqualToAnchorConstant(pickerContainer.leftAnchor, DateTimePicker.PICKER_WIDTH_INSETS).active = true;
110+
pickerView.rightAnchor.constraintLessThanOrEqualToAnchorConstant(pickerContainer.rightAnchor, DateTimePicker.PICKER_WIDTH_INSETS).active = true;
111+
103112
const cancelButtonText = options.cancelButtonText ? options.cancelButtonText : "Cancel";
104113
const okButtonText = options.okButtonText ? options.okButtonText : "OK";
105114
const cancelActionStyle = (style && style.buttonCancelBackgroundColor) ? UIAlertActionStyle.Default : UIAlertActionStyle.Cancel;
@@ -169,6 +178,7 @@ export class DateTimePicker extends DateTimePickerBase {
169178
}
170179
if (color) {
171180
nativePicker.setValueForKey(color.ios, "textColor");
181+
nativePicker.setValueForKey(false, "highlightsToday");
172182
}
173183
}
174184

@@ -201,6 +211,25 @@ export class DateTimePicker extends DateTimePickerBase {
201211
}
202212
}
203213

214+
private static _clearVibrancyEffects(uiView: UIView) {
215+
if (uiView instanceof UIVisualEffectView && uiView.effect instanceof UIVibrancyEffect) {
216+
// Since ios13 UIAlertController has some effects which cause
217+
// semi-transparency and interfere with color customizations:
218+
uiView.effect = null;
219+
}
220+
const subViewsCount = uiView.subviews.count;
221+
for (let i = 0; i < subViewsCount; i++) {
222+
DateTimePicker._clearVibrancyEffects(uiView.subviews[i]);
223+
}
224+
}
225+
226+
private static _getLabelContainer(uiView: UIView) {
227+
if (uiView.superview.class() === (UIView.class())) {
228+
return uiView.superview;
229+
}
230+
return DateTimePicker._getLabelContainer(uiView.superview);
231+
}
232+
204233
private static _findLabelWithText(uiView: UIView, text: string) {
205234
if ((uiView instanceof UILabel) && uiView.text === text) {
206235
return uiView;

0 commit comments

Comments
 (0)