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

Bugfix/#152 pan to center #158

Merged
merged 3 commits into from
Jun 12, 2020
Merged

Bugfix/#152 pan to center #158

merged 3 commits into from
Jun 12, 2020

Conversation

markusressel
Copy link
Collaborator

Honestly, I still can't quite wrap my head around how the matrix transformation stuff works, so I am not entirely sure if this is the right thing to do to fix the issue.

I tested the ZoomImageView on my device with different types of images of different size, and it works for all of them. I have not tested if code based functions like panTo or moveTo are affected by this. If I should do so please let me know.

It would probably be a good idea to add tests for these transformation functions since - at least for outside contributors - it is probably really hard to understand their intended and correct behavior, and a tiny change in code can have a massive impact on the functionality.

Solution

As I discovered that your proposal code for centering an image in #47 did not work I found the code in computeTransformationPan() that did the exact same thing. Applying the realZoom to the content to match its width and height values with the width and height of the container fixed the issue.

Again, I don't understand every line of code in this lib yet, so, please have a thorough look and let me know if anything about this change worries you.

@markusressel
Copy link
Collaborator Author

Thinking about this, could this also be an issue in computeTransformationZoom()?

val extraWidth = contentWidth - containerWidth
val extraHeight = contentHeight - containerHeight
val extraWidth = contentWidth * realZoom - containerWidth
val extraHeight = contentHeight * realZoom - containerHeight
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are the important 2 lines.

Copy link
Owner

@natario1 natario1 left a comment

Choose a reason for hiding this comment

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

If it helps, anytime I go back to this repo after some time, I don't understand the code either. And that's because of bad naming I think (like, what the hell is a realZoom?). We should go through a big change and rethink/rename APIs at some point.

About this PR I'm a bit confused as to why it seemed to work just fine until now (the demo app correctly centers the image IIRC). But the changes you made seem to make sense to me, so if you know they fix the issue, let's merge this!

@markusressel
Copy link
Collaborator Author

My guess is that the issue is related to the dimensions of the device, the image, or the fact that multiple images are applied in succession (setImageDrawable) or a combination of those things.

@natario1
Copy link
Owner

I see. Feel free to merge when you're ready

@markusressel
Copy link
Collaborator Author

I have done some additional monkey testing and haven't found any issues, so I will merge and we will see if something explodes 😅

@markusressel markusressel merged commit adeed37 into master Jun 12, 2020
@markusressel markusressel deleted the bugfix/#152_pan_to_center branch June 12, 2020 18:34
@markusressel markusressel mentioned this pull request Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZoomImageView doesn't initially pan to center of the bitmap
2 participants