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
[TIMOB-15747] Use CENTER_CROP to scale and fit the image #5019
Conversation
This will introduce many regressions, such as this test case https://jira.appcelerator.org/browse/TIMOB-15747?focusedCommentId=282170&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-282170. Please also take a look at https://jira.appcelerator.org/browse/TIMOB-10358 for the details of the ImageView parity for scaling behavior. |
Any update on this? |
I've tested this. https://jira.appcelerator.org/browse/TIMOB-15747?focusedCommentId=282170&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-282170 is a valid regression. Please run this test case on with and without your PR, and you will see the scaling difference. With your PR, the image takes up the whole screen - i.e ignoring aspect ratio. |
I am little confused about the behaviour. What I see is the image being scaled to fill the height and width is chopped keeping the aspect ratio. As per https://jira.appcelerator.org/browse/TIMOB-10358, it looks like the IOS behaviour is to scale the image keeping the aspect ratio if either height or width is size behaviour which is the case here. |
I'm just doing a comparison before and after on Android only, as I haven't tested with iOS. There is a behavior difference with and without this PR. I.e: Before when you run https://jira.appcelerator.org/browse/TIMOB-15747?focusedCommentId=282170&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-282170 you would see the image in the middle, but after it scaled to take the whole imageview. Are you saying that the behavior before was incorrect? |
Let me check in IOS and understand the behaviour. |
@salachi Any updates here? |
Ingo, I am not very clear on the behaviour. It will really help if Vishal or Hieu can define the behaviour. |
…ght is not defined
New fix added. Scale the imageview based on the image aspect ration if width and height is not defined. |
Merged with latest code from master |
Any updates? This PR is here for ages.... |
I've moved it into the next sprint for re-review. |
maxHeight = h; | ||
maxWidth = Math.round(h / aspectRatio); | ||
// donot override if the width is already defined | ||
if (!viewWidthDefinedLocal) { |
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.
Why do you treat this as a special case but ignore the similar condition in line 391? Or why not add
if (!viewHeightDefinedLocal)
in line 391 too?
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.
It was a miss on my part, I should have done the same checking.
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.
Please take a look at my last comment. It seems it's not necessary to do these manipulations here.
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 debugged it and just changing the line 374 seems to be working as viewWidthDefined is false when left and right are set. Also, the special condition you mentioned above in the code is not required for both height and width as the condition will be always true.
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.
Sorry, what I meant was doesn't seems to be working.
Actually, the original ticket is a duplicate of TIMOB-14395. The issue is due to a bug in the fix of TIMOB-14395 (#4738). The fix should be
|
Changing the line 374 doesn't seems to be working as viewWidthDefined is false when left and right are set. Also, the special condition I had in the code (that you mentioned above) is not required for both height and width as the condition will be always true. |
The two steps in my last comment together will fix the issue. If you only tried step 1, it would not work. For step 2, you can do a similar check for left and right and decide how to set viewWidthDefined, just like https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIImageView.java#L761 |
…same for top and bottom
The original issue mentioned in the bug is fixed with this changes but the one Hieu mentioned above with sample https://jira.appcelerator.org/browse/TIMOB-15747?focusedCommentId=282170&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-282170 is scaling the image to the full screen which I think is the right behaviour but old behaviour was not to scale to full width. Since both left and right is defined, and height is 100%, I think it should scale to fill the screen and that is the behaviour now. Can you confirm if this is the right behaviour? I am checking in the changes anyway. |
Yes. That's the right behavior. For the second sample, your very first fix cropped the image in width which is not correct. The correct behavior is:
Code reviewed and functionally tested. Accepted |
[TIMOB-15747] Use CENTER_CROP to scale and fit the image
https://jira.appcelerator.org/browse/TIMOB-15747