Skip to content

Image Size Changes in InputTextView After Screen Rotation #278

@style513

Description

@style513

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions