README.md
1# Expo Documentation
2
3This is the public documentation for **Expo**, its SDK, client, and services (**EAS**). This documentation is built using Next.js and you can access it online at https://docs.expo.dev/.
4
5> **Note** **Contributors:** Please make sure that you edit the docs in the **pages/versions/unversioned** for SDK reference if you want your changes to apply to the next SDK version too!
6
7> **Note**
8> If you are looking for Expo Documentation Writing Style guidelines, please refer [Expo Documentation Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md).
9
10## To run locally in development mode
11
121. Download a copy of this repository.
13
14```sh
15git clone https://github.com/expo/expo.git
16```
17
182. Then `cd` into the `docs` directory and install dependencies with:
19
20```sh
21yarn
22```
23
243. Then you can run the app with (make sure you have no server running on port `3002`):
25
26```sh
27yarn run dev
28```
29
304. Now the documentation is running at `http://localhost:3002`, and any changes you make to markdown or JavaScript files will automatically trigger reloads.
31
32### To run locally in production mode
33
34```sh
35yarn run export
36yarn run export-server
37```
38
39## Edit Docs Content
40
41All documentation-related content is inside the **pages** directory. We write docs in markdown with the help of custom React components that provide additional functionality, such as embedding Snack examples, representing commands inside a terminal component and so on.
42
43The documentation is divided into four main sections:
44
45- **Home**: Provides a guided path from starting a project from scratch to deploying it to app stores.
46- **Guides**: General purpose and fundamental guides that help you understand how Expo works and how to use it. This section also contains all EAS related documentation.
47- **Reference**: Detailed reference documentation for all Expo APIs and modules. All Expo SDK API docs are located under **pages/versions** directory. We keep separate versions of documentation for each SDK version currently supported in Expo Go. See [A note about versioning](#a-note-about-versioning) for more information.
48- **Learn**: Tutorials and guides that help you learn how to use Expo and React Native.
49
50> **Note**
51> We are currently in the process of moving our API documentation to being auto-generated using `expotools`'s `GenerateDocsAPIData` command for some Expo libraries.
52
53### Metadata of a page
54
55Each markdown page can be provided metadata in the heading, distinguished by:
56
57```
58---
59metadata: goes here
60---
61```
62
63These metadata items include:
64
65- `title`: Title of the page shown as the heading and in search results.
66- `description`: Description of the page shown in search results and open graph descriptions when the page is shared on social media sites.
67- `hideFromSearch`: Whether to hide the page from Algolia search results. Defaults to `false`.
68- `hideInSidebar`: Whether to hide this page from the sidebar. Defaults to `false`.
69- `hideTOC`: Whether to hide the table of contents (appears on the right sidebar). Defaults to `false`.
70- `sidebar_title`: The title of the page to display in the sidebar. Defaults to the page title.
71- `maxHeadingDepth`: The max level of headings shown in Table of Content on the right side. Defaults to `3`.
72
73### Edit Code
74
75The docs are written with Next.js and TypeScript. If you need to make code changes, follow steps from the [Running locally](#running-locally) section, then open a separate terminal and run the TypeScript compiler in watch mode - it will watch your code changes and notify you about errors.
76
77```sh
78yarn watch
79```
80
81When you are done, you should run `prettier` to format your code. Also, don't forget to run tests and linter before committing your changes.
82
83```sh
84yarn prettier
85yarn test
86yarn lint
87```
88
89### Prose linter
90
91We use [Vale](https://vale.sh/) to lint our docs for style and grammar based on [Expo's writing style guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md).
92
93There are two ways you can use it:
94
95#### Use Vale in VS Code (Recommended)
96
97- [Install Vale on your system](https://vale.sh/docs/vale-cli/installation/)
98- [Install Vale's VS Code extension](https://marketplace.visualstudio.com/items?itemName=errata-ai.vale-server)
99
100Open the doc file (`*.mdx`) that you are working on and you'll may see suggested lines (yellow squiggly) in VS Code editor.
101
102#### Run the `lint-prose` script
103
104In a terminal window, run the `yarn run lint-prose` script from **package.json**. This will run Vale for all markdown files in the **pages** directory.
105
106## Redirects
107
108### Server-side redirects
109
110These redirects are limited in their expressiveness - you can map a path to another path, but no regular expressions are supported. See client-side redirects for more of that. Server-side redirects are re-created on each run of **deploy.sh**.
111
112We currently do two client-side redirects, using meta tags with `http-equiv="refresh"`:
113
114- `/` -> `/versions/latest/`
115- `/versions` -> `/versions/latest`
116
117This method is not great for accessibility and should be avoided where possible.
118
119### Client-side redirects
120
121Use these for more complex rules than one-to-one path-to-path redirect mapping. For example, we use client-side redirects to strip the `.html` extension off, and to identify if the request is for a version of the documentation that we no longer support.
122
123You can add your own client-side redirect rules in `common/error-utilities.ts`.
124
125## Search
126
127We use Algolia as a main search results provider for our docs. Besides the query, results are also filtered based on the `version` tag which represents the user's current location. The tag is set in the `components/DocumentationPage.tsx` head.
128
129In `ui/components/CommandMenu/utils.ts`, you can see the `facetFilters` set to `[['version:none', 'version:{version}']]`. Translated to English, this means - search on all pages where `version` is `none`, or the currently selected version. Here are the rules we use to set this tag:
130
131- all unversioned pages use the version tag `none`,
132- all versioned pages use the SDK version (for example, `v46.0.0` or `v47.0.0`),
133- all pages with `hideFromSearch: true` frontmatter entry don't have the version tag.
134
135Currently, the base results for Expo docs are combined with other results from multiple sources, such as:
136
137- manually defined paths for Expo dashboard located in `ui/components/CommandMenu/expoEntries.ts`,
138- public Algolia index for React Native website,
139- React Native directory public API, see the directory [README.md](https://github.com/react-native-community/directory#i-dont-like-your-website-can-i-hit-an-api-instead-and-build-my-own-better-stuff) for more details.
140
141## Quirks
142
143You can't have curly brace without quotes: \`{}\` -> `{}`.
144
145## Deployment
146
147The docs are deployed automatically via a GitHub Action each time a PR with docs changes is merged to `main`.
148
149## How-tos
150
151### Internal linking
152
153If you need to link from one MDX file to another, please use the static/full path to this file (avoid relative links):
154
155- from: **tutorial/button.mdx**, to: **introduction/expo.mdx** -> `/introduction/expo`
156- from: **index.mdx**, to: **guides/errors.mdx#tracking-js-errors** -> `/guides/errors/#tracking-javascript-errors`
157
158Validate all current links by running `yarn lint-links` script.
159
160### Update latest version of docs
161
162When we release a new SDK, we copy the `unversioned` directory, and rename it to the new version. Latest version of docs is read from **package.json** so make sure to update the `version` key there as well.
163
164Make sure to also grab the upgrade instructions from the release notes blog post and put them in **upgrading-expo-sdk-walkthrough.mdx**.
165
166That's all you need to do. The `versions` directory is listed on server start to find all available versions. The routes and navbar contents are automatically inferred from the directory structure within `versions`.
167
168Because the navbar is automatically generated from the directory structure, the default ordering of the links under each section is alphabetical. However, for many sections, this is not ideal UX.
169So, if you wish to override the alphabetical ordering, manipulate page titles in **constants/navigation.js**.
170
171### Update API reference docs
172
173The API reference docs are generated from the TypeScript source code.
174
175This section walks through the process of updating documentation for an Expo package. Throughout this document, we will assume we want to update TypeDoc definitions of property inside `expo-constants` as an example.
176
177> For more information on how TypeDoc/JSDoc parses comments, see [**Doc comments in TypeDoc documentation**](https://typedoc.org/guides/doccomments/).
178
179#### Prerequisites
180
181Before proceeding, make sure you:
182
183- have [**expo/**](https://github.com/expo/expo) repo cloned on your machine
184 - make sure to [install `direnv`](https://direnv.net/docs/installation.html) and run `direnv allow` at the root of the **expo/** repo.
185- have gone through the steps mentioned in [**"Download and Setup" in the contribution guideline**](https://github.com/expo/expo/blob/main/CONTRIBUTING.md#-download-and-setup).
186- can run **expo/docs** app **[locally](https://github.com/expo/expo/tree/main/docs#running-locally)**.
187- can run [`et` (Expotools)](https://github.com/expo/expo/blob/main/tools/README.md) command locally.
188
189Once you have made sure the development setup is ready, proceed to the next section:
190
191#### Step 1: Update the package’s TypeDoc
192
193- After you have identified which package docs you want to update, open a terminal window and navigate to that package’s directory. For example:
194
195```shell
196# Navigate to expo-constants package directory inside expo/ repo
197cd expo/packages/expo-constants
198```
199
200- Then, open **.ts** file in your code editor/IDE where you want to make changes/updates.
201- Start the TypeScript build compilation in watch mode using `yarn build` in the terminal window.
202- Make the update. For example, we want to update the TypeDoc description of [`expoConfig` property](https://docs.expo.dev/versions/latest/sdk/constants/#nativeconstants)
203
204 - Inside the **src/** directory, open **Constants.types.ts** file.
205 - Search for `expoConfig` property. It has a current description as shown below:
206
207 ```ts
208 /**
209 * The standard Expo confg object defined in `app.json` and `app.config.js` files. For both
210 * classic and modern manifests, whether they are embedded or remote.
211 */
212 expoConfig: ExpoConfig | null;
213 ```
214
215- In the above example, let’s fix the typo by changing `confg` to `config`:
216
217```ts
218/**
219 * The standard app config object defined in `app.json` and `app.config.js` files. For both
220 * classic and modern manifests, whether they are embedded or remote.
221 */
222expoConfig: ExpoConfig | null;
223```
224
225- Before moving to the next step, make sure to exit the "watch mode" by pressing `Ctrl + C` from the keyboard.
226
227#### Step 2: Apply TypeDoc updates to expo/docs repo
228
229In the terminal window and run the following command with to generate the JSON data file for the package (which is stored at the location `expo/docs/public/static/data/[SDK-VERSION]`)
230
231- Read the **NOTE** in the below snippet for updating the docs for `unversioned`:
232
233```shell
234et generate-docs-api-data --packageName expo-constants --sdk 47
235
236#### NOTE ####
237# To update unversioned docs, run the command without mentioning the SDK version
238et gdad -p expo-constants
239
240# For more information about et command, run: et gdad --help
241```
242
243**Why update `unversioned` docs?** If these are new changes/updates, apply them to `unversioned` to make sure that those changes are part of the next SDK version.
244
245#### Step 3: See the changes in the docs repo
246
247Now, in the terminal window, navigate to **expo/docs** repo and run the command `yarn run dev` to see the changes applied
248
249- Open [http://localhost:3002/](http://localhost:3002/) in the browser and go to the API doc to see the changes you have made. Make sure to select the right SDK version to see the changes in the left sidebar.
250
251#### Tips
252
253##### Disable changelog
254
255After making changes, when you are opening the PR, consider adding `<!-- disable:changelog-checks -->` in the PR description if the changes you are making are docs-related changes (such as updating the field description or fixing a typo, and so on).
256
257This will make sure that the ExpoBot on GitHub will not complain about updating the package’s changelog (some of these changes, as described above, are not worth mentioning in the changelog).
258
259##### Use the correct package name
260
261Some of the packages have documentation spread over multiple pages. For example, `expo-av` package has a separate base interface, and some of the information is separated into `Audio` and `Video` components. For such packages, always make sure to check the [name of the package](https://github.com/expo/expo/blob/main/tools/src/commands/GenerateDocsAPIData.ts#L24) for `et` command.
262
263### Sync app.json/app.config.js with the schema
264
265To render the app.json / app.config.js properties table, we currently store a local copy of the appropriate version of the schema.
266
267If the schema is updated, to sync and rewrite our local copy, run `yarn run schema-sync <SDK version integer>` or `yarn run schema-sync unversioned`.
268
269### Add images and assets
270
271You can add images and assets to the **public/static** directory. They'll be served by the production and staging servers at **static**.
272
273#### Add videos
274
275- Record the video using QuickTime
276- Install `ffmpeg` (`brew install ffmpeg`)
277- Run `ffmpeg -i your-video-name.mov -vcodec h264 -acodec mp2 your-video-name.mp4` to convert to mp4.
278- If the width of the video is larger than ~1200px, then run this to shrink it: `ffmpeg -i your-video.mp4 -filter:v scale="1280:trunc(ow/a/2)*2" your-video-smaller.mp4`
279- Put the video in the appropriate location in `public/static/videos` and use it in your docs page MDX like this:
280
281```js
282import Video from '~/components/plugins/Video';
283
284// Change the path to point to the relative path to your video from within the `static/videos` directory
285<Video file="guides/color-schemes.mp4" />;
286```
287
288### Inline Snack examples
289
290Snacks are a great way to add instantly-runnable examples to our docs. The `SnackInline` component can be imported to any markdown file, and used like this:
291
292<!-- prettier-ignore -->
293```jsx
294import SnackInline from '~/components/plugins/SnackInline';
295
296<SnackInline label='My Example Label' dependencies={['array of', 'packages', 'this Snack relies on']}>
297
298// All your JavaScript code goes in here
299
300// You can use:
301/* @info Some text goes here */
302 const myVariable = SomeCodeThatDoesStuff();
303/* @end */
304// to create hoverable-text, which reveals the text inside of `@info` onHover.
305
306// You can use:
307/* @hide Content that is still shown, like a preview. */
308 Everything in here is hidden in the example Snack until
309 you open it in snack.expo.dev
310/* @end */
311// to shorten the length of the Snack shown in our docs. Common example are hiding useless code in examples, like StyleSheets
312
313</SnackInline>
314```
315
316### Embed multiple options of code
317
318Sometimes it's useful to show multiple ways of doing something, for instance, maybe you'd like to have an example using a React class component, and also an example of a functional component.
319The `Tabs` plugin is really useful for this, and this is how you'd use it in a markdown file:
320
321<!-- prettier-ignore -->
322```jsx
323import { Tabs, Tab } from '~/ui/components/Tabs';
324
325<Tabs>
326<Tab label="Add 1 One Way">
327
328 addOne = async x => {
329 /* @info This text will be shown onHover */
330 return x + 1;
331 /* @end */
332 };
333
334</Tab>
335<Tab label="Add 1 Another Way">
336
337 addOne = async x => {
338 /* @info This text will be shown onHover */
339 return x++;
340 /* @end */
341 };
342
343</Tab>
344</Tabs>
345```
346
347**Note:** The components should not be indented or they will not be parsed correctly.
348
349### Exclude pages from DocSearch
350
351To ignore a page from the search result, use `hideFromSearch: true` on that page. This removes the `<meta name="docsearch:version">` tag from that page and filters it from our facet-based search.
352
353Please note that `hideFromSearch` only prevents the page from showing up in the internal docs search (Algolia). The page will still show up in search engine results like Google.
354For a page to be hidden even from search engine results, you need to edit the sitemap that is generated via our Next.js config (**next.config.js**).
355
356### Exclude directories from the sidebar
357
358Certain directories are excluded from the sidebar to prevent it from getting too long and unnavigable. You can find a list of these directories, and add new ones, in **constants/navigation.js** under `hiddenSections`.
359
360If you just want to hide a single page from the sidebar, set `hideInSidebar: true` in the page metadata.
361
362### Use `Terminal` component for shell commands snippets
363
364Whenever shell commands are used or referred, use `Terminal` component to make the code snippets copy/pasteable. This component can be imported into any markdown file.
365
366```jsx
367import { Terminal } from '~/ui/components/Snippet';
368
369// for single command and one prop
370<Terminal cmd={["$ npx expo install package"]} />
371
372// for multiple commands
373
374<Terminal cmd={[
375 "# Create a new native project",
376 "$ npx create-expo-app --template bare-minimum",
377 "",
378 "# If you don’t have expo-cli yet, get it",
379 "$ npm i -g expo-cli",
380 "",
381]} cmdCopy="npx create-expo-app --template bare-minimum && npm i -g expo-cli" />
382```
383
384### Use callouts
385
386Four different types of callouts can be used with markdown syntax for `> ...` blockquote. Each callout represents a purpose.
387
388```md
389> Normal callout that doesn't demand much attention but is required to add as a note.
390
391> **info** Callout that is informative and demands attention is required to add as a note or a tip.
392
393> **warning** Callout that is used for warnings and deprecation messages.
394
395> **error** Callout that is used for errors and breaking changes or deprecated changes in the archive.
396```
397
398### Prettier
399
400Please commit any sizeable diffs that are the result of `prettier` separately to make reviews as easy as possible.
401
402If you have a code block using `/* @info */` highlighting, use `{/* prettier-ignore */}` on the block and take care to preview the block in the browser to ensure that the indentation is correct - the highlighting annotation will sometimes swallow newlines.
403