Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS][Regression] Fix ToolbarItem color when used with IconImageSource is always default color #26048

Merged
merged 14 commits into from
Dec 6, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.ComponentModel;
using CoreGraphics;
using Microsoft.Maui.Graphics;
using ObjCRuntime;
using UIKit;
using PointF = CoreGraphics.CGPoint;
Expand Down Expand Up @@ -108,6 +109,10 @@ void UpdateIconAndStyle(ToolbarItem item)
{
Image = result?.Value;
Style = UIBarButtonItemStyle.Plain;
if (item.IconImageSource is FontImageSource fontImageSource && fontImageSource.Color is not null)
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
{
TintColor = fontImageSource.Color.ToPlatform();
}
});
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25912.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue25912MainPage">

<ContentPage.ToolbarItems>
<ToolbarItem x:Name="toolbarItem" IconImageSource="{FontImage Glyph='+',Color=Red,Size=30}"/>
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
</ContentPage.ToolbarItems>


<ContentPage.Content>
<Label Text="ToolbarItemIconColorTest" AutomationId="Label"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could modify the sample to change the ToolbarItem color at runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per your suggestion, I have modified the test case. Could you please validate the changes?

</ContentPage.Content>

</controls:TestContentPage>
26 changes: 26 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25912.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 25912, "ToolbarItem color when used with IconImageSource is always white", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue25912 : NavigationPage
{
public Issue25912()
{
Navigation.PushAsync(new Issue25912MainPage());
}
}

public partial class Issue25912MainPage : TestContentPage
{

public Issue25912MainPage()
{
InitializeComponent();
}

protected override void Init()
{
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if TEST_FAILS_ON_WINDOWS //The images generated from the CI do not display the toolbar on the Windows platform. However, the icon color issue does not exist on Windows. Therefore, the test is restricted to exclude the Windows platform.
using NUnit.Framework;
using NUnit.Framework.Legacy;
using OpenQA.Selenium;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25912 : _IssuesUITest
{
public Issue25912(TestDevice device) : base(device)
{
}

public override string Issue => "ToolbarItem color when used with IconImageSource is always white";

[Test]
[Category(UITestCategories.ToolbarItem)]
public void VerifyToolbarItemIconColor()
{
App.WaitForElement("Label");
VerifyScreenshot();
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
}

}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading