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