|
| 1 | +import { |
| 2 | + getAndroidResourceFolderName, |
| 3 | + getAndroidResourceIdentifier, |
| 4 | + getBasePath, |
| 5 | +} from "@react-native/assets-registry/path-support"; |
| 6 | +import { |
| 7 | + AssetDestPathResolver, |
| 8 | + getAssetByID, |
| 9 | + PackagerAsset, |
| 10 | + registerAsset, |
| 11 | +} from "@react-native/assets-registry/registry"; |
| 12 | + |
| 13 | +const asset: PackagerAsset = { |
| 14 | + __packager_asset: true, |
| 15 | + fileSystemLocation: "/assets", |
| 16 | + httpServerLocation: "/assets", |
| 17 | + width: 100, |
| 18 | + height: 100, |
| 19 | + scales: [1, 1.5, 2, 3, 4], |
| 20 | + hash: "abc123", |
| 21 | + name: "logo", |
| 22 | + type: "png", |
| 23 | +}; |
| 24 | + |
| 25 | +const assetWithResolver: PackagerAsset = { |
| 26 | + __packager_asset: true, |
| 27 | + fileSystemLocation: "/assets", |
| 28 | + httpServerLocation: "/assets", |
| 29 | + scales: [1], |
| 30 | + hash: "def456", |
| 31 | + name: "icon", |
| 32 | + type: "png", |
| 33 | + resolver: "android", |
| 34 | +}; |
| 35 | + |
| 36 | +const assetWithNullDimensions: PackagerAsset = { |
| 37 | + __packager_asset: true, |
| 38 | + fileSystemLocation: "/assets", |
| 39 | + httpServerLocation: "/assets", |
| 40 | + width: null, |
| 41 | + height: null, |
| 42 | + scales: [1], |
| 43 | + hash: "ghi789", |
| 44 | + name: "placeholder", |
| 45 | + type: "png", |
| 46 | +}; |
| 47 | + |
| 48 | +// exactOptionalPropertyTypes: explicit undefined is valid |
| 49 | +const assetWithUndefinedDimensions: PackagerAsset = { |
| 50 | + __packager_asset: true, |
| 51 | + fileSystemLocation: "/assets", |
| 52 | + httpServerLocation: "/assets", |
| 53 | + width: undefined, |
| 54 | + height: undefined, |
| 55 | + scales: [1], |
| 56 | + hash: "jkl012", |
| 57 | + name: "empty", |
| 58 | + type: "png", |
| 59 | + resolver: undefined, |
| 60 | +}; |
| 61 | + |
| 62 | +const resolver: AssetDestPathResolver = "generic"; |
| 63 | + |
| 64 | +const id: number = registerAsset(asset); |
| 65 | +const retrieved: PackagerAsset = getAssetByID(id); |
| 66 | + |
| 67 | +const folder: string = getAndroidResourceFolderName(asset, 2); |
| 68 | +const identifier: string = getAndroidResourceIdentifier(asset); |
| 69 | +const basePath: string = getBasePath(asset); |
0 commit comments