Skip to content

Commit c3661fd

Browse files
PureWeenCopilot
andauthored
Revert "ToolbarItem behavior with ImageSource iOS - fix (#28833)" (#31112)
* Revert "ToolbarItem behavior with ImageSource iOS - fix (#28833)" This reverts commit 5860fe6. * Update src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30818.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * - fix define on testing --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2faddc2 commit c3661fd

File tree

9 files changed

+145
-5
lines changed

9 files changed

+145
-5
lines changed

src/Controls/src/Core/Compatibility/iOS/Extensions/ToolbarItemExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ void UpdateIconAndStyle(ToolbarItem item)
112112
}
113113
item.IconImageSource.LoadImage(mauiContext, result =>
114114
{
115-
Image = item.IconImageSource is not FontImageSource
116-
? result?.Value.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
117-
: result?.Value;
115+
Image = result?.Value;
118116
Style = UIBarButtonItemStyle.Plain;
119117
});
120118
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System.ComponentModel;
2+
using Microsoft.Maui.Controls.PlatformConfiguration;
3+
using Entry = Microsoft.Maui.Controls.Entry;
4+
5+
namespace Maui.Controls.Sample.Issues
6+
{
7+
8+
[Issue(IssueTracker.Github, 30818, "ToolbarItem color with custom BarTextColor not working", PlatformAffected.iOS)]
9+
public class Issue30818 : NavigationPage
10+
{
11+
12+
public Issue30818() : base(new MainPage())
13+
{
14+
}
15+
16+
class MainPage : ContentPage
17+
{
18+
public MainPage()
19+
{
20+
Title = "Main Page";
21+
22+
var toolBarItem = new ToolbarItem
23+
{
24+
Text = "Bank",
25+
IconImageSource = "bank.png",
26+
AutomationId = "BankToolbarItem",
27+
Order = ToolbarItemOrder.Primary,
28+
Priority = 0
29+
};
30+
31+
// ToolbarItem with Bank.png icon
32+
ToolbarItems.Add(toolBarItem);
33+
34+
var setRedButton = new Button
35+
{
36+
Text = "Set BarTextColor Red",
37+
AutomationId = "SetRedButton"
38+
};
39+
40+
var setGreenButton = new Button
41+
{
42+
Text = "Set BarTextColor Green",
43+
AutomationId = "SetGreenButton"
44+
};
45+
46+
var setResetButton = new Button
47+
{
48+
Text = "Reset BarTextColor",
49+
AutomationId = "SetResetButton"
50+
};
51+
52+
// There is a known issue with setting the BarTextColor on iOS from NULL to a color won't work
53+
// This will get fixed in a followup issue
54+
// https://github.com/dotnet/maui/issues/31111
55+
setRedButton.Clicked += (_, __) =>
56+
{
57+
ToolbarItems.Remove(toolBarItem);
58+
if (Parent is NavigationPage nav)
59+
{
60+
nav.BarTextColor = Microsoft.Maui.Graphics.Colors.Red;
61+
}
62+
ToolbarItems.Add(toolBarItem);
63+
};
64+
65+
setGreenButton.Clicked += (_, __) =>
66+
{
67+
// https://github.com/dotnet/maui/issues/31111
68+
ToolbarItems.Remove(toolBarItem);
69+
if (Parent is NavigationPage nav)
70+
{
71+
nav.BarTextColor = Microsoft.Maui.Graphics.Colors.Green;
72+
}
73+
ToolbarItems.Add(toolBarItem);
74+
};
75+
76+
setResetButton.Clicked += (_, __) =>
77+
{
78+
// https://github.com/dotnet/maui/issues/31111
79+
ToolbarItems.Remove(toolBarItem);
80+
if (Parent is NavigationPage nav)
81+
{
82+
nav.BarTextColor = null;
83+
}
84+
ToolbarItems.Add(toolBarItem);
85+
};
86+
87+
Content = new StackLayout
88+
{
89+
Padding = 20,
90+
Children =
91+
{
92+
setRedButton,
93+
setGreenButton,
94+
setResetButton
95+
}
96+
};
97+
}
98+
}
99+
}
100+
}
Binary file not shown.

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28822.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NUnit.Framework;
1+
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS
2+
// https://github.com/dotnet/maui/issues/28822
3+
using NUnit.Framework;
24
using UITest.Appium;
35
using UITest.Core;
46

@@ -20,4 +22,5 @@ public void ToolbarItemShouldBeCorrectlyRendered()
2022
VerifyScreenshot();
2123
}
2224
}
23-
}
25+
}
26+
#endif
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#if IOS
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues
7+
{
8+
public class Issue30818 : _IssuesUITest
9+
{
10+
public Issue30818(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "ToolbarItem color with custom BarTextColor not working";
15+
16+
[Test]
17+
[Category(UITestCategories.ToolbarItem)]
18+
[Category(UITestCategories.Navigation)]
19+
public void ToolbarItemColorWithCustomBarTextColorShouldWork()
20+
{
21+
App.WaitForElement("SetResetButton");
22+
VerifyScreenshot();
23+
24+
// Wait for the page to load and toolbar item to be present
25+
App.Tap("SetRedButton");
26+
VerifyScreenshot("ToolbarItemColorWithCustomBarTextColorShouldWork_Red");
27+
28+
// Set the BarTextColor to red
29+
App.WaitForElement("SetGreenButton");
30+
App.Tap("SetGreenButton");
31+
VerifyScreenshot("ToolbarItemColorWithCustomBarTextColorShouldWork_Green");
32+
33+
34+
App.Tap("SetResetButton");
35+
VerifyScreenshot();
36+
}
37+
}
38+
}
39+
#endif
38.2 KB
Loading
38.5 KB
Loading
37.2 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)