Skip to content

fix(ios, android): clamp image dimensions if the given width exceeds the available space - #807

Open
hejsztynx wants to merge 9 commits into
mainfrom
@ksienkiewicz/fix-img-dimensions-clamping
Open

hejsztynx wants to merge 9 commits into
mainfrom
@ksienkiewicz/fix-img-dimensions-clamping

Conversation

@hejsztynx

Copy link
Copy Markdown
Collaborator

Summary

Closes #797

When the image's width was exceeding the available horizontal space in the container's view, it lead to unwanted behavior on both mobile platforms.

Android:

  • if the width-exeeding image was the last element inside EnrichedText, it did not render
  • the width-exeeding image did not properly wrap inside both EnrichedText and EnrichedTextInput

iOS:

  • in EnrichedText the width-exceeding images did not wrap properly and overflowed the container horizontally
  • in EnrichedTextInput the width-exceeding image was cut to the container's width

Added a relevant e2e test suite that checks both clamping and wrapping inside both components.

Test Plan

Add some inline images width dimensions exceeding the container's ones. The image should be scaled down properly. Put them into a single paragraph to see if they wrap correctly.

Screenshots / Videos

Used HTML:

<html>
   <p>
      <img src="https://picsum.photos/200/200" width="100" height="100"/>
      <img src="https://picsum.photos/200/200" width="100" height="100"/>
      <img src="https://picsum.photos/200/200" width="100" height="100"/>
      <img src="https://picsum.photos/400/100" width="400" height="100"/>
   </p>
   <p>
      <img src="https://picsum.photos/400/100" width="400" height="100"/>
   </p>
</html>

EnrichedText

Android:

Before:

image

After:

image

iOS:

Before:

image

After:

image

EnrichedTextInput

Android:

Before:

image

After:

image

iOS:

Using HTML:

<html>
   <p>
      <img src="https://picsum.photos/id/140/400/100" width="400" height="100"/>
   </p>
</html>

Before:

image

After:

image

Compatibility

OS Implemented
iOS ✅
Android ✅
Web ❌

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

@hejsztynx
hejsztynx marked this pull request as draft September 24, 2026 11:16
@hejsztynx
hejsztynx requested a lite review from Copilot September 24, 2026 11:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Clamps oversized inline images on iOS and Android to available content width and adds Maestro coverage for wrapping behavior.

Changes:

  • Scales image attachment bounds and overlay frames on iOS.
  • Propagates container width to Android image spans.
  • Adds EnrichedText and EnrichedTextInput Maestro flows.
File Description
ios/​utils/​AttachmentLayoutUtils.mm Updated as part of this pull request.
ios/​interfaces/​ImageAttachment.mm Updated as part of this pull request.
android/​src/​main/​java/​com/​swmansion/​enriched/​textinput/​EnrichedTextInputView.kt Updated as part of this pull request.
android/​src/​main/​java/​com/​swmansion/​enriched/​text/​MeasurementStore.kt Updated as part of this pull request.
android/​src/​main/​java/​com/​swmansion/​enriched/​text/​EnrichedTextView.kt Updated as part of this pull request.
android/​src/​main/​java/​com/​swmansion/​enriched/​common/​spans/​EnrichedImageSpan.kt Updated as part of this pull request.
.maestro/​enrichedText/​flows/​image_wrap.yaml Updated as part of this pull request.
.maestro/​enrichedInput/​flows/​image_width_clamping.yaml Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt Outdated

@szydlovsky szydlovsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

iOS looks solid

Comment thread ios/interfaces/ImageAttachment.mm Outdated
Comment thread ios/utils/AttachmentLayoutUtils.mm Outdated
Base automatically changed from @ksienkiewicz/fix-ios-enriched-text-img-relayout to main October 12, 2026 10:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants