-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
@react-native/assets
package for Asset Registry related code
Summary: Changelog: [Internal] Reviewed By: GijsWeterings Differential Revision: D22628865 fbshipit-source-id: 66ff311b2dab4e0c42f906d5a2642997b1570ae4
- Loading branch information
1 parent
91d16bb
commit 63377fa
Showing
12 changed files
with
107 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/__mocks__/** | ||
**/__tests__/** | ||
BUCK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
load("@fbsource//tools/build_defs:js_glob.bzl", "js_glob") | ||
load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace") | ||
load("@fbsource//xplat/js:JS_DEFS.bzl", "rn_library") | ||
|
||
rn_library( | ||
name = "assets", | ||
srcs = js_glob([ | ||
"**/*", | ||
"package.json", | ||
]), | ||
labels = ["supermodule:xplat/default/public.react_native.core"], | ||
skip_processors = True, | ||
visibility = ["PUBLIC"], | ||
worker = "//xplat/js:experimental-packager", | ||
) | ||
|
||
yarn_workspace( | ||
name = "yarn-workspace", | ||
srcs = glob( | ||
[ | ||
"**/*.js", | ||
"**/*.json", | ||
], | ||
exclude = [ | ||
"**/__fixtures__/**", | ||
"**/__flowtests__/**", | ||
"**/__mocks__/**", | ||
"**/__tests__/**", | ||
"**/node_modules/**", | ||
"**/node_modules/.bin/**", | ||
], | ||
), | ||
visibility = ["PUBLIC"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@react-native/assets", | ||
"version": "1.0.0", | ||
"description": "Asset support code for React Native.", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:facebook/react-native.git" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
export type PackagerAsset = { | ||
+__packager_asset: boolean, | ||
+fileSystemLocation: string, | ||
+httpServerLocation: string, | ||
+width: ?number, | ||
+height: ?number, | ||
+scales: Array<number>, | ||
+hash: string, | ||
+name: string, | ||
+type: string, | ||
... | ||
}; | ||
|
||
const assets: Array<PackagerAsset> = []; | ||
|
||
function registerAsset(asset: PackagerAsset): number { | ||
// `push` returns new array length, so the first asset will | ||
// get id 1 (not 0) to make the value truthy | ||
return assets.push(asset); | ||
} | ||
|
||
function getAssetByID(assetId: number): PackagerAsset { | ||
return assets[assetId - 1]; | ||
} | ||
|
||
module.exports = {registerAsset, getAssetByID}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters