diff --git a/src/Compatibility/Core/src/Android/Renderers/DatePickerRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/DatePickerRenderer.cs index 37c00e191ffc..00dd9371e617 100644 --- a/src/Compatibility/Core/src/Android/Renderers/DatePickerRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/DatePickerRenderer.cs @@ -112,6 +112,7 @@ protected virtual DatePickerDialog CreateDatePickerDialog(int year, int month, i return dialog; } + [PortHandler] void DeviceInfoPropertyChanged(object sender, DisplayInfoChangedEventArgs e) { DatePickerDialog currentDialog = _dialog; diff --git a/src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs b/src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs index f904a1eb1468..19524aa5ccd8 100644 --- a/src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs +++ b/src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs @@ -1,6 +1,8 @@ -using Android.App; +using System; +using Android.App; using Android.Content.Res; using Android.Graphics.Drawables; +using Microsoft.Maui.Essentials; namespace Microsoft.Maui.Handlers { @@ -32,6 +34,8 @@ protected override MauiDatePicker CreatePlatformView() protected override void ConnectHandler(MauiDatePicker platformView) { base.ConnectHandler(platformView); + + DeviceDisplay.MainDisplayInfoChanged += OnMainDisplayInfoChanged; SetupDefaults(platformView); } @@ -46,10 +50,13 @@ protected override void DisconnectHandler(MauiDatePicker platformView) { if (_dialog != null) { + _dialog.CancelEvent -= OnCancelButtonClicked; _dialog.Hide(); _dialog.Dispose(); _dialog = null; } + + DeviceDisplay.MainDisplayInfoChanged -= OnMainDisplayInfoChanged; base.DisconnectHandler(platformView); } @@ -134,6 +141,8 @@ void ShowPickerDialog(int year, int month, int day) else _dialog.UpdateDate(year, month, day); + _dialog.CancelEvent += OnCancelButtonClicked; + _dialog.Show(); } @@ -141,5 +150,23 @@ void HidePickerDialog() { _dialog?.Hide(); } + + void OnMainDisplayInfoChanged(object? sender, DisplayInfoChangedEventArgs e) + { + DatePickerDialog? currentDialog = _dialog; + + if (currentDialog != null && currentDialog.IsShowing) + { + currentDialog.Dismiss(); + currentDialog.CancelEvent -= OnCancelButtonClicked; + + ShowPickerDialog(currentDialog.DatePicker.Year, currentDialog.DatePicker.Month, currentDialog.DatePicker.DayOfMonth); + } + } + + void OnCancelButtonClicked(object? sender, EventArgs e) + { + // TODO: Update IsFocused Property + } } } \ No newline at end of file