Skip to content

feat: add onImagePress event to EnrichedText - #681

Open
kacperzolkiewski wants to merge 17 commits into
mainfrom
@kacperzolkiewski/feat-on-image-press
Open

feat: add onImagePress event to EnrichedText#681
kacperzolkiewski wants to merge 17 commits into
mainfrom
@kacperzolkiewski/feat-on-image-press

Conversation

@kacperzolkiewski

@kacperzolkiewski kacperzolkiewski commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add OnImagePress event

Test Plan

  1. Display remote and local images inside EnrichedText in example app.
  2. Press on them and check if OnImagePress event is emitted

Screenshots / Videos

Screen.Recording.2026-07-06.at.17.13.49.mov

Compatibility

OS Implemented
iOS
Android
Web

Checklist

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

@kacperzolkiewski
kacperzolkiewski marked this pull request as ready for review July 6, 2026 19:14
Copilot AI lite review requested due to automatic review settings July 6, 2026 19:14

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.

Pull request overview

Adds a new cross-platform (iOS/Android) onImagePress event to EnrichedText, allowing consumers to react to presses on inline <img> elements and receive the pressed image’s URI and dimensions.

Changes:

  • Extend the public TS API (EnrichedTextProps) with onImagePress and a new OnImagePressEvent type, and re-export it from the package entrypoints.
  • Wire the event through the React Native codegen spec and JS wrapper, then emit it from native iOS + Android implementations.
  • Document the new prop, update the example app to demonstrate it, and add an E2E Maestro flow covering image press.

Reviewed changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/types.ts Adds onImagePress prop and OnImagePressEvent type to the public TS API.
src/spec/EnrichedTextNativeComponent.ts Adds codegen event type + onImagePress to native component props.
src/native/EnrichedText.tsx Plumbs the native onImagePress event through to the JS EnrichedText prop.
src/index.tsx Re-exports OnImagePressEvent from the library entrypoint.
src/index.native.tsx Re-exports OnImagePressEvent for native entrypoint parity.
ios/utils/EnrichedTextTouchHandler.mm Detects presses on EnrichedImage attributes and dispatches image-press events.
ios/EnrichedTextView.mm Emits onImagePress via the Fabric event emitter with URI + dimensions.
ios/EnrichedTextView.h Declares emitOnImagePressEvent: on the view interface.
docs/TEXT_API_REFERENCE.md Documents onImagePress, its payload shape, and lack of visual feedback.
apps/example/src/screens/EnrichedTextScreen.tsx Demonstrates handling onImagePress in the example screen.
apps/example/src/components/TextRenderer.tsx Demonstrates handling onImagePress in the renderer component.
android/src/main/java/com/swmansion/enriched/text/spans/EnrichedTextImageSpan.kt Makes image spans clickable and dispatches OnImagePressEvent.
android/src/main/java/com/swmansion/enriched/text/events/OnImagePressEvent.kt Adds the native Android event payload for onImagePress.
android/src/main/java/com/swmansion/enriched/text/EnrichedTextViewManager.kt Registers onImagePress as a direct event for the view manager.
.maestro/enrichedText/flows/image_press.yaml Adds an E2E flow to validate image press event behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kacperzolkiewski
kacperzolkiewski marked this pull request as draft July 7, 2026 08:41
@kacperzolkiewski
kacperzolkiewski marked this pull request as ready for review July 10, 2026 10:14

@hejsztynx hejsztynx 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.

Works great!

kacperzolkiewski and others added 3 commits July 21, 2026 07:53
# Summary

Implemented `onImagePress` callback functionality on the web
`EnrichedText` component

## Test Plan

There is a set `console.log` callback in the main example app, to see
the feature works.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |    ❌     |
| Android |    ❌     |
| Web     |    ✅     |

## Checklist

- [x] E2E tests are passing
- [x] Required E2E tests have been added (if applicable)

@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.

lgtm, just remember to wait for the docs to land first and update them, not a .md

Comment thread docs/TEXT_API_REFERENCE.md 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.

Good, a small nit

Comment thread docs/docs/core-functionalities/rendering-rich-text.mdx Outdated
Comment thread docs/docs/core-functionalities/rendering-rich-text.mdx Outdated
Copilot AI review requested due to automatic review settings August 28, 2026 10:33
@hejsztynx
hejsztynx force-pushed the @kacperzolkiewski/feat-on-image-press branch from 0f5348b to 63e9ad8 Compare August 28, 2026 10:34

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.

Pull request overview

Copilot reviewed 24 out of 26 changed files in this pull request and generated 4 comments.

Comment thread src/web/htmlExtensions/usePressInteractions.ts
Comment thread src/web/EnrichedText.css Outdated
Comment thread ios/EnrichedTextView.mm
Copilot AI review requested due to automatic review settings August 28, 2026 10:37

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.

Pull request overview

Copilot reviewed 24 out of 26 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/web/htmlExtensions/usePressInteractions.ts:50

  • When an is nested inside an or , this handler can emit multiple press events for a single click (e.g., onImagePress and onLinkPress), because execution continues after the image block. Consider short-circuiting after handling the image (only when onImagePress is provided) to avoid double-dispatch and ambiguous behavior.
      const image = target.closest('img');
      if (image && container.contains(image)) {
        e.preventDefault();

        const imageAttributes = getImageAttributes(image);

        if (imageAttributes) {
          onImagePressRef.current?.({
            image: imageAttributes,
          });
        }
      }

src/web/EnrichedText.css:347

  • This rule sets pointer-events: none; twice. Keeping it once avoids duplication and makes future edits less error-prone.
  pointer-events: none;
  accent-color: var(--et-checkbox-box-color, #0000ff);

  /* disable checkbox press style as it's read-only */
  pointer-events: none;

hejsztynx and others added 2 commits August 28, 2026 18:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
if (!uri) {
return undefined;
}
const uri = image.getAttribute('src') ?? '';

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.

Tweaked the web implementation to emit an onImagePress event, even when src is empty. This is done to match the mobile implementation

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.

4 participants