Commit 1d12e8b
feat!: add modular resource fetcher adapters for Expo and bare React Native (#759)
## 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?
- [x] Yes
- [ ] No
**Migration Required:**
Users must now explicitly initialize the library with a resource fetcher
adapter:
```typescript
// 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)
- [x] New feature (change which adds functionality)
- [x] Documentation update (improves or adds clarity to existing
documentation)
- [ ] Other (chores, tests, code style improvements etc.)
### Tested on
- [x] iOS
- [x] 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 #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
<!-- Add screenshots here, if applicable -->
### Related issues
Closes #549
### 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
**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.
---------
Co-authored-by: Mateusz Słuszniak <mateusz.sluszniak@swmansion.com>
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Co-authored-by: Jakub Chmura <92989966+chmjkb@users.noreply.github.com>1 parent 19cc916 commit 1d12e8b
90 files changed
Lines changed: 3655 additions & 1398 deletions
File tree
- .github/workflows
- apps
- computer-vision
- app
- llm
- app
- llm_structured_output
- llm_tool_calling
- llm
- voice_chat
- speech
- text-embeddings
- app
- docs/docs
- 01-fundamentals
- 06-api-reference
- classes
- enumerations
- functions
- interfaces
- react-native-executorch/namespaces/ResourceFetcherUtils
- functions
- type-aliases
- packages
- bare-resource-fetcher
- src
- constants
- expo-resource-fetcher
- src
- constants
- react-native-executorch
- common/rnexecutorch
- src
- common
- controllers
- errors
- modules
- computer_vision
- general
- natural_language_processing
- utils
- readmes
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
79 | 88 | | |
80 | 89 | | |
81 | 90 | | |
| |||
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
91 | | - | |
| 100 | + | |
| 101 | + | |
92 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
93 | 108 | | |
94 | 109 | | |
95 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
| |||
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
5 | | - | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
0 commit comments