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 Button Regression with null image source #25485

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

tj-devel709
Copy link
Member

This PR fixes an null reference issue that occurs when an button has its image set by UIButton.SetImage. Instead of using the Button.ImageSource.ToString() to see if the image has changed without needing to hold a reference to the image, the code now uses the UIButton.CurrentImage hash to determine if the image has changed. This helps us know if the image was changed in those situations where the Button.ImageSource is null but the UIButton.CurrentImage is still set.

Description of Change

Issues Fixed

Fixes #25409

@tj-devel709 tj-devel709 requested a review from a team as a code owner October 23, 2024 22:06
@tj-devel709 tj-devel709 requested review from jfversluis and rmarinho and removed request for a team October 23, 2024 22:06
#if IOS
((Action)(async () =>
{
var imageSource = new FileImageSource() { File = "shopping_cart.png" };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the test be extended to:

  • Set the image when the button is tapped.
  • Remove the image, setting a null value when tapping again.
  • Reset the image by tapping the button again (for example, using a counter, odd sets image, even removes it).
    ?

@tj-devel709 tj-devel709 force-pushed the dev/TJ/ButtonImageSourceRegression_SR9 branch from e8b6993 to 7807d75 Compare October 24, 2024 17:19
@tj-devel709 tj-devel709 force-pushed the dev/TJ/ButtonImageSourceRegression_SR9 branch from 7807d75 to cc5dc08 Compare October 24, 2024 17:25
@tj-devel709 tj-devel709 requested a review from a team as a code owner October 24, 2024 17:25
@tj-devel709 tj-devel709 changed the base branch from release/8.0.1xx-sr9 to release/9.0.1xx October 24, 2024 17:25
@tj-devel709
Copy link
Member Author

Okay, test has been rebased off the release/9.0.1xx branch, and it now uses the UIImage as a weakreference instead of the hash. Tests have also been updated on @jsuarezruiz's request!

@tj-devel709
Copy link
Member Author

/azp run

Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@@ -81,22 +80,29 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
}
platformButton.UpdateContentEdgeInsets(button, contentEdgeInsets);

_originalImageRef.TryGetTarget(out var _originalImage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove _ from this variable

@PureWeen PureWeen added this to the .NET 9.0 GA milestone Oct 24, 2024
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen PureWeen merged commit 743afa0 into release/9.0.1xx Oct 25, 2024
7 checks passed
@PureWeen PureWeen deleted the dev/TJ/ButtonImageSourceRegression_SR9 branch October 25, 2024 13:11
@PureWeen
Copy link
Member

/backport to release/8.0.1xx-sr10

Copy link
Contributor

Started backporting to release/8.0.1xx-sr10: https://github.com/dotnet/maui/actions/runs/11518924955

@PureWeen
Copy link
Member

/backport to 8.0.1xx-sr9

Copy link
Contributor

Started backporting to 8.0.1xx-sr9: https://github.com/dotnet/maui/actions/runs/11595720335

Copy link
Contributor

@PureWeen an error occurred while backporting to 8.0.1xx-sr9, please check the run log for details!

The process '/usr/bin/git' failed with exit code 1

PureWeen added a commit that referenced this pull request Oct 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2024
@samhouts samhouts added fixed-in-9.0.0 fixed-in-9.0.10 fixed-in-net8.0-nightly This may be available in a nightly release! labels Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants