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

support for focus point in image #1392

Merged
merged 3 commits into from
Jan 15, 2025

Conversation

tvrrp
Copy link
Contributor

@tvrrp tvrrp commented Jan 2, 2025

Added support for focus point in image
Size and offset calc are taken from here

Screenshot 2025-01-02 at 11 38 33

Closes #868

@CLAassistant
Copy link

CLAassistant commented Jan 2, 2025

CLA assistant check
All committers have signed the CLA.

@whattherestimefor
Copy link
Contributor

Thanks so much for addressing this. I wonder if this could be done with a little less code by using the anchorPoint property of CGLayer? Is that an approach you considered or would like to consider?

@tvrrp
Copy link
Contributor Author

tvrrp commented Jan 15, 2025

@whattherestimefor It can be done using anchorPoint, but in the end, it would require the same amount of code. Much of the code in this MR changes the logic behind the animated transition to MediaPreviewController.

UIImageView clips the original image to fit inside its bounds. Because of this, UIImageView must have the full width or height (depending on the aspect ratio). This allows the origin to be used for shifting the image to the focus point. I think this approach is easier to understand than manipulating layer properties or transforms.

Since I changed the image size, it broke the logic behind the animated transition. That’s why an additional container with clipToBounds enabled was required. Otherwise, the image would pop out of its original container during the push animation, as the code relies on the frame growing to a specific size and assumes that UIImageView will handle fitting the image to the new size.

Changing the anchorPoint of CALayer would result in the same problems as the origin shift approach. The underlying CALayer would pop out of the container during the animation, requiring additional layer rect manipulation in MediaPreviewController.

As for the code behind focus point calculation, it will not work by simply shifting the anchorPoint. The JS library referenced in the Mastodon documentation first clips the image to the container using either the container’s width or height, depending on the image’s aspect ratio. From the scaled size, it then calculates the focus point.

@whattherestimefor
Copy link
Contributor

Great, thank you!

@whattherestimefor whattherestimefor merged commit 571d736 into mastodon:develop Jan 15, 2025
1 check passed
@tvrrp tvrrp deleted the image-focus-support branch January 17, 2025 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Image focal point is ignored when displaying attached images
3 participants