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

Image Size Changes in InputTextView After Screen Rotation #278

Open
style513 opened this issue Dec 11, 2024 · 0 comments
Open

Image Size Changes in InputTextView After Screen Rotation #278

style513 opened this issue Dec 11, 2024 · 0 comments
Labels

Comments

@style513
Copy link

Description

In the implementation of InputTextView, the method redrawTextAttachments() is triggered whenever the device orientation changes. This method adjusts the size of NSTextAttachment images:

@objc
private func redrawTextAttachments() {
    guard images.count > 0 else { return }
    let range = NSRange(location: 0, length: attributedText.length)
    attributedText.enumerateAttribute(.attachment, in: range, options: [], using: { value, _, _ -> Void in
        if let attachment = value as? NSTextAttachment, let image = attachment.image {
            let newWidth = frame.width - 2 * (textContainerInset.left + textContainerInset.right)
            let ratio = image.size.height / image.size.width
            attachment.bounds.size = CGSize(width: newWidth, height: ratio * newWidth)
        }
    })
    layoutManager.invalidateLayout(forCharacterRange: range, actualCharacterRange: nil)
}

The logic is designed to resize the images based on the width of the InputTextView. However, there are a few concerns:
1. Why is it necessary to adjust the image size on screen rotation?
Is this behavior tied to a specific use case or requirement?
2. Why does the adjustment result in such a significant size change?
The new width is calculated as frame.width - 2 * (textContainerInset.left + textContainerInset.right), which can sometimes make the images unnaturally large.

Steps to Reproduce
1. Add some images as NSTextAttachment in InputTextView.
2. Rotate the device to a different orientation.
3. Observe that the images are resized and may become too large.

Expected Behavior
• After screen rotation, image sizes should be adjusted reasonably.
• There should be an option to prevent image resizing unless explicitly required.

Questions
• What is the purpose of resizing images upon screen rotation?
• Can we have a configuration option to toggle this resizing behavior?

@style513 style513 changed the title Issue: Image Size Changes in InputTextView After Screen Rotation Image Size Changes in InputTextView After Screen Rotation Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant