From 4f4df05e8be8789938fb715bf94fc57e3fb55026 Mon Sep 17 00:00:00 2001 From: tgpetrov Date: Tue, 29 Oct 2019 19:09:34 +0200 Subject: [PATCH] fix: styles don't work with ios13 --- src/datetimepicker.ios.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/datetimepicker.ios.ts b/src/datetimepicker.ios.ts index 89dc264..bceac1f 100644 --- a/src/datetimepicker.ios.ts +++ b/src/datetimepicker.ios.ts @@ -81,8 +81,7 @@ export class DateTimePicker extends DateTimePickerBase { pickerContainerFrameTop += DateTimePicker.PICKER_DEFAULT_TITLE_HEIGHT; } const pickerViewHeight = DateTimePicker.PICKER_DEFAULT_MESSAGE_HEIGHT; - const pickerContainerFrame = CGRectMake(0, pickerContainerFrameTop, pickerViewWidth, pickerViewHeight); - const pickerContainer = UIView.alloc().initWithFrame(pickerContainerFrame); + const pickerContainer = UIView.alloc().init(); let spinnersBackgroundColor = new Color("transparent"); let spinnersTextColor = null; if (style) { @@ -94,12 +93,22 @@ export class DateTimePicker extends DateTimePickerBase { const pickerView = nativePicker; pickerView.frame = CGRectMake(0, 0, pickerViewWidth, pickerViewHeight); pickerContainer.addSubview(pickerView); + DateTimePicker._clearVibrancyEffects(alertController.view); const messageLabel = DateTimePicker._findLabelWithText(alertController.view, DateTimePicker.PICKER_DEFAULT_MESSAGE); - const messageLabelContainer = messageLabel.superview; + const messageLabelContainer = DateTimePicker._getLabelContainer(messageLabel); messageLabelContainer.clipsToBounds = true; messageLabelContainer.addSubview(pickerContainer); + pickerContainer.translatesAutoresizingMaskIntoConstraints = false; + pickerContainer.topAnchor.constraintEqualToAnchorConstant(alertController.view.topAnchor, pickerContainerFrameTop).active = true; + pickerContainer.leftAnchor.constraintEqualToAnchor(alertController.view.leftAnchor).active = true; + pickerContainer.rightAnchor.constraintEqualToAnchor(alertController.view.rightAnchor).active = true; + pickerContainer.bottomAnchor.constraintEqualToAnchor(alertController.view.bottomAnchor).active = true; + + pickerView.leftAnchor.constraintLessThanOrEqualToAnchorConstant(pickerContainer.leftAnchor, DateTimePicker.PICKER_WIDTH_INSETS).active = true; + pickerView.rightAnchor.constraintLessThanOrEqualToAnchorConstant(pickerContainer.rightAnchor, DateTimePicker.PICKER_WIDTH_INSETS).active = true; + const cancelButtonText = options.cancelButtonText ? options.cancelButtonText : "Cancel"; const okButtonText = options.okButtonText ? options.okButtonText : "OK"; const cancelActionStyle = (style && style.buttonCancelBackgroundColor) ? UIAlertActionStyle.Default : UIAlertActionStyle.Cancel; @@ -169,6 +178,7 @@ export class DateTimePicker extends DateTimePickerBase { } if (color) { nativePicker.setValueForKey(color.ios, "textColor"); + nativePicker.setValueForKey(false, "highlightsToday"); } } @@ -201,6 +211,25 @@ export class DateTimePicker extends DateTimePickerBase { } } + private static _clearVibrancyEffects(uiView: UIView) { + if (uiView instanceof UIVisualEffectView && uiView.effect instanceof UIVibrancyEffect) { + // Since ios13 UIAlertController has some effects which cause + // semi-transparency and interfere with color customizations: + uiView.effect = null; + } + const subViewsCount = uiView.subviews.count; + for (let i = 0; i < subViewsCount; i++) { + DateTimePicker._clearVibrancyEffects(uiView.subviews[i]); + } + } + + private static _getLabelContainer(uiView: UIView) { + if (uiView.superview.class() === (UIView.class())) { + return uiView.superview; + } + return DateTimePicker._getLabelContainer(uiView.superview); + } + private static _findLabelWithText(uiView: UIView, text: string) { if ((uiView instanceof UILabel) && uiView.text === text) { return uiView;