Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue19256.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 19256, "DatePicker control minimum date issue", PlatformAffected.Android)]
public class Issue19256 : ContentPage
{
readonly DatePicker _leftDatePicker;
readonly DatePicker _rightDatePicker;

static readonly DateTime BaseDate = new DateTime(2025, 6, 15);
static readonly DateTime FutureDate = new DateTime(2025, 6, 25); // BaseDate + 10 days
static readonly DateTime EarlierDate = new DateTime(2025, 6, 20); // BaseDate + 5 days

public Issue19256()
{
_leftDatePicker = new DatePicker
{
HorizontalOptions = LayoutOptions.Center,
AutomationId = "LeftDatePicker",
Date = BaseDate
};
_leftDatePicker.DateSelected += OnLeftDateSelected;

_rightDatePicker = new DatePicker
{
HorizontalOptions = LayoutOptions.Center,
AutomationId = "RightDatePicker",
Date = BaseDate,
MinimumDate = BaseDate
};

var setFutureDateButton = new Button
{
AutomationId = "SetFutureDateButton",
Text = "Set Future Date"
};
setFutureDateButton.Clicked += OnSetFutureDateClicked;

var setEarlierDateButton = new Button
{
AutomationId = "SetEarlierDateButton",
Text = "Set Earlier Date"
};
setEarlierDateButton.Clicked += OnSetEarlierDateClicked;

Content = new VerticalStackLayout
{
Spacing = 20,
Padding = 20,
Children =
{
_leftDatePicker,
_rightDatePicker,
setFutureDateButton,
setEarlierDateButton
}
};
}


void OnLeftDateSelected(object sender, DateChangedEventArgs e)
{
_rightDatePicker.MinimumDate = e.NewDate;

if (_rightDatePicker.Date < e.NewDate)
{
_rightDatePicker.Date = e.NewDate;
}
}

void OnSetFutureDateClicked(object sender, EventArgs e)
{
_leftDatePicker.Date = FutureDate;
}

void OnSetEarlierDateClicked(object sender, EventArgs e)
{
_leftDatePicker.Date = EarlierDate;
}
}
39 changes: 39 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue33583.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 33583, "DatePicker does not update MinimumDate / MaximumDate in the Popup after first opening", PlatformAffected.Android)]
public class Issue33583 : TestContentPage
{
DatePicker _datePicker;

protected override void Init()
{
_datePicker = new DatePicker
{
AutomationId = "TestDatePicker",
HorizontalOptions = LayoutOptions.Center,
MinimumDate = new DateTime(2025, 1, 4),
MaximumDate = new DateTime(2025, 1, 28),
Date = new DateTime(2025, 1, 15)
};

var changeMaxDateButton = new Button
{
Text = "Change MaximumDate to 2027",
AutomationId = "ChangeMaxDateButton"
};
changeMaxDateButton.Clicked += (s, e) =>
{
_datePicker.MaximumDate = new DateTime(2027, 12, 31);
};

Content = new VerticalStackLayout
{
Spacing = 10,
Children =
{
_datePicker,
changeMaxDateButton
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Android specific scenario
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue19256 : _IssuesUITest
{
public Issue19256(TestDevice device) : base(device)
{
}

public override string Issue => "DatePicker control minimum date issue";

[Test]
[Category(UITestCategories.DatePicker)]
public void DatePickerMinimumDateShouldUpdateDynamically()
{
Exception? exception = null;

App.WaitForElement("LeftDatePicker");
App.WaitForElement("RightDatePicker");

// Step 1: Set LEFT to future date (June 25) - RIGHT MinimumDate becomes June 25
App.Tap("SetFutureDateButton");

// Step 2: Open RIGHT DatePicker to see MinimumDate is June 25
App.Tap("RightDatePicker");

// Screenshot 1: Shows dates before June 25 are disabled
VerifyScreenshotOrSetException(ref exception, "DatePickerMinimumDateShouldUpdateDynamically_FutureDate");

// Dismiss the dialog
App.Tap("Cancel");

// Step 3: Set LEFT to earlier date (June 20) - RIGHT MinimumDate should become June 20
App.Tap("SetEarlierDateButton");

// Step 4: Open RIGHT DatePicker again to verify MinimumDate updated
App.Tap("RightDatePicker");

// Screenshot 2: Should show dates from June 20 are now enabled (not June 25)
VerifyScreenshotOrSetException(ref exception, "DatePickerMinimumDateShouldUpdateDynamically_EarlierDate");

if (exception is not null)
{
throw exception;
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#if !IOS // iOS DatePicker uses a wheel picker, not a calendar dialog - cannot verify disabled dates visually
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue33583 : _IssuesUITest
{
#if ANDROID
const string DismissDatePicker = "Cancel";
#elif WINDOWS
const string DismissDatePicker = "16"; // Tap a date to close
#elif MACCATALYST
const string DismissDatePicker = "ChangeMaxDateButton"; // Tap another element to dismiss/unfocus
#endif

public Issue33583(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "DatePicker does not update MinimumDate / MaximumDate in the Popup after first opening";

[Test]
[Category(UITestCategories.DatePicker)]
public void VerifyMaximumDateInRuntime()
{
// Wait for the page to load
App.WaitForElement("TestDatePicker");

// Step 1: Open the date picker the first time by tapping it directly
App.Tap("TestDatePicker");

// Dismiss the dialog
App.Tap(DismissDatePicker);

// Step 2: Change the MaximumDate to 2027
App.WaitForElement("ChangeMaxDateButton");
App.Tap("ChangeMaxDateButton");

// Step 3: Open the date picker again - this is where the bug would occur
// Before the fix, the dialog would still show the old MaximumDate constraints
App.Tap("TestDatePicker");

// Verify the DatePicker dialog shows updated constraints via screenshot
// With the fix, dates beyond Jan 28 should now be selectable
VerifyScreenshot();
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 44 additions & 8 deletions src/Core/src/Handlers/DatePicker/DatePickerHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ void OnViewAttachedToWindow(object? sender = null, View.ViewAttachedToWindowEven

protected override void DisconnectHandler(MauiDatePicker platformView)
{
if (_dialog != null)
{
_dialog.DismissEvent -= OnDialogDismiss;
_dialog.Dismiss();
_dialog = null;
}
ResetDialog();

platformView.ViewAttachedToWindow -= OnViewAttachedToWindow;
platformView.ViewDetachedFromWindow -= OnViewDetachedFromWindow;
Expand Down Expand Up @@ -106,13 +101,47 @@ public static partial void MapDate(IDatePickerHandler handler, IDatePicker dateP
public static partial void MapMinimumDate(IDatePickerHandler handler, IDatePicker datePicker)
{
if (handler is DatePickerHandler platformHandler)
handler.PlatformView?.UpdateMinimumDate(datePicker, platformHandler._dialog);
{
// Force dialog recreation when MinimumDate is provided.
// Android's DatePickerDialog caches min/max dates internally,
// making it unreliable to update them after the dialog is created.
if (datePicker.MinimumDate is not null)
{
platformHandler.ResetDialog();
}
else
{
handler.PlatformView?.UpdateMinimumDate(datePicker, platformHandler._dialog);
}
}
}

public static partial void MapMaximumDate(IDatePickerHandler handler, IDatePicker datePicker)
{
if (handler is DatePickerHandler platformHandler)
handler.PlatformView?.UpdateMaximumDate(datePicker, platformHandler._dialog);
{
// Force dialog recreation when MaximumDate is provided.
// Android's DatePickerDialog caches min/max dates internally,
// making it unreliable to update them after the dialog is created.
if (datePicker.MaximumDate is not null)
{
platformHandler.ResetDialog();
}
else
{
handler.PlatformView?.UpdateMaximumDate(datePicker, platformHandler._dialog);
}
}
}

void ResetDialog()
{
if (_dialog is not null)
{
_dialog.DismissEvent -= OnDialogDismiss;
_dialog.Dismiss();
_dialog = null;
}
}

public static partial void MapCharacterSpacing(IDatePickerHandler handler, IDatePicker datePicker)
Expand Down Expand Up @@ -170,6 +199,13 @@ void ShowPickerDialog(DateTime? date)
if (_dialog is null)
{
_dialog = CreateDatePickerDialog(year, month, day);

// Apply min/max constraints to newly created dialog
if (VirtualView is not null)
{
PlatformView?.UpdateMinimumDate(VirtualView, _dialog);
PlatformView?.UpdateMaximumDate(VirtualView, _dialog);
}
}
else
{
Expand Down
Loading