Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions apps/bare-rn/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'react-native-executorch-bare-resource-fetcher/auto';
import React, { useEffect, useRef, useState } from 'react';
import {
ActivityIndicator,
Expand All @@ -13,12 +14,7 @@ import {
TouchableWithoutFeedback,
View,
} from 'react-native';
import {
initExecutorch,
useLLM,
LLAMA3_2_1B_SPINQUANT,
} from 'react-native-executorch';
import { BareResourceFetcher } from 'react-native-executorch-bare-resource-fetcher';
import { useLLM, LLAMA3_2_1B_SPINQUANT } from 'react-native-executorch';
import { setConfig } from '@kesha-antonov/react-native-background-downloader';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';

Expand All @@ -30,11 +26,6 @@ setConfig({
},
});

// Initialize Executorch with bare adapter
initExecutorch({
resourceFetcher: BareResourceFetcher,
});

const ColorPalette = {
primary: '#001A72',
blueLight: '#C1C6E5',
Expand Down
7 changes: 1 addition & 6 deletions apps/computer-vision/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'react-native-executorch-expo-resource-fetcher/auto';
import { Drawer } from 'expo-router/drawer';
import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher';

import ColorPalette from '../colors';
import React, { useState } from 'react';
Expand All @@ -13,10 +12,6 @@ import {
} from '@react-navigation/drawer';
import { GeneratingContext } from '../context';

initExecutorch({
resourceFetcher: ExpoResourceFetcher,
});

interface CustomDrawerProps extends DrawerContentComponentProps {
isGenerating: boolean;
}
Expand Down
7 changes: 1 addition & 6 deletions apps/llm/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'react-native-executorch-expo-resource-fetcher/auto';
import { Drawer } from 'expo-router/drawer';
import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher';
import ColorPalette from '../colors';
import React, { useState } from 'react';
import { Text, StyleSheet, View } from 'react-native';
Expand All @@ -12,10 +11,6 @@ import {
} from '@react-navigation/drawer';
import { GeneratingContext } from '../context';

initExecutorch({
resourceFetcher: ExpoResourceFetcher,
});

interface CustomDrawerProps extends DrawerContentComponentProps {
isGenerating: boolean;
}
Expand Down
7 changes: 1 addition & 6 deletions apps/speech/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'react-native-executorch-expo-resource-fetcher/auto';
import React, { useState } from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { TextToSpeechScreen } from './screens/TextToSpeechScreen';
Expand All @@ -6,12 +7,6 @@ import ColorPalette from './colors';
import ExecutorchLogo from './assets/executorch.svg';
import { Quiz } from './screens/Quiz';
import { TextToSpeechLLMScreen } from './screens/TextToSpeechLLMScreen';
import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher';

initExecutorch({
resourceFetcher: ExpoResourceFetcher,
});

export default function App() {
const [currentScreen, setCurrentScreen] = useState<
Expand Down
7 changes: 1 addition & 6 deletions apps/text-embeddings/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'react-native-executorch-expo-resource-fetcher/auto';
import { Drawer } from 'expo-router/drawer';
import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher';
import ColorPalette from '../colors';
import React, { useState } from 'react';
import { Text, StyleSheet, View } from 'react-native';
Expand All @@ -12,10 +11,6 @@ import {
} from '@react-navigation/drawer';
import { GeneratingContext } from '../context';

initExecutorch({
resourceFetcher: ExpoResourceFetcher,
});

interface CustomDrawerProps extends DrawerContentComponentProps {
isGenerating: boolean;
}
Expand Down
12 changes: 10 additions & 2 deletions docs/docs/01-fundamentals/01-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,20 @@ Installation is pretty straightforward, use your package manager of choice to in
</Tabs>

:::warning
Before using any other API, you must call `initExecutorch` with a resource fetcher adapter at the entry point of your app:
Before using any other API, you must register a resource fetcher adapter at the entry point of your app. The simplest way is a side-effect import:

```js
// For Expo projects:
import 'react-native-executorch-expo-resource-fetcher/auto';
// Or, for bare React Native projects:
import 'react-native-executorch-bare-resource-fetcher/auto';
```

If you need more control — registering a custom adapter, swapping adapters at runtime, or ordering registration relative to other side effects — call `initExecutorch` directly instead:

```js
import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher';
// or BareResourceFetcher for Expo projects

initExecutorch({ resourceFetcher: ExpoResourceFetcher });
```
Expand Down
16 changes: 14 additions & 2 deletions docs/docs/01-fundamentals/02-loading-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ yarn add react-native-executorch-expo-resource-fetcher
yarn add expo-file-system expo-asset
```

and then add the following code in your React Native app:
and then add a single side-effect import at the entry point of your React Native app:

```typescript
import 'react-native-executorch-expo-resource-fetcher/auto';
```

If you need more control — registering a custom adapter, swapping adapters at runtime, or ordering registration relative to other side effects — call `initExecutorch` directly instead:

```typescript
import { initExecutorch } from 'react-native-executorch';
Expand All @@ -35,9 +41,15 @@ yarn add @dr.pogodin/react-native-fs @kesha-antonov/react-native-background-down

and

```typescript
import 'react-native-executorch-bare-resource-fetcher/auto';
```

The same `initExecutorch(...)` escape hatch applies for the bare adapter:

```typescript
import { initExecutorch } from 'react-native-executorch';
import { BareResourceFetcher } from '@react-native-executorch/bare-adapter';
import { BareResourceFetcher } from 'react-native-executorch-bare-resource-fetcher';

initExecutorch({
resourceFetcher: BareResourceFetcher,
Expand Down
4 changes: 4 additions & 0 deletions packages/bare-resource-fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
".": {
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./auto": {
"import": "./lib/auto.js",
"types": "./lib/auto.d.ts"
}
},
"files": [
Expand Down
15 changes: 15 additions & 0 deletions packages/bare-resource-fetcher/src/auto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Side-effect import that registers the bare React Native resource
// fetcher with react-native-executorch on import. Saves the boilerplate
// `initExecutorch({ resourceFetcher: BareResourceFetcher })` call at
// app entry. Use this when you have nothing custom to configure:
//
// import 'react-native-executorch-bare-resource-fetcher/auto';
//
// Stick with the explicit `initExecutorch(...)` call from the package's
// main entry if you need to register a different adapter, swap adapters
// at runtime, or order the registration relative to other side effects.

import { initExecutorch } from 'react-native-executorch';
import { BareResourceFetcher } from './ResourceFetcher';

initExecutorch({ resourceFetcher: BareResourceFetcher });
4 changes: 4 additions & 0 deletions packages/expo-resource-fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
".": {
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./auto": {
"import": "./lib/auto.js",
"types": "./lib/auto.d.ts"
}
},
"files": [
Expand Down
15 changes: 15 additions & 0 deletions packages/expo-resource-fetcher/src/auto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Side-effect import that registers the Expo resource fetcher with
// react-native-executorch on import. Saves the boilerplate
// `initExecutorch({ resourceFetcher: ExpoResourceFetcher })` call at
// app entry. Use this when you have nothing custom to configure:
//
// import 'react-native-executorch-expo-resource-fetcher/auto';
//
// Stick with the explicit `initExecutorch(...)` call from the package's
// main entry if you need to register a different adapter, swap adapters
// at runtime, or order the registration relative to other side effects.

import { initExecutorch } from 'react-native-executorch';
import { ExpoResourceFetcher } from './ResourceFetcher';

initExecutorch({ resourceFetcher: ExpoResourceFetcher });
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ResourceFetcher {
static getAdapter(): ResourceFetcherAdapter {
if (!this.adapter) {
const errorMessage =
'ResourceFetcher adapter is not initialized. Please call initExecutorch({ resourceFetcher: ... }) with a valid adapter, e.g., from react-native-executorch-expo-resource-fetcher or react-native-executorch-bare-resource-fetcher. For more details please refer to: https://docs.swmansion.com/react-native-executorch/docs/next/fundamentals/loading-models';
"ResourceFetcher adapter is not initialized. The simplest fix is a side-effect import at your app entry point: `import 'react-native-executorch-expo-resource-fetcher/auto'` (Expo) or `import 'react-native-executorch-bare-resource-fetcher/auto'` (bare React Native). For full control over registration, call `initExecutorch({ resourceFetcher: ... })` directly. See: https://docs.swmansion.com/react-native-executorch/docs/next/fundamentals/loading-models";
// for sanity :)
Logger.error(errorMessage);
throw new RnExecutorchError(
Expand Down
Loading