|
1 | 1 | # @react-native/assets-registry |
2 | 2 |
|
3 | | -[![Version][version-badge]][package] |
| 3 | + |
4 | 4 |
|
5 | | -## Installation |
| 5 | +Runtime registry that maps asset IDs generated in a Metro bundle to asset metadata. It backs `<Image>`, `Image.resolveAssetSource()`, and any code that resolves `require('./img.png')` on native. |
6 | 6 |
|
7 | | -``` |
8 | | -yarn add --dev @react-native/assets-registry |
9 | | -``` |
| 7 | +Most apps never import this directly — assets are handled through `<Image>`. |
10 | 8 |
|
11 | | -*Note: We're using `yarn` to install deps. Feel free to change commands to use `npm` 3+ and `npx` if you like* |
| 9 | +## API |
12 | 10 |
|
13 | | -[version-badge]: https://img.shields.io/npm/v/@react-native/assets-registry?style=flat-square |
14 | | -[package]: https://www.npmjs.com/package/@react-native/assets-registry |
| 11 | +### `@react-native/assets-registry/registry` |
15 | 12 |
|
16 | | -## Testing |
| 13 | +| Export | Signature | Notes | |
| 14 | +|---|---|---| |
| 15 | +| `registerAsset` | `(asset: PackagerAsset) => number` | Stores the asset; returns a numeric ID | |
| 16 | +| `getAssetByID` | `(assetId: number) => PackagerAsset` | Looks an asset back up by ID | |
17 | 17 |
|
18 | | -To run the tests in this package, run the following commands from the React Native root folder: |
| 18 | +### `@react-native/assets-registry/path-support` |
19 | 19 |
|
20 | | -1. `yarn` to install the dependencies. You just need to run this once |
21 | | -2. `yarn jest packages/assets-registry`. |
| 20 | +Android resource-path helpers, used when copying assets into `drawable-*` folders. |
| 21 | + |
| 22 | +| Export | Signature | Notes | |
| 23 | +|---|---|---| |
| 24 | +| `getAndroidResourceFolderName` | `(asset: PackagerAsset, scale: number) => string` | e.g. `drawable-xhdpi`; non-drawable types resolve to `raw` | |
| 25 | +| `getAndroidResourceIdentifier` | `(asset: PackagerAsset) => string` | Sanitised resource name | |
| 26 | +| `getBasePath` | `(asset: PackagerAsset) => string` | `httpServerLocation` without the leading slash | |
0 commit comments