feat: support loading local images#588
Open
eszlamczyk wants to merge 5 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class support for rendering bundled/local image sources in markdown across iOS/macOS and Android, aligning behavior with React Native’s <Image> resolution so release builds work the same as dev (Fixes #377).
Changes:
- iOS/macOS: introduce a local image loader and branch
ENRMImageDownloaderto load local sources withoutNSURLSession. - Android: add
LocalImageLoaderto handle multiple non-network URI shapes (resources, android_res/android_asset, content, data URIs) and route non-HTTP(S) spans through it. - Docs + example: document supported URI forms and add Storybook stories for local asset + data URI.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-enriched-markdown/ios/utils/ENRMLocalImageLoader.m | New iOS/macOS local image resolution implementation (bundle-relative + file loading). |
| packages/react-native-enriched-markdown/ios/utils/ENRMLocalImageLoader.h | Public API/docs for local image detection + loading. |
| packages/react-native-enriched-markdown/ios/utils/ENRMImageDownloader.m | Routes local sources through the local loader before NSURLSession. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/text/LocalImageLoader.kt | New Android local-source decoder supporting RN/expo URI variants. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/text/ImageDownloader.kt | Adds a bytes-based downsample decode helper used by local loading paths. |
| packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt | Uses scheme parsing to route non-HTTP(S) images through LocalImageLoader. |
| packages/android-enriched-markdown/ui/src/main/java/com/swmansion/enriched/markdown/utils/text/LocalImageLoader.kt | Mirrors Android local-source decoder for the UI package. |
| packages/android-enriched-markdown/ui/src/main/java/com/swmansion/enriched/markdown/utils/text/ImageDownloader.kt | Adds bytes-based downsample decode helper in the UI package. |
| packages/android-enriched-markdown/ui/src/main/java/com/swmansion/enriched/markdown/spans/ImageSpan.kt | Routes non-HTTP(S) images through LocalImageLoader in the UI package. |
| docs/IMAGE_CACHING.md | Documents supported image source formats and behavior differences for local vs network. |
| apps/react-native-example/.rnstorybook/stories/components/EnrichedMarkdownText/block/Image.stories.tsx | Adds Storybook coverage for local bundled assets and data URIs. |
Comments suppressed due to low confidence (1)
packages/react-native-enriched-markdown/ios/utils/ENRMLocalImageLoader.m:55
decodedis anNSString;absolutePathisn’t an NSString API and should fail to compile. If the intent is to branch on absolute vs bundle-relative paths, useisAbsolutePath.
if (decoded.absolutePath) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eszlamczyk
marked this pull request as ready for review
July 24, 2026 16:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What/Why?
Fixes #377.
Bundled/local images never rendered outside dev mode. In dev,
require()'d assets resolve to Metro http URLs, which go through the network loaders and work. In a bundled app they resolve to shapes the library did not understand:src_assets_logo) - this is also exactly what expo-asset hands out asuri/localUrifile:///android_res/<dir>/<file>paths, which are not real filesystem pathsfile://URLs near the app bundleThe Android side only stripped a
file://prefix and calledBitmapFactory.decodeFile(); iOS pushed every URL throughNSURLSession. This PR adds proper local-source resolution on both platforms, mirroring what React Native core does for<Image>:LocalImageLoaderdispatches onUri.parse().scheme, following RN'sImageSource/ResourceDrawableIdHelperand expo-asset'sResourceAsset.kt: bare resource names (lowercased,-replaced with_, numeric ids accepted, drawable then raw),file://with percent-decoding,file:///android_res/with density-qualifier stripping,file:///android_asset/,asset://,res://,content://, anddata:base64 URIs. All decodes reuse the existing screen-width downsampling.ENRMLocalImageLoadermirrorsRCTImageFromLocalAssetURL: bundle-relative sources go throughimageNamed:first (asset catalogs and 2x/3x scale selection for free), falling back to direct file loading with percent-decoding viafileSystemRepresentation.ENRMImageDownloaderbranches to it before theNSURLSessionpath, so local files skip HTTP caching/timeouts but keep both memory cache tiers.ENRMImageAttachmentis unchanged.Testing
Dev mode (both platforms)
EnrichedMarkdownText/Block/Image:Default- remote image still loads (network path regression check)LocalAsset- renders via Metro URL; description shows the resolved URIDataUri- checkerboard renders; on Android this runs the newLocalImageLoadereven in devDataUri/LocalAssetstories to confirm memory-cache hits render instantly (no flash of empty span).Release builds (the actual #377 scenario)
3. Android:
yarn android:test:release, open theLocalAssetstory - the URI is now a bare drawable name and must render through the resource lookup.4. iOS: build the example app in Release -
LocalAssetresolves to a bundlefile://URL and must render throughENRMLocalImageLoader.5. Rotate/resize on both to confirm the processed-variant cache and reflow still work for locally loaded images.
Regression checks
6. Remote images with
imageRequestHeadersstill fetch and cache per-header (local sources ignore headers by design).8. Inline images (image next to text) still render for both local and remote sources.
PR Checklist