Skip to content

Commit

Permalink
[iOS][Regression] Fix ToolbarItem color when used with IconImageSourc…
Browse files Browse the repository at this point in the history
…e is always default color (#26048)

* fix added

* unwanted method removed

* ToPlatform method added

* UITest added

* Modified the UITest

* ios and android snap added

* Revert "ios and android snap added"

This reverts commit 7fef108.

* ios and android snap added

* Windows platform restricted

* comment added

* test case modified

* modified the test case

* new snaps added for android and ios

* Update Issue25912.xaml.cs

---------

Co-authored-by: Rui Marinho <me@ruimarinho.net>
  • Loading branch information
devanathan-vaithiyanathan and rmarinho authored Dec 6, 2024
1 parent b479513 commit 23e1522
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
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)
{
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}"/>
</ContentPage.ToolbarItems>


<ContentPage.Content>
<Button Text="Change Icon" WidthRequest="150" HeightRequest="50" Clicked="Button_Clicked" AutomationId="Button"/>
</ContentPage.Content>

</controls:TestContentPage>
35 changes: 35 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,35 @@
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()
{
}

void Button_Clicked(object sender, EventArgs e)
{
toolbarItem.IconImageSource = new FontImageSource
{
Glyph ="+",
Color = Colors.Green
};
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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("Button");
App.Tap("Button");
VerifyScreenshot();
}

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

0 comments on commit 23e1522

Please sign in to comment.