-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fixed duplicate title icon when setting TitleIconImageSource Multiple times #31487
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
base: main
Are you sure you want to change the base?
Conversation
Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes a bug where duplicate title icons would appear in Android navigation bars when the TitleIconImageSource property was set multiple times. The issue was caused by the UpdateTitleIcon method always creating a new ToolbarTitleIconImageView without checking for existing ones.
Key changes:
- Modified the UpdateTitleIcon method to check for existing ToolbarTitleIconImageView before creating new ones
- Added proper reuse logic to prevent duplicate icons
- Included test cases to verify the fix
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs | Updated UpdateTitleIcon method to check for existing icon views and reuse them instead of always creating new ones |
src/Controls/tests/TestCases.HostApp/Issues/Issue31445.cs | Added test page that reproduces the duplicate icon issue by setting TitleIconImageSource multiple times |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31445.cs | Added UI test that verifies the fix by checking that only one title icon appears after button interaction |
VerticalOptions = LayoutOptions.Start, | ||
AutomationId = "Issue31445Button" | ||
}; | ||
button.Clicked += (s, e) => { NavigationPage.SetTitleIconImageSource(this, "dotnet_bot.png"); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test only sets the same image source again. To better validate the fix, consider testing with different image sources or setting the same source multiple times in rapid succession to ensure the duplicate prevention works in various scenarios.
Copilot uses AI. Check for mistakes.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
RootCause:
UpdateTitleIcon always added a new ToolbarTitleIconImageView without checking for an existing one, causing duplicate icons when TitleIconImageSource was set multiple times.
Description of Change
Modified UpdateTitleIcon method to check for an existing ToolbarTitleIconImageView and only add a new one if necessary, ensuring that duplicate icons are not created when the title icon is set multiple times.
Issues Fixed
Fixes #31445
Tested the behavior in the following platforms
Screenshot
BeforeFix31445.mov
AfterFix31445.mov