Skip to content

Commit a9fbbfb

Browse files
committed
docs: expo router entry
1 parent 7537136 commit a9fbbfb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

docs/docs/tutorial/register-task-handler.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ registerWidgetTaskHandler(widgetTaskHandler);
7171

7272
## Register widget task handler (Expo)
7373

74+
:::warning Note
75+
The below is just an example. New versions of expo router or expo might have different code in the entry file. The main goal is to see what the original `main` property in `package.json` was, and copy the code from that file in `index.ts`.
76+
77+
After that, add `registerWidgetTaskHandler(widgetTaskHandler);`
78+
:::
79+
7480
If we are using Expo, there is no `index.js` (or `index.ts`, `index.tsx`), but we can create it.
7581

7682
First, update `package.json` main field to point to `index.ts` (or `.js`) instead of `node_modules/expo/AppEntry.js`
@@ -100,6 +106,30 @@ registerRootComponent(App);
100106
registerWidgetTaskHandler(widgetTaskHandler);
101107
```
102108

109+
## Register widget task handler (Expo + Expo Router)
110+
111+
If we are using Expo with Expo Router, there is no `index.js` (or `index.ts`, `index.tsx`), but we can create it.
112+
113+
First, update `package.json` main field to point to `index.ts` (or `.js`) instead of `expo-router/entry`
114+
115+
```js title="package.json"
116+
{
117+
"name": "my-expo-app",
118+
"main": "index.ts",
119+
...
120+
}
121+
```
122+
123+
Create the file, using `node_modules/expo-router/entry` as a template.
124+
Then import `widgetTaskHandler` and register it.
125+
126+
```js title="index.ts"
127+
import 'expo-router/entry';
128+
import { widgetTaskHandler } from './widget-task-handler';
129+
130+
registerWidgetTaskHandler(widgetTaskHandler);
131+
```
132+
103133
## Next steps
104134

105135
We designed our widget, saw the preview, and registered a handler that will handle adding it to the home screen.

0 commit comments

Comments
 (0)