-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 the bug of wrong aspect ratio of image cropper in some cases #4482
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Something about this feels off...
@HHChaos were you able to pinpoint exactly what caused the original issue? Could we get some additional insight into the cause and the fix?
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.
I just noticed we don't do any gate on the control to be loaded. Maybe that'd be the better fix is waiting for layout to complete?
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.
@Arlodotexe The source of this bug is when ImageCropper is in the layout arranging phase, it may take more time if the available sizes are infinite, and because CanvasRect is not a valid size before the layout is completed, this bug may occur if the InitImageLayout method is called at this time.
@michael-hawker I have tested it, when loaded occurs, CanvasRect may still be an invalid value.
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.
This fix feels like it's patching over a slightly deeper issue.
Looking at the code, it appears that
PART_ImageCanvas
that contains the image, rather than the image itself.InitImageLayout
when the source has changed, but not when the image is loaded.If the above ends up being the cause of other issues down the road, we don't want to be band-aid patching them. When underlying issues get fixed that have been partially patched over, we need to clean up all those patches, and there are no notes or comments to tell us what code should be included in the cleanup.
To save time and headache later, I think we should look at fixing this by fixing the underlying problem.
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.
Looks like the source of the problem is that calling
await imgCropper.LoadImageFromFile(file);
doesn't wait for the image to load before completing.Adding a
Task.Delay()
with any value (minimum of 1) fixes the issue.Notably, this issue also exists when do you
Seems this scenario wasn't considered when designing the architecture for this control. I'll see if there's a better fix for this than lazy-loading. A few options come to mind...
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.
Moving additional findings to here in case I need to open a new PR for this.
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.
PR #4720 opened with a much simpler fix