Skip to content

feat!: add modular resource fetcher adapters for Expo and bare React Native#759

Merged
msluszniak merged 43 commits intosoftware-mansion:mainfrom
rizalibnu:feat/resource-fetcher-adapters
Feb 19, 2026
Merged

feat!: add modular resource fetcher adapters for Expo and bare React Native#759
msluszniak merged 43 commits intosoftware-mansion:mainfrom
rizalibnu:feat/resource-fetcher-adapters

Conversation

@rizalibnu
Copy link
Copy Markdown
Contributor

@rizalibnu rizalibnu commented Jan 27, 2026

Description

This PR introduces modular resource fetcher adapters to support both Expo and bare React Native environments, replacing the previous monolithic approach with a flexible, platform-specific architecture.

Key Changes
New Adapter Packages:

  • @rn-executorch/expo-adapter: Resource fetcher for Expo projects using expo-file-system and expo-asset
  • @rn-executorch/bare-adapter: Resource fetcher for bare React Native projects using @dr.pogodin/react-native-fs and @kesha-antonov/react-native-background-downloader

Initialization Changes:

  • Added initExecutorch() function that requires explicit adapter selection
  • Users must now choose and configure the appropriate adapter for their project type
  • Provides better separation of concerns and platform-specific optimizations

Documentation Updates:

  • Created individual README.md files for each adapter package

Introduces a breaking change?

  • Yes
  • No

Migration Required:
Users must now explicitly initialize the library with a resource fetcher adapter:

// Before (no initialization needed)
import { useLLM } from 'react-native-executorch';

// After (required initialization)
import { initExecutorch, useLLM } from 'react-native-executorch';
import { ExpoResourceFetcher } from '@rn-executorch/expo-adapter'; // or BareResourceFetcher

initExecutorch({
  resourceFetcher: ExpoResourceFetcher,
});

Type of change

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Documentation update (improves or adds clarity to existing documentation)
  • Other (chores, tests, code style improvements etc.)

Tested on

  • iOS
  • Android

Testing instructions

For Expo projects:

  • Install dependencies: yarn add @rn-executorch/expo-adapter expo-file-system expo-asset
  • Initialize: initExecutorch({ resourceFetcher: ExpoResourceFetcher })
  • Run existing LLM example app to verify model downloads work correctly

For bare React Native projects:

  • Install dependencies: yarn add @rn-executorch/bare-adapter @dr.pogodin/react-native-fs @kesha-antonov/react-native-background-downloader
  • Initialize: initExecutorch({ resourceFetcher: BareResourceFetcher })
  • Run the bare React Native example app in PR feat: add bare React Native LLM chat example app #763

Note: A separate PR will add a dedicated bare React Native example app to make this PR easier to review. The Expo example apps can be used to verify the Expo adapter functionality.

Screenshots

Related issues

Closes #549

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional notes

Why This Change:

  • Different React Native environments have different filesystem APIs and c
  • apabilities
  • Expo projects benefit from using Expo's managed filesystem APIs
  • Bare React Native projects can leverage native libraries with background download support
  • Modular architecture allows for better platform-specific optimizations
  • Enables future extensibility for other environments (e.g., React Native Windows, macOS)

Split Into Multiple PRs:
To make review easier, this work has been split:

  • This PR: Core adapter infrastructure and Expo adapter implementation
  • Follow-up PR: Bare React Native example app demonstrating the bare adapter usage

BREAKING CHANGE: initExecutorch() with explicit adapter selection is now required before using any react-native-executorch hooks. Users must install and configure either @rn-executorch/expo-adapter or @rn-executorch/bare-adapter depending on their project type.

@rizalibnu rizalibnu changed the title feat: add modular resource fetcher adapters for Expo and React Native feat: add modular resource fetcher adapters for Expo and bare React Native Jan 27, 2026
@IgorSwat IgorSwat requested a review from chmjkb January 27, 2026 08:42
@mkopcins mkopcins self-requested a review January 27, 2026 09:02
@msluszniak
Copy link
Copy Markdown
Member

Lint CI fails (you don't need to worry about the second failing CI ;)). Please could you fix the errors from this CI?

@rizalibnu
Copy link
Copy Markdown
Contributor Author

@msluszniak I’m not able to reproduce the lint CI failure locally — everything passes on my side.

I’ll take a closer look and investigate further to see what might be causing the discrepancy (environment, cache, or config differences). I’ll follow up with a fix or more details as soon as I find the root cause.

Screenshot 2026-01-27 at 17 19 22

@msluszniak
Copy link
Copy Markdown
Member

@rizalibnu Sure thing, maybe the configuration of the CI itself does not work with as it should. We'll also look at this, don't worry :)

@rizalibnu rizalibnu marked this pull request as draft January 27, 2026 13:22
@rizalibnu rizalibnu marked this pull request as ready for review January 27, 2026 14:06
@rizalibnu
Copy link
Copy Markdown
Contributor Author

@msluszniak Found the issue 👍
CI was failing because react-native-executorch types come from lib/typescript, which isn’t built on a fresh run. It worked locally since I already had the build artifacts.

Fixed by adding a build step before adapter type checks and bumped Node to 22 in .nvmrc due to an ESM-only dependency (arktype via react-native-builder-bob).

@rizalibnu rizalibnu force-pushed the feat/resource-fetcher-adapters branch from 72914c0 to 359427b Compare January 27, 2026 14:57
@msluszniak msluszniak added the feature PRs that implement a new feature label Jan 28, 2026
Comment thread package.json Outdated
Comment thread packages/expo-adapter/package.json Outdated
Comment thread apps/llm/tsconfig.json Outdated
Comment thread package.json Outdated
Comment thread packages/react-native-executorch/src/index.ts Outdated
Comment thread packages/bare-adapter/README.md Outdated
Comment thread packages/bare-adapter/src/ResourceFetcherUtils.ts Outdated
Comment thread packages/expo-resource-fetcher/src/ResourceFetcherUtils.ts
Comment thread packages/react-native-executorch/src/utils/ResourceFetcher.ts Outdated
Comment thread packages/bare-resource-fetcher/src/ResourceFetcher.ts Outdated
Comment thread packages/bare-resource-fetcher/src/ResourceFetcher.ts Outdated
Comment thread packages/bare-resource-fetcher/src/ResourceFetcher.ts
@msluszniak
Copy link
Copy Markdown
Member

msluszniak commented Feb 3, 2026

Also I think that adding these changes will make section Fundamentals in documentation out of date. Could look at these three subsections, and make sure they will be up to date? Also, a docs for ResourceFetcher itself would need an update.

@NorbertKlockiewicz
Copy link
Copy Markdown
Contributor

Hi, I worked a bit with this PR by building bare react native app. From what I've tested I didn't get a single issue with the bare resource fetcher and the integration was also very smooth. To sum up my experience with it was good and I don't have any issues. Thank you @rizalibnu for this amazing piece of code :D

msluszniak

This comment was marked as resolved.

Comment thread packages/bare-resource-fetcher/src/ResourceFetcherUtils.ts Outdated
@msluszniak msluszniak self-assigned this Feb 16, 2026
@msluszniak
Copy link
Copy Markdown
Member

The last thing from my side is to add API Reference to this PR generated from typedoc comments & resolve warning / errors that comes from pre-commit hook.

@msluszniak msluszniak force-pushed the feat/resource-fetcher-adapters branch from e06996f to 1407899 Compare February 17, 2026 12:12
@msluszniak msluszniak force-pushed the feat/resource-fetcher-adapters branch from 1b95894 to f9d9449 Compare February 17, 2026 14:14
Comment thread packages/react-native-executorch/src/modules/computer_vision/OCRModule.ts Outdated
Comment thread packages/react-native-executorch/src/modules/computer_vision/TextToImageModule.ts Outdated
Comment thread packages/react-native-executorch/src/modules/computer_vision/TextToImageModule.ts Outdated
Add modular resource fetcher adapters to support both Expo and bare React Native environments.

- Expo-based resource fetcher using expo-file-system
- Supports asset bundles, local files, and remote downloads
- Download management with pause/resume/cancel capabilities

- Bare React Native resource fetcher using RNFS and background downloader
- Supports all platform-specific file operations
- Background download support with proper lifecycle management

- Refactor ResourceFetcher to use adapter pattern
- Add initExecutorch() and cleanupExecutorch() for adapter management
- Export adapter interfaces and utilities
- Update LLM controller to support new resource fetching

- Update computer-vision, llm, speech-to-text, text-embeddings apps
- Add adapter initialization to each app
- Update dependencies to use workspace packages
@msluszniak msluszniak changed the title feat: add modular resource fetcher adapters for Expo and bare React Native feat!: add modular resource fetcher adapters for Expo and bare React Native Feb 18, 2026
Comment thread packages/react-native-executorch/src/controllers/BaseOCRController.ts Outdated
Comment thread docs/docs/01-fundamentals/01-getting-started.md Outdated
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Comment thread packages/react-native-executorch/src/modules/general/ExecutorchModule.ts Outdated
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Co-authored-by: Jakub Chmura <92989966+chmjkb@users.noreply.github.com>
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Comment thread docs/docs/01-fundamentals/02-loading-models.md Outdated
Comment thread docs/docs/01-fundamentals/01-getting-started.md Outdated
@msluszniak msluszniak requested a review from chmjkb February 19, 2026 09:55
Copy link
Copy Markdown
Collaborator

@chmjkb chmjkb left a comment

Choose a reason for hiding this comment

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

overall looks good, thanks @rizalibnu @msluszniak
one more thing - the current README is now obsolete. Can we update it? 🙏🏻

@msluszniak msluszniak requested a review from chmjkb February 19, 2026 11:42
@msluszniak msluszniak merged commit 1d12e8b into software-mansion:main Feb 19, 2026
5 checks passed
msluszniak added a commit that referenced this pull request Mar 16, 2026
## Description

Adds a new bare React Native example application demonstrating LLM chat
functionality using Executorch. This example provides a complete
reference implementation for running local LLM inference on mobile
devices through a simple chat interface.

**Key features:**

- Local LLM inference using Executorch
- Simple chat UI with message history
- Model loading and inference pipeline
- Error handling and user feedback
- Compatible with both iOS and Android

### Introduces a breaking change?

- [ ] Yes
- [x] No

### Type of change

- [ ] Bug fix (change which fixes an issue)
- [x] New feature (change which adds functionality)
- [ ] Documentation update (improves or adds clarity to existing
documentation)
- [ ] Other (chores, tests, code style improvements etc.)

### Tested on

- [x] iOS
- [x] Android

### Testing instructions

1. Navigate to the example directory:

`cd apps/bare_rn`

2. Install dependencies:

`yarn install`

3. Run on iOS:

`npx pod-install`
`yarn ios`

Or run on Android:

`yarn android`

4. Verify the app launches and displays the chat interface

5. Test message sending and model inference (requires model file setup)

### Screenshots

[
<img width="1040" height="1037" alt="Screenshot 2026-01-28 at 02 06 29"
src="https://github.com/user-attachments/assets/3774f4d2-ccc0-414b-85e7-3e26b06249ad"
/>
](url)

### Related issues

This PR provides an example app for PR #759

### Checklist

- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation accordingly
- [x] My changes generate no new warnings

### Additional notes

This example app was generated using `npx
@react-native-community/cli@latest init bare_rn --version 0.81.5 --pm
yarn` and follows bare React Native project structure (not Expo). It
serves as a foundational example for developers to understand how to
integrate Executorch for on-device LLM inference in their React Native
applications.

**Why this example is not included in the yarn workspace:**

The bare React Native example is maintained outside the yarn workspace
structure due to fundamental architectural differences and specific
technical issues:

1. Native Module Resolution Issues with Background Downloader:
Using the workspace monorepo breaks the Android app's integration with
`@kesha-antonov/react-native-background-downloader`. The monorepo's
package hoisting and workspace resolution interferes with the native
module's ability to properly register and resolve its native components.
This causes runtime failures when attempting to download AI models in
the background, which is a critical feature for this LLM chat example.

2. Dependency Isolation: Bare React Native projects have distinct native
dependency chains (iOS Pods, Android Gradle) that conflict with the
monorepo's package management. The monorepo uses workspaces and hoisting
strategies optimized for JavaScript/TypeScript packages, which can
interfere with native module resolution.

---------

Co-authored-by: Mateusz Słuszniak <mateusz.sluszniak@swmansion.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Co-authored-by: Norbert Klockiewicz <Nklockiewicz12@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PRs that implement a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explore removing expo dependency

5 participants