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

When inserting an image into the RichTextEdit contained within a ScrollView, the image is being scaled down to the height of the view. This happens because the smallest height is being used for scaling. #221

Open
alonematch86 opened this issue Dec 14, 2024 · 1 comment

Comments

@alonematch86
Copy link

When inserting an image into the RichTextEdit contained within a ScrollView, the image is being scaled down to the height of the view. This happens because the smallest height is being used for scaling.

To resolve this, I modified the RichTextImageAttachmentManager.swift file by commenting out the logic responsible for height scaling in the attachmentSize method.

public extension RichTextImageAttachmentManager {

/// Get the attachment bounds of an image, given a max size.
func attachmentBounds(
    for image: ImageRepresentable,
    maxSize: CGSize
) -> CGRect {
    let size = attachmentSize(for: image, maxSize: maxSize)
    return CGRect(origin: .zero, size: size)
}

/// Get the attachment size of an image, given a max size.
func attachmentSize(
    for image: ImageRepresentable,
    maxSize: CGSize
) -> CGSize {
    let size = image.size
    let validWidth = size.width < maxSize.width
    let validHeight = size.height < maxSize.height
    let validSize = validWidth && validHeight
    if validSize { 
        return image.size 
    }
    
    let aspectWidth = maxSize.width / size.width
    // Removed height scaling logic to avoid shrinking the image unnecessarily
    // let aspectHeight = maxSize.height / size.height
    let aspectRatio = aspectWidth // min(aspectWidth, aspectHeight)
    
    let newSize = CGSize(
        width: size.width * aspectRatio,
        height: size.height * aspectRatio
    )
    return newSize
}

}

@danielsaidi
Copy link
Owner

Thank you for the information @alonematch86

I will take a look if I'll add this to the SDK.

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

No branches or pull requests

2 participants