1# Expo Documentation 2 3This is the public documentation for **Expo**, its SDK, client, and services, like **EAS**. 4 5This documentation is built using Next.js and you can access it online at https://docs.expo.dev/. 6 7> **Note** **Contributors:** Please make sure that you edit the docs in the `pages/versions/unversioned` directory if you want your changes to apply to the next SDK version too! 8 9> **Note** 10> 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). 11 12## Running Locally 13 14Download the copy of this repository. 15 16```sh 17git clone https://github.com/expo/expo.git 18``` 19 20Then `cd` into the `docs` directory and install dependencies with: 21 22```sh 23yarn 24``` 25 26Then you can run the app with (make sure you have no server running on port `3002`): 27 28```sh 29yarn run dev 30``` 31 32Now the documentation is running at http://localhost:3002, and any changes you make to markdown or JavaScript files will automatically trigger reloads. 33 34### To run locally in production mode 35 36```sh 37yarn run export 38yarn run export-server 39``` 40 41## Editing Docs Content 42 43You can find the content source of the documentation inside the `pages/` directory. Documentation is mostly written in markdown with the help of some React components (for Snack embeds, etc). Our API documentation can all be found under `pages/versions/`; we keep separate versions of the documentation for each SDK version currently supported in Expo Go, see ["A note about versioning"](#a-note-about-versioning) for more info. The routes and navbar are automatically inferred from the directory structure within `versions`. 44 45> **Note** 46> We are currently in the process of moving our API documentation to being auto-generated using `expotools`'s `GenerateDocsAPIData` command. 47 48Each markdown page can be provided metadata in the heading, distinguished by: 49 50``` 51--- 52metadata: goes here 53--- 54``` 55 56These metadata items include: 57 58- `title`: Title of the page shown as the heading and in search results. 59- `description`: Description of the page shown in search results and open graph descriptions when the page is shared on social media sites. 60- `hideFromSearch`: Whether to hide the page from Algolia search results. Defaults to `false`. 61- `hideInSidebar`: Whether to hide this page from the sidebar. Defaults to `false`. 62- `hideTOC`: Whether to hide the table of contents (appears on the right sidebar). Defaults to `false`. 63- `sidebar_title`: The title of the page to display in the sidebar. Defaults to the page title. 64- `maxHeadingDepth`: The max level of headings shown in Table of Content on the right side. Defaults to `3`. 65 66### Editing Code 67 68The 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. 69 70```sh 71yarn watch 72``` 73 74When you are done, you should run _prettier_ to format your code. Also, don't forget to run tests and linter before committing your changes. 75 76```sh 77yarn prettier 78yarn test 79yarn lint 80``` 81 82## Redirects 83 84### Server-side redirects 85 86These redirects are limited in their expressiveness - you can map a path to another path, but no regular expressions or anything are supported. See client-side redirects for more of that. Server-side redirects are re-created on each run of **deploy.sh**. 87 88We currently do two client-side redirects, using meta tags with `http-equiv="refresh"`: 89 90- `/` -> `/versions/latest/` 91- `/versions` -> `/versions/latest` 92 93This method is not great for accessibility and should be avoided where possible. 94 95### Client-side redirects 96 97Use 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. 98 99You can add your own client-side redirect rules in `common/error-utilities.ts`. 100 101## Search 102 103We 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 current location. The tag set in the `components/DocumentationPage.tsx` head. 104 105In `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: 106 107- all unversioned pages use the version tag `none`, 108- all versioned pages use the SDK version (e.g. `v46.0.0` or `v47.0.0`), 109- all pages with `hideFromSearch: true` frontmatter entry don't have the version tag. 110 111Currently, the base results for Expo docs are combined with other results from multiple sources, like: 112 113- manually defined paths for Expo dashboard located in `ui/components/CommandMenu/expoEntries.ts`, 114- public Algolia index for React Native website, 115- 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. 116 117## Quirks 118 119- You can't have curly brace without quotes: \`{}\` -> `{}` 120- Make sure to leave an empty newline between a table and following content 121 122## A note about versioning 123 124Expo's SDK is versioned so that apps made on old SDKs are still supported 125when new SDKs are released. The website documents previous SDK versions too. 126 127Version names correspond to directory names under `versions`. 128 129`unversioned` is a special version for the next SDK release. It is not included in production output. Additionally, any versions greater than the package.json `version` number are not included in production output, so that it's possible to generate, test, and make changes to new SDK version docs during the release process. 130 131`latest` is an untracked folder which duplicates the contents of the folder matching the version number in **package.json**. 132 133Sometimes you want to make an edit in version `X` and have that edit also 134be applied in versions `Y, Z, ...` (say, when you're fixing documentation for an 135API call that existed in old versions too). You can use the 136`./scripts/versionpatch.sh` utility to apply your `git diff` in one version in 137other versions. For example, to update the docs in `unversioned` then apply it 138on `v8.0.0` and `v7.0.0`, you'd do the following after editing the docs in 139`unversioned` such that it shows up in `git diff`: 140 141`./scripts/versionpatch.sh unversioned v8.0.0 v7.0.0` 142 143Any changes in your `git diff` outside the `unversioned` directory are ignored 144so don't worry if you have code changes or such elsewhere. 145 146## Deployment 147 148The docs are deployed automatically via a GitHub Action each time a PR with docs changes is merged to `main`. 149 150## How-tos 151 152## Internal linking 153 154If you need to link from one MDX file to another, please use the path-reference to this file including extension. 155This allows us to automatically validate these links and see if the file and/or headers still exists. 156 157- from: `tutorial/button.md`, to: `/workflow/guides/` -> `../workflow/guides.md` 158- from: **index.md**, to: `/guides/errors/#tracking-js-errors` -> `./guides/errors.md#tracking-js-errors` (or without `./`) 159 160You can validate all current links by running `yarn lint-links`. 161 162### Updating latest version of docs 163 164When 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. 165 166Make sure to also grab the upgrade instructions from the release notes blog post and put them in `upgrading-expo-sdk-walkthrough.md`. 167 168That'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`. 169 170Because 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. 171So, if you wish to override the alphabetical ordering, manipulate page titles in **constants/navigation.js**. 172 173### Syncing app.json / app.config.js with the schema 174 175To render the app.json / app.config.js properties table, we currently store a local copy of the appropriate version of the schema. 176 177If the schema is updated, in order to sync and rewrite our local copy, run `yarn run schema-sync <SDK version integer>` or `yarn run schema-sync unversioned`. 178 179### Adding Images and Assets 180 181You can add images and assets to the `public/static` directory. They'll be served by the production and staging servers at `/static`. 182 183#### Adding videos 184 185- Record the video using QuickTime 186- Install `ffmpeg` (`brew install ffmpeg`) 187- Run `ffmpeg -i your-video-name.mov -vcodec h264 -acodec mp2 your-video-name.mp4` to convert to mp4. 188- 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` 189- Put the video in the appropriate location in `public/static/videos` and use it in your docs page MDX like this: 190 191```js 192import Video from '~/components/plugins/Video'; 193 194// Change the path to point to the relative path to your video from within the `static/videos` directory 195<Video file="guides/color-schemes.mp4" />; 196``` 197 198### Inline Snack examples 199 200Snacks 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: 201 202<!-- prettier-ignore --> 203```jsx 204import SnackInline from '~/components/plugins/SnackInline'; 205 206<SnackInline label='My Example Label' dependencies={['array of', 'packages', 'this Snack relies on']}> 207 208// All your JavaScript code goes in here 209 210// You can use: 211/* @info Some text goes here */ 212 const myVariable = SomeCodeThatDoesStuff(); 213/* @end */ 214// to create hoverable-text, which reveals the text inside of `@info` onHover. 215 216// You can use: 217/* @hide Content that is still shown, like a preview. */ 218 Everything in here is hidden in the example Snack until 219 you open it in snack.expo.dev 220/* @end */ 221// to shorten the length of the Snack shown in our docs. Common example are hiding useless code in examples, like StyleSheets 222 223</SnackInline> 224``` 225 226### Embedding multiple options of code 227 228Sometimes 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. 229The `Tabs` plugin is really useful for this, and this is how you'd use it in a markdown file: 230 231<!-- prettier-ignore --> 232```jsx 233import { Tabs, Tab } from '~/ui/components/Tabs'; 234 235<Tabs> 236<Tab label="Add 1 One Way"> 237 238 addOne = async x => { 239 /* @info This text will be shown onHover */ 240 return x + 1; 241 /* @end */ 242 }; 243 244</Tab> 245<Tab label="Add 1 Another Way"> 246 247 addOne = async x => { 248 /* @info This text will be shown onHover */ 249 return x++; 250 /* @end */ 251 }; 252 253</Tab> 254</Tabs> 255``` 256 257n.b. The components should not be indented or they will not be parsed correctly. 258 259### Excluding pages from DocSearch 260 261To 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. 262 263Please 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. 264For 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**). 265 266### Excluding directories from the sidebar 267 268Certain directories are excluded from the sidebar in order 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`. 269 270If you just want to hide a single page from the sidebar, set `hideInSidebar: true` in the page metadata. 271 272### Use `Terminal` component for shell commands snippets 273 274Whenever shell commands are used or referred, use `Terminal` component to make the code snippets copy/pasteable. This component can be imported in any markdown file. 275 276```jsx 277import { Terminal } from '~/ui/components/Snippet'; 278 279// for single command and one prop 280<Terminal cmd={["$ npx expo install package"]} /> 281 282// for multiple commands 283 284<Terminal cmd={[ 285 "# Create a new native project", 286 "$ npx create-expo-app --template bare-minimum", 287 "", 288 "# If you don’t have expo-cli yet, get it", 289 "$ npm i -g expo-cli", 290 "", 291]} cmdCopy="npx create-expo-app --template bare-minimum && npm i -g expo-cli" /> 292``` 293 294### Prettier 295 296Please commit any sizeable diffs that are the result of `prettier` separately to make reviews as easy as possible. 297 298If 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. 299 300## TODOs: 301 302- Handle image sizing in imports better 303- Make Snack embeds work; these are marked in some of the React Native docs but they are just imported as plain JS code blocks 304