Skip to content

Commit

Permalink
Update the DatePicker Dialog if the display info changes (#4815)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz authored Feb 28, 2022
1 parent 0524615 commit 009cce7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -32,6 +34,8 @@ protected override MauiDatePicker CreatePlatformView()
protected override void ConnectHandler(MauiDatePicker platformView)
{
base.ConnectHandler(platformView);

DeviceDisplay.MainDisplayInfoChanged += OnMainDisplayInfoChanged;

SetupDefaults(platformView);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -134,12 +141,32 @@ void ShowPickerDialog(int year, int month, int day)
else
_dialog.UpdateDate(year, month, day);

_dialog.CancelEvent += OnCancelButtonClicked;

_dialog.Show();
}

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
}
}
}

0 comments on commit 009cce7

Please sign in to comment.