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.
57 changes: 57 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue36933.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 36933, "DatePicker and TimePicker Background set to null at runtime does not clear on iOS/MacCatalyst", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue36933 : ContentPage
{
public Issue36933()
{
var datePicker = new DatePicker
{
AutomationId = "TestDatePicker",
Background = new SolidColorBrush(Colors.LightGreen),
Date = new DateTime(2025, 1, 15)
};

var timePicker = new TimePicker
{
AutomationId = "TestTimePicker",
Background = new SolidColorBrush(Colors.LightGreen),
Time = new TimeSpan(10, 30, 0)
};

var clearButton = new Button
{
Text = "Set Background to Null",
AutomationId = "ClearBackgroundButton",
Command = new Command(() =>
{
datePicker.Background = null;
timePicker.Background = null;
})
};

var setColorButton = new Button
{
Text = "Set Background Color",
AutomationId = "SetBackgroundButton",
Command = new Command(() =>
{
datePicker.Background = new SolidColorBrush(Colors.LightBlue);
timePicker.Background = new SolidColorBrush(Colors.LightBlue);
})
};

Content = new VerticalStackLayout
{
Spacing = 20,
Padding = 30,
Children =
{
datePicker,
timePicker,
clearButton,
setColorButton
}
};
}
}
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

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

public override string Issue => "DatePicker and TimePicker Background set to null at runtime does not clear on iOS/MacCatalyst";

[Test]
[Category(UITestCategories.DatePicker)]
public void VerifyDatePickerAndTimePickerBackgroundClearsOnNull()
{
App.WaitForElement("TestDatePicker");

Exception? exception = null;

// Tap clear button to set Background = null — should clear the initial background
App.Tap("ClearBackgroundButton");
VerifyScreenshotOrSetException(ref exception, "Issue36933BackgroundCleared");

// Tap set button to set a new background color
App.Tap("SetBackgroundButton");
VerifyScreenshotOrSetException(ref exception, "Issue36933BackgroundColorSet");

if (exception is not null)
{
throw exception;
}
}
}
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.
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.
26 changes: 26 additions & 0 deletions src/Core/src/Handlers/DatePicker/DatePickerHandler.MacCatalyst.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Foundation;
using Microsoft.Maui.Graphics;
using UIKit;
using RectangleF = CoreGraphics.CGRect;

Expand Down Expand Up @@ -341,5 +342,30 @@ void OnValueChanged(object? sender, EventArgs? e)
}
}
}

//TODO: Make it public in .NET 11.
internal static void MapBackground(IDatePickerHandler handler, IDatePicker datePicker)
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
Resolved
{
if (handler.PlatformView is not UIDatePicker platformView)
{
return;
}

if (datePicker.Background is ImageSourcePaint image)
{
var provider = handler.GetRequiredService<IImageSourceServiceProvider>();
platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider)
.FireAndForget(handler);
}
else if (datePicker.Background.IsNullOrEmpty())
{
platformView.RemoveBackgroundLayer();
platformView.BackgroundColor = null;
}
else
{
platformView.UpdateBackground(datePicker);
}
}
}
}
1 change: 1 addition & 0 deletions src/Core/src/Handlers/DatePicker/DatePickerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public partial class DatePickerHandler : IDatePickerHandler
#if ANDROID || WINDOWS
[nameof(IDatePicker.Background)] = MapBackground,
#elif IOS
[nameof(IDatePicker.Background)] = MapBackground,
[nameof(IDatePicker.FlowDirection)] = MapFlowDirection,
#endif
[nameof(IDatePicker.CharacterSpacing)] = MapCharacterSpacing,
Expand Down
26 changes: 26 additions & 0 deletions src/Core/src/Handlers/DatePicker/DatePickerHandler.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Maui.Graphics;
using UIKit;

namespace Microsoft.Maui.Handlers
Expand Down Expand Up @@ -185,6 +186,31 @@ public override void DoneClicked()
DatePickerHandler.OnDoneClicked(Handler);
}
}

//TODO: Make it public in .NET 11.
internal static void MapBackground(IDatePickerHandler handler, IDatePicker datePicker)
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
Resolved
{
if (handler.PlatformView is not MauiDatePicker platformView)
{
return;
}

if (datePicker.Background is ImageSourcePaint image)
{
var provider = handler.GetRequiredService<IImageSourceServiceProvider>();
platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider)
.FireAndForget(handler);
}
else if (datePicker.Background.IsNullOrEmpty())
{
platformView.RemoveBackgroundLayer();
platformView.BackgroundColor = null;
}
else
{
platformView.UpdateBackground(datePicker);
}
}
}
#endif
}
26 changes: 26 additions & 0 deletions src/Core/src/Handlers/TimePicker/TimePickerHandler.MacCatalyst.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Foundation;
using Microsoft.Maui.Graphics;
using UIKit;

namespace Microsoft.Maui.Handlers
Expand Down Expand Up @@ -123,5 +124,30 @@ void OnValueChanged(object? sender, EventArgs e)
}
}
}

//TODO: Make it public in .NET 11.
internal static void MapBackground(ITimePickerHandler handler, ITimePicker timePicker)
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
Resolved
{
if (handler.PlatformView is not UIDatePicker platformView)
{
return;
}

if (timePicker.Background is ImageSourcePaint image)
{
var provider = handler.GetRequiredService<IImageSourceServiceProvider>();
platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider)
.FireAndForget(handler);
}
else if (timePicker.Background.IsNullOrEmpty())
{
platformView.RemoveBackgroundLayer();
platformView.BackgroundColor = null;
}
else
{
platformView.UpdateBackground(timePicker);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/TimePicker/TimePickerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class TimePickerHandler : ITimePickerHandler
{
public static IPropertyMapper<ITimePicker, ITimePickerHandler> Mapper = new PropertyMapper<ITimePicker, ITimePickerHandler>(ViewHandler.ViewMapper)
{
#if ANDROID || WINDOWS
#if IOS || ANDROID || WINDOWS
[nameof(ITimePicker.Background)] = MapBackground,
#endif
#if IOS || ANDROID
Expand Down
26 changes: 26 additions & 0 deletions src/Core/src/Handlers/TimePicker/TimePickerHandler.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Handlers
{
Expand Down Expand Up @@ -156,6 +157,31 @@ public void OnDateSelected()
}
}
}

//TODO: Make it public in .NET 11.
internal static void MapBackground(ITimePickerHandler handler, ITimePicker timePicker)
Comment thread
HarishwaranVijayakumar marked this conversation as resolved.
Resolved
{
if (handler.PlatformView is not MauiTimePicker platformView)
{
return;
}

if (timePicker.Background is ImageSourcePaint image)
{
var provider = handler.GetRequiredService<IImageSourceServiceProvider>();
platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider)
.FireAndForget(handler);
}
else if (timePicker.Background.IsNullOrEmpty())
{
platformView.RemoveBackgroundLayer();
platformView.BackgroundColor = null;
}
else
{
platformView.UpdateBackground(timePicker);
}
}
}
#endif
}
Loading