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

Fix text toolbar item icon not removed when navigating on Android #16796

Merged
merged 5 commits into from
May 7, 2024

Conversation

Adam--
Copy link
Contributor

@Adam-- Adam-- commented Aug 16, 2023

Description of Change

Fixes an issue on Android when there are multiple pages with toolbar items and on one page the toolbar item has an icon and on another page it doesn't, the icon is not removed when navigating to the page without the icon.

When updating the Android MenuItem icon and the base drawable is null, the icon is set to null. On Android, this clears out the previous icon.

Issues Fixed

Fixes #7823

@Adam-- Adam-- requested a review from a team as a code owner August 16, 2023 17:48
@ghost ghost added the community ✨ Community Contribution label Aug 16, 2023
@ghost
Copy link

ghost commented Aug 16, 2023

Hey there @Adam--! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@samhouts samhouts added this to the Under Consideration milestone Aug 16, 2023
@jfichtner
Copy link

This is a much needed fix! Hopefully this gets reviewed and approved quickly!

@mattleibow
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@mattleibow
Copy link
Member

This all looks great, but we probably should add some tests.

@PureWeen is there a good example - or even possible - to have a test? I know we have device tests, but we also now have the image comparison tests.

@Adam--
Copy link
Contributor Author

Adam-- commented Aug 30, 2023

@mattleibow, @PureWeen

Adding tests sounds like a great idea.

It seems that if we were to write a test similar (or just use the same test) to ToolbarItemsOrderUpdatesCorrectlyAfterNavigation in \src\Controls\tests\DeviceTests\Elements\Toolbar\ToolbarTests.cs but with toolbar items with icons on one of the pages and not the other then check if those icons are correct on the platform after navigation this would test the fix.

Such as:

[Fact(DisplayName = "Toolbar Items Order Updates Correctly After Navigation")]
public async Task ToolbarItemsOrderUpdatesCorrectlyAfterNavigation()
{
	SetupBuilder();
	var firstPageToolbarItem = new ToolbarItem() { Text = "Toolbar Item First Page" };
	var secondPagePrimaryToolbarItem = new ToolbarItem() { Text = "Toolbar Item Second Page", IconImageSource = "SecondPageIcon" };
	var secondPageSecondaryToolbarItem = new ToolbarItem() { Text = "Secondary Toolbar Item Second Page", Order = ToolbarItemOrder.Secondary };

	var navPage = new NavigationPage(new ContentPage()
	{
		ToolbarItems =
		{
			firstPageToolbarItem
		}
	});

	await CreateHandlerAndAddToWindow<WindowHandlerStub>(new Window(navPage), async (handler) =>
	{
		await navPage.PushAsync(new ContentPage()
		{
			ToolbarItems =
			{
				secondPagePrimaryToolbarItem,
				secondPageSecondaryToolbarItem
			}
		});

		ToolbarItemsMatch(handler, GetExpectedToolbarItems(navPage));
		ToolbarItemsMatch(handler, secondPagePrimaryToolbarItem, secondPageSecondaryToolbarItem);
		await navPage.PopAsync();
		ToolbarItemsMatch(handler, GetExpectedToolbarItems(navPage));
		ToolbarItemsMatch(handler, firstPageToolbarItem);
	});
}

ToolbarItemsMatch would need to be updated to check the toolbar IconImageSource to the platform's element icon in the platforms' ControlsHandlerTestBase.cs. I don't know how to do this on Android (how can you get the image source from the Icon drawable?) and even less on the other platforms.

Would you be able to help out?

@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Sep 14, 2023
@Adam--
Copy link
Contributor Author

Adam-- commented Sep 29, 2023

Hey, I'd like to get this merged. Can you review the code?

@DP-Technology-LLC
Copy link

We agree with @jfichtner, this is a much needed fix!

@samhouts samhouts removed the stale Indicates a stale issue/pr and will be closed soon label Feb 6, 2024
@PureWeen
Copy link
Member

ToolbarItemsOrderUpdatesCorrectlyAfterNavigation

Let me know if you want me to take this one over.

I think for the device tests on this one, you could grab the handler from the toolbar which will be of type MaterialToolbar

toolbar.Handler.PlatformView as MaterialToolbar

And then retrieve the menu items from there to see if the icon has been removed.

@jsuarezruiz
Copy link
Contributor

Added UI Test

@mattleibow
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Adam--
Copy link
Contributor Author

Adam-- commented Feb 22, 2024

Thanks all, I appreciate the help on this!

@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Mar 27, 2024

/azp run

This comment was marked as outdated.

@samhouts samhouts removed the request for review from rachelkang March 28, 2024 23:17
@PureWeen

This comment was marked as off-topic.

@github-actions github-actions bot force-pushed the bugfix-android-toolbar-icon branch from 3ce216f to 0d356e9 Compare March 28, 2024 23:25
@jfversluis jfversluis force-pushed the bugfix-android-toolbar-icon branch from 0d356e9 to 5e9032e Compare May 2, 2024 19:04
@PureWeen PureWeen force-pushed the bugfix-android-toolbar-icon branch from 5e9032e to 3e5b814 Compare May 3, 2024 20:57
PureWeen
PureWeen previously approved these changes May 6, 2024
@PureWeen PureWeen enabled auto-merge (squash) May 6, 2024 00:19
Adam-- and others added 4 commits May 7, 2024 04:30
Fixes an issue on Android when there are multiple pages with toolbar
items and on one page the toolbar item has an icon and on another page
it doesn't, the icon is not removed when navigating to the page without
the icon.

When updating the Android Menuitem icon and the base drawable is null,
the icon is set to null. On Android, this clears out the previous icon.

Fixes dotnet#7823
@github-actions github-actions bot force-pushed the bugfix-android-toolbar-icon branch from 3e5b814 to a64c23c Compare May 7, 2024 04:30
@PureWeen
Copy link
Member

PureWeen commented May 7, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@dotnet dotnet deleted a comment from azure-pipelines bot May 7, 2024
@dotnet dotnet deleted a comment from azure-pipelines bot May 7, 2024
@dotnet dotnet deleted a comment from azure-pipelines bot May 7, 2024
@PureWeen
Copy link
Member

PureWeen commented May 7, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen disabled auto-merge May 7, 2024 13:25
@PureWeen PureWeen merged commit a93e88c into dotnet:main May 7, 2024
49 checks passed
tj-devel709 pushed a commit that referenced this pull request May 9, 2024
…6796)

* Fix text toolbar item icon not removed when navigating on Android

Fixes an issue on Android when there are multiple pages with toolbar
items and on one page the toolbar item has an icon and on another page
it doesn't, the icon is not removed when navigating to the page without
the icon.

When updating the Android Menuitem icon and the base drawable is null,
the icon is set to null. On Android, this clears out the previous icon.

Fixes #7823

* Added UITest

* Improve test

* - update screenshots

* - add windows

---------

Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
9 participants