feat: add onImagePress event to EnrichedText - #681
Conversation
There was a problem hiding this comment.
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) withonImagePressand a newOnImagePressEventtype, 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.
# 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
left a comment
There was a problem hiding this comment.
lgtm, just remember to wait for the docs to land first and update them, not a .md
This reverts commit 685b8ad.
0f5348b to
63e9ad8
Compare
There was a problem hiding this comment.
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;
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| if (!uri) { | ||
| return undefined; | ||
| } | ||
| const uri = image.getAttribute('src') ?? ''; |
There was a problem hiding this comment.
Tweaked the web implementation to emit an onImagePress event, even when src is empty. This is done to match the mobile implementation
Summary
Add
OnImagePresseventTest Plan
EnrichedTextin example app.OnImagePressevent is emittedScreenshots / Videos
Screen.Recording.2026-07-06.at.17.13.49.mov
Compatibility
Checklist