[iOS] - Fix Custom FlyoutIcon from Being Overridden to Default Color in Shell#27580
[iOS] - Fix Custom FlyoutIcon from Being Overridden to Default Color in Shell#27580PureWeen merged 10 commits intodotnet:inflight/currentfrom
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Azure Pipelines successfully started running 3 pipeline(s). |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/IssueShell6738.cs
Show resolved
Hide resolved
This comment was marked as off-topic.
This comment was marked as off-topic.
821492b to
2057da3
Compare
| icon = result?.Value; | ||
|
|
||
| var foregroundColor = _context.Shell.GetValue(Shell.ForegroundColorProperty); | ||
| if (foregroundColor is null) |
There was a problem hiding this comment.
What if I change the foreground color? Will it change back? Should there be an else statement that sets the UIImageRenderingMode the other way? Can we have that in a (additional) test that we can toggle between the colors here?
There was a problem hiding this comment.
The Flyout icon updates its color correctly when the foreground color changes dynamically. It does not remain in UIImageRenderingMode.AlwaysOriginal since the image is always loaded with its default rendering mode, allowing it to adapt to the assigned ForegroundColor.
I have added a test to validate this behavior. Let me know if any further refinements are needed.
|
/rebase |
8884344 to
dfb21fd
Compare
| App.WaitForElement(defaultColor); | ||
| App.Tap(defaultColor); | ||
| App.WaitForElement(defaultColor); | ||
| VerifyScreenshot("EnsureFlyoutIconAsDefaultIconColor"); |
There was a problem hiding this comment.
Pending snapshot on Mac.
Baseline snapshot not yet created: /Users/runner/work/1/s/artifacts/bin/Controls.TestCases.Mac.Tests/Release/net9.0/snapshots/mac/EnsureFlyoutIconAsDefaultIconColor.png
Ensure new snapshot is correct: /Users/runner/work/1/a/Controls.TestCases.Shared.Tests/snapshots-diff/mac/EnsureFlyoutIconAsDefaultIconColor.png
There was a problem hiding this comment.
@jsuarezruiz, Thank you for pointing this out. I have added the pending snapshot.
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| @@ -0,0 +1,43 @@ | |||
| #if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROID | |||
There was a problem hiding this comment.
There is a parameter to include or not the TitleBar:
Could you try it?
There was a problem hiding this comment.
@jsuarezruiz, Yes, including the TitleBar helps clarify the issue with the FlyoutIcon on the Windows platform. Since there is an existing issue, where the ForegroundColor does not work as expected, it has already been reported and tracked in the following issue: #26148
StephaneDelcroix
left a comment
There was a problem hiding this comment.
PR Review: Approved ✅
Summary
This PR correctly fixes issue #6738 where custom FlyoutIcon colors in Shell were being overridden to iOS's default blue tint.
Fix Analysis
The solution uses UIImageRenderingMode.AlwaysOriginal when no ForegroundColor is set, which correctly preserves the custom icon's original colors while still allowing tinting when ForegroundColor is explicitly set.
Key changes reviewed:
- ✅ Property change handlers correctly trigger
UpdateLeftToolbarItems()forForegroundColorProperty - ✅ Logic correctly checks both
CurrentPageandShellfor ForegroundColor - ✅ Test coverage is adequate for iOS/Mac (Windows/Android correctly excluded)
- ✅ Test file preprocessor directive
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROIDcorrectly limits tests to iOS/Mac
Minor Suggestion (Optional)
Consider adding a defensive null check on icon before calling ImageWithRenderingMode():
if (foregroundColor is null && icon is not null)
{
icon = icon.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
}While unlikely to be null in practice (since image != null is already checked), this would be more defensive.
Tested
- Built and ran reproduction scenario on iOS simulator
- Confirmed the fix approach is correct for iOS/UIKit behavior
LGTM! 🚀
243b7c7 to
a3a0a3b
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Issue: The color of the custom FlyoutIcon in Shell resets to the default blue instead of retaining its original color.
RootCause
By default,
UIImageRenderingModeis set toAutomatic, allowing the rendering behavior to be determined based on the UI context. When a customFlyoutIconis applied, it does not retain its original color but instead adapts to the predefined tinting behavior, leading to unintended color changes.Description of Change
The image rendering mode is now set to
UIImageRenderingMode.AlwaysOriginal, ensuring that custom icons maintain their original colors without being altered by default rendering behavior.FlyoutIconis set, its color can still be modified usingShell.ForegroundColor.FlyoutIconis applied, it now preserves its original image color without automatic tinting.Shell.ForegroundColorshould be set accordingly to allow the color modification to be applied.Issues Fixed
Fixes #6738
Tested the behaviour in the following platforms
Output