expo-asset 11.1.1 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/android/build.gradle +9 -2
- package/android/src/main/java/expo/modules/asset/AssetModule.kt +2 -1
- package/android/src/main/java/expo/modules/asset/ResourceAsset.kt +39 -2
- package/build/Asset.d.ts +5 -0
- package/build/Asset.d.ts.map +1 -1
- package/build/Asset.fx.js +9 -5
- package/build/Asset.fx.js.map +1 -1
- package/build/Asset.js +11 -1
- package/build/Asset.js.map +1 -1
- package/build/Asset.server.d.ts.map +1 -1
- package/build/Asset.server.js.map +1 -1
- package/build/AssetSourceResolver.d.ts +2 -1
- package/build/AssetSourceResolver.d.ts.map +1 -1
- package/build/AssetSourceResolver.js +1 -0
- package/build/AssetSourceResolver.js.map +1 -1
- package/build/AssetSources.js +1 -1
- package/build/AssetSources.js.map +1 -1
- package/build/resolveAssetSource.d.ts +7 -1
- package/build/resolveAssetSource.d.ts.map +1 -1
- package/build/resolveAssetSource.js +2 -1
- package/build/resolveAssetSource.js.map +1 -1
- package/expo-module.config.json +1 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2-sources.jar +0 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2-sources.jar.md5 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2-sources.jar.sha1 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2-sources.jar.sha256 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2-sources.jar.sha512 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.aar +0 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.aar.md5 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.aar.sha1 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.aar.sha256 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.aar.sha512 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.module +87 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.module.md5 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.module.sha1 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.module.sha256 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.module.sha512 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/{11.1.1/expo.modules.asset-11.1.1.pom → 11.1.2/expo.modules.asset-11.1.2.pom} +1 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.pom.md5 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.pom.sha1 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.pom.sha256 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.pom.sha512 +1 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/maven-metadata.xml +4 -4
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/maven-metadata.xml.md5 +1 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/maven-metadata.xml.sha1 +1 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/maven-metadata.xml.sha256 +1 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/maven-metadata.xml.sha512 +1 -1
- package/package.json +7 -5
- package/src/Asset.fx.ts +12 -3
- package/src/Asset.server.ts +2 -2
- package/src/Asset.ts +14 -4
- package/src/AssetSourceResolver.ts +5 -2
- package/src/AssetSources.ts +1 -1
- package/src/resolveAssetSource.ts +10 -1
- package/src/ts-declarations/react-native-assets.d.ts +16 -2
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1-sources.jar +0 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1-sources.jar.md5 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1-sources.jar.sha1 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1-sources.jar.sha256 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1-sources.jar.sha512 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.aar +0 -0
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.aar.md5 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.aar.sha1 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.aar.sha256 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.aar.sha512 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.module +0 -87
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.module.md5 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.module.sha1 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.module.sha256 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.module.sha512 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.pom.md5 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.pom.sha1 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.pom.sha256 +0 -1
- package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.pom.sha512 +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 11.1.2 — 2025-04-14
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- Added `file:///android_res/` format support. ([#36058](https://github.com/expo/expo/pull/36058) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
13
19
|
## 11.1.1 — 2025-04-09
|
|
14
20
|
|
|
15
21
|
_This version does not introduce any user-facing changes._
|
package/android/build.gradle
CHANGED
|
@@ -4,12 +4,19 @@ plugins {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
group = 'expo.modules.asset'
|
|
7
|
-
version = '11.1.
|
|
7
|
+
version = '11.1.2'
|
|
8
8
|
|
|
9
9
|
android {
|
|
10
10
|
namespace "expo.modules.asset"
|
|
11
11
|
defaultConfig {
|
|
12
12
|
versionCode 1
|
|
13
|
-
versionName "11.1.
|
|
13
|
+
versionName "11.1.2"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
dependencies {
|
|
18
|
+
testImplementation 'androidx.test:core:1.6.1'
|
|
19
|
+
testImplementation 'io.mockk:mockk:1.13.11'
|
|
20
|
+
testImplementation 'junit:junit:4.13.2'
|
|
21
|
+
testImplementation 'org.robolectric:robolectric:4.14.1'
|
|
22
|
+
}
|
|
@@ -57,6 +57,7 @@ class AssetModule : Module() {
|
|
|
57
57
|
try {
|
|
58
58
|
val inputStream = when {
|
|
59
59
|
uri.toString().contains(":").not() -> openAssetResourceStream(context, uri.toString())
|
|
60
|
+
uri.toString().startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE) -> openAndroidResStream(context, uri.toString())
|
|
60
61
|
else -> uri.toURL().openStream()
|
|
61
62
|
}
|
|
62
63
|
inputStream.use { input ->
|
|
@@ -75,7 +76,7 @@ class AssetModule : Module() {
|
|
|
75
76
|
Name("ExpoAsset")
|
|
76
77
|
|
|
77
78
|
AsyncFunction("downloadAsync") Coroutine { uri: URI, md5Hash: String?, type: String ->
|
|
78
|
-
if (uri.scheme === "file") {
|
|
79
|
+
if (uri.scheme === "file" && !uri.toString().startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {
|
|
79
80
|
return@Coroutine uri
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -3,15 +3,27 @@ package expo.modules.asset
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.content.res.Resources
|
|
6
|
+
import androidx.core.net.toUri
|
|
7
|
+
import expo.modules.core.errors.InvalidArgumentException
|
|
6
8
|
import java.io.InputStream
|
|
7
9
|
|
|
10
|
+
internal const val ANDROID_EMBEDDED_URL_BASE_RESOURCE = "file:///android_res/"
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Opens an Android resource as stream.
|
|
10
14
|
*/
|
|
11
15
|
internal fun openAssetResourceStream(context: Context, assetName: String): InputStream {
|
|
12
|
-
val resources = context.resources
|
|
13
16
|
val resId = findResourceId(context, assetName) ?: throw Resources.NotFoundException(assetName)
|
|
14
|
-
return resources.openRawResource(resId)
|
|
17
|
+
return context.resources.openRawResource(resId)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Opens an Android resource as stream for `file:///android_res/` format
|
|
22
|
+
*/
|
|
23
|
+
internal fun openAndroidResStream(context: Context, resourceFilePath: String): InputStream {
|
|
24
|
+
val resId = findResourceIdForAndroidResPath(context, resourceFilePath)
|
|
25
|
+
?: throw Resources.NotFoundException(resourceFilePath)
|
|
26
|
+
return context.resources.openRawResource(resId)
|
|
15
27
|
}
|
|
16
28
|
|
|
17
29
|
@SuppressLint("DiscouragedApi")
|
|
@@ -22,3 +34,28 @@ private fun findResourceId(context: Context, assetName: String): Int? {
|
|
|
22
34
|
return resources.getIdentifier(assetName, "raw", packageName).takeIf { it != 0 }
|
|
23
35
|
?: resources.getIdentifier(assetName, "drawable", packageName).takeIf { it != 0 }
|
|
24
36
|
}
|
|
37
|
+
|
|
38
|
+
@SuppressLint("DiscouragedApi")
|
|
39
|
+
private fun findResourceIdForAndroidResPath(context: Context, resourceFilePath: String): Int? {
|
|
40
|
+
if (!resourceFilePath.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {
|
|
41
|
+
throw InvalidArgumentException("Invalid resource file path: $resourceFilePath")
|
|
42
|
+
}
|
|
43
|
+
val uri = resourceFilePath.toUri()
|
|
44
|
+
val pathSegments = uri.pathSegments
|
|
45
|
+
if (pathSegments.size < 3) {
|
|
46
|
+
throw InvalidArgumentException("Invalid resource file path: $resourceFilePath")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Strip any qualifiers after a dash, for example "drawable-xhdpi" becomes "drawable"
|
|
50
|
+
val resourceDirectory = pathSegments[1].substringBefore('-')
|
|
51
|
+
|
|
52
|
+
// Strip file extension for resource name
|
|
53
|
+
val resourceFilename = pathSegments[2]
|
|
54
|
+
val resourceName = resourceFilename.substringBeforeLast('.', resourceFilename)
|
|
55
|
+
|
|
56
|
+
return context.resources.getIdentifier(
|
|
57
|
+
resourceName,
|
|
58
|
+
resourceDirectory,
|
|
59
|
+
context.packageName
|
|
60
|
+
).takeIf { it != 0 }
|
|
61
|
+
}
|
package/build/Asset.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export type AssetDescriptor = {
|
|
|
8
8
|
height?: number | null;
|
|
9
9
|
};
|
|
10
10
|
export { AssetMetadata };
|
|
11
|
+
/**
|
|
12
|
+
* Android resource URL prefix.
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
15
|
+
export declare const ANDROID_EMBEDDED_URL_BASE_RESOURCE = "file:///android_res/";
|
|
11
16
|
/**
|
|
12
17
|
* The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
|
|
13
18
|
* name and type) and provides facilities to load the asset data.
|
package/build/Asset.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.d.ts","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAqB,MAAM,gBAAgB,CAAC;AASlE,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAOF,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB;;;GAGG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"Asset.d.ts","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAqB,MAAM,gBAAgB,CAAC;AASlE,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,I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,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GACnF,KAAK;IAwDR,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,KAAK;IAsB/C,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IA2BlC;;;;;;;OAOG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAoCrC"}
|
package/build/Asset.fx.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { Asset } from './Asset';
|
|
1
|
+
import { Asset, ANDROID_EMBEDDED_URL_BASE_RESOURCE } from './Asset';
|
|
2
2
|
import { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';
|
|
3
3
|
import resolveAssetSource, { setCustomSourceTransformer } from './resolveAssetSource';
|
|
4
4
|
// Override React Native's asset resolution for `Image` components in contexts where it matters
|
|
5
5
|
if (IS_ENV_WITH_LOCAL_ASSETS) {
|
|
6
|
-
const setTransformer =
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
resolveAssetSource.setCustomSourceTransformer || setCustomSourceTransformer;
|
|
6
|
+
const setTransformer = resolveAssetSource.setCustomSourceTransformer || setCustomSourceTransformer;
|
|
9
7
|
setTransformer((resolver) => {
|
|
10
8
|
try {
|
|
11
9
|
// Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists
|
|
12
|
-
if (resolver.asset.fileHashes) {
|
|
10
|
+
if ('fileHashes' in resolver.asset && resolver.asset.fileHashes) {
|
|
13
11
|
const asset = Asset.fromMetadata(resolver.asset);
|
|
12
|
+
if (asset.uri.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {
|
|
13
|
+
// TODO(@kitten): See https://github.com/expo/expo/commit/ec940b57a87d99ab4f1d06d87126e662c3f04f04#r155340943
|
|
14
|
+
// It's unclear whether this is sound since this may be our own AssetSourceResolver, which doesn't have this method
|
|
15
|
+
// Please compare `AssetSourceResolver` type from `react-native/Libraries/Image/AssetSourceResolver` against `./AssetSourceResolver`
|
|
16
|
+
return resolver.resourceIdentifierWithoutScale();
|
|
17
|
+
}
|
|
14
18
|
return resolver.fromSource(asset.downloaded ? asset.localUri : asset.uri);
|
|
15
19
|
}
|
|
16
20
|
else {
|
package/build/Asset.fx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.fx.js","sourceRoot":"","sources":["../src/Asset.fx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Asset.fx.js","sourceRoot":"","sources":["../src/Asset.fx.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,kCAAkC,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,kBAAkB,EAAE,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEtF,+FAA+F;AAC/F,IAAI,wBAAwB,EAAE,CAAC;IAC7B,MAAM,cAAc,GAClB,kBAAkB,CAAC,0BAA0B,IAAI,0BAA0B,CAAC;IAC9E,cAAc,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC1B,IAAI,CAAC;YACH,2FAA2F;YAC3F,IAAI,YAAY,IAAI,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;gBAChE,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACjD,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,kCAAkC,CAAC,EAAE,CAAC;oBAC7D,6GAA6G;oBAC7G,mHAAmH;oBACnH,oIAAoI;oBACpI,OACE,QACD,CAAC,8BAA8B,EAAS,CAAC;gBAC5C,CAAC;gBACD,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7E,CAAC;iBAAM,CAAC;gBACN,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;YACjC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { default as AssetSourceResolver } from 'react-native/Libraries/Image/AssetSourceResolver';\n\nimport { Asset, ANDROID_EMBEDDED_URL_BASE_RESOURCE } from './Asset';\nimport { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';\nimport resolveAssetSource, { setCustomSourceTransformer } from './resolveAssetSource';\n\n// Override React Native's asset resolution for `Image` components in contexts where it matters\nif (IS_ENV_WITH_LOCAL_ASSETS) {\n const setTransformer =\n resolveAssetSource.setCustomSourceTransformer || setCustomSourceTransformer;\n setTransformer((resolver) => {\n try {\n // Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists\n if ('fileHashes' in resolver.asset && resolver.asset.fileHashes) {\n const asset = Asset.fromMetadata(resolver.asset);\n if (asset.uri.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {\n // TODO(@kitten): See https://github.com/expo/expo/commit/ec940b57a87d99ab4f1d06d87126e662c3f04f04#r155340943\n // It's unclear whether this is sound since this may be our own AssetSourceResolver, which doesn't have this method\n // Please compare `AssetSourceResolver` type from `react-native/Libraries/Image/AssetSourceResolver` against `./AssetSourceResolver`\n return (\n resolver as unknown as AssetSourceResolver\n ).resourceIdentifierWithoutScale() as any;\n }\n return resolver.fromSource(asset.downloaded ? asset.localUri! : asset.uri);\n } else {\n return resolver.defaultAsset();\n }\n } catch {\n return resolver.defaultAsset();\n }\n });\n}\n"]}
|
package/build/Asset.js
CHANGED
|
@@ -7,6 +7,11 @@ import * as ImageAssets from './ImageAssets';
|
|
|
7
7
|
import { getLocalAssetUri } from './LocalAssets';
|
|
8
8
|
import { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';
|
|
9
9
|
import resolveAssetSource from './resolveAssetSource';
|
|
10
|
+
/**
|
|
11
|
+
* Android resource URL prefix.
|
|
12
|
+
* @hidden
|
|
13
|
+
*/
|
|
14
|
+
export const ANDROID_EMBEDDED_URL_BASE_RESOURCE = 'file:///android_res/';
|
|
10
15
|
/**
|
|
11
16
|
* The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
|
|
12
17
|
* name and type) and provides facilities to load the asset data.
|
|
@@ -69,7 +74,12 @@ export class Asset {
|
|
|
69
74
|
}
|
|
70
75
|
if (hash) {
|
|
71
76
|
this.localUri = getLocalAssetUri(hash, type);
|
|
72
|
-
if (this.localUri) {
|
|
77
|
+
if (this.localUri?.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {
|
|
78
|
+
// Treat Android embedded resources as not downloaded state, because the uri is not direct accessible.
|
|
79
|
+
this.uri = this.localUri;
|
|
80
|
+
this.localUri = null;
|
|
81
|
+
}
|
|
82
|
+
else if (this.localUri) {
|
|
73
83
|
this.downloaded = true;
|
|
74
84
|
}
|
|
75
85
|
}
|
package/build/Asset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.js","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAiB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,kBAAkB,MAAM,sBAAsB,C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IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC9C,CAAC;YACH,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAEpE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,CAAC;QACV,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { getAssetByID } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\n\nimport { AssetMetadata, selectAssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport { downloadAsync } from './ExpoAsset';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\n// @docsMissing\nexport type AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport { AssetMetadata };\n\n/**\n * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its\n * name and type) and provides facilities to load the asset data.\n */\nexport class Asset {\n private static byHash = {};\n private static byUri = {};\n\n /**\n * The name of the asset file without the extension. Also without the part from `@` onward in the\n * filename (used to specify scale factor for images).\n */\n public name: string;\n /**\n * The extension of the asset filename.\n */\n public readonly type: string;\n /**\n * The MD5 hash of the asset's data.\n */\n public readonly hash: string | null = null;\n /**\n * A URI that points to the asset's data on the remote server. When running the published version\n * of your app, this refers to the location on Expo's asset server where Expo has stored your\n * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's\n * server running on your computer and the asset is served directly from your computer. If you\n * are not using Classic Updates (legacy), this field should be ignored as we ensure your assets\n * are on device before running your application logic.\n */\n public readonly uri: string;\n /**\n * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the\n * `file://` URI pointing to the local file on the device that contains the asset data.\n */\n public localUri: string | null = null;\n /**\n * If the asset is an image, the width of the image data divided by the scale factor. The scale\n * factor is the number after `@` in the filename, or `1` if not present.\n */\n public width: number | null = null;\n /**\n * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.\n */\n public height: number | null = null;\n\n private downloading: boolean = false;\n\n /**\n * Whether the asset has finished downloading from a call to [`downloadAsync()`](#downloadasync).\n */\n public downloaded: boolean = false;\n\n private _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n // @needsAudit\n /**\n * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.\n * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be\n * just one module or URL without an Array.\n * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been\n * saved to disk.\n * @example\n * ```ts\n * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));\n * ```\n */\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n // @needsAudit\n /**\n * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.\n * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external\n * network URL\n * @return The [`Asset`](#asset) instance for the asset.\n */\n static fromModule(\n virtualAssetModule: number | string | { uri: string; width: number; height: number }\n ): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n if (\n typeof virtualAssetModule === 'object' &&\n 'uri' in virtualAssetModule &&\n typeof virtualAssetModule.uri === 'string'\n ) {\n const extension = AssetUris.getFileExtension(virtualAssetModule.uri);\n return new Asset({\n name: '',\n type: extension.startsWith('.') ? extension.substring(1) : extension,\n hash: null,\n uri: virtualAssetModule.uri,\n width: virtualAssetModule.width,\n height: virtualAssetModule.height,\n });\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_LOCAL_ASSETS) {\n // null-check is performed above with `getAssetByID`.\n const { uri } = resolveAssetSource(virtualAssetModule)!;\n\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // For images backward compatibility,\n // keeps localUri the same as uri for React Native's Image that\n // works fine with drawable resource names.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n // @docsMissing\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n // @docsMissing\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n // @needsAudit\n /**\n * Downloads the asset data to a local file in the device's cache directory. Once the returned\n * promise is fulfilled without error, the [`localUri`](#localuri) field of this asset points\n * to a local file containing the asset data. The asset is only downloaded if an up-to-date local\n * file for the asset isn't already present due to an earlier download. The downloaded `Asset`\n * will be returned when the promise is resolved.\n * @return Returns a Promise which fulfills with an `Asset` instance.\n */\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Asset.js","sourceRoot":"","sources":["../src/Asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAiB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAmBtD;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,sBAAsB,CAAC;AAEzE;;;GAGG;AACH,MAAM,OAAO,KAAK;IACR,MAAM,CAAC,MAAM,GAAsC,EAAE,CAAC;IACtD,MAAM,CAAC,KAAK,GAAsC,EAAE,CAAC;IAE7D;;;OAGG;IACI,IAAI,CAAS;IACpB;;OAEG;IACa,IAAI,CAAS;IAC7B;;OAEG;IACa,IAAI,GAAkB,IAAI,CAAC;IAC3C;;;;;;;OAOG;IACa,GAAG,CAAS;IAC5B;;;OAGG;IACI,QAAQ,GAAkB,IAAI,CAAC;IACtC;;;OAGG;IACI,KAAK,GAAkB,IAAI,CAAC;IACnC;;OAEG;IACI,MAAM,GAAkB,IAAI,CAAC;IAE5B,WAAW,GAAY,KAAK,CAAC;IAErC;;OAEG;IACI,UAAU,GAAY,KAAK,CAAC;IAE3B,kBAAkB,GAA+B,EAAE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AC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,CAAC;QACV,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import { getAssetByID } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\n\nimport { AssetMetadata, selectAssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport { downloadAsync } from './ExpoAsset';\nimport * as ImageAssets from './ImageAssets';\nimport { getLocalAssetUri } from './LocalAssets';\nimport { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';\nimport resolveAssetSource from './resolveAssetSource';\n\n// @docsMissing\nexport type AssetDescriptor = {\n name: string;\n type: string;\n hash?: string | null;\n uri: string;\n width?: number | null;\n height?: number | null;\n};\n\ntype DownloadPromiseCallbacks = {\n resolve: () => void;\n reject: (error: Error) => void;\n};\n\nexport { AssetMetadata };\n\n/**\n * Android resource URL prefix.\n * @hidden\n */\nexport const ANDROID_EMBEDDED_URL_BASE_RESOURCE = 'file:///android_res/';\n\n/**\n * The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its\n * name and type) and provides facilities to load the asset data.\n */\nexport class Asset {\n private static byHash: Record<string, Asset | undefined> = {};\n private static byUri: Record<string, Asset | undefined> = {};\n\n /**\n * The name of the asset file without the extension. Also without the part from `@` onward in the\n * filename (used to specify scale factor for images).\n */\n public name: string;\n /**\n * The extension of the asset filename.\n */\n public readonly type: string;\n /**\n * The MD5 hash of the asset's data.\n */\n public readonly hash: string | null = null;\n /**\n * A URI that points to the asset's data on the remote server. When running the published version\n * of your app, this refers to the location on Expo's asset server where Expo has stored your\n * asset. When running the app from Expo CLI during development, this URI points to Expo CLI's\n * server running on your computer and the asset is served directly from your computer. If you\n * are not using Classic Updates (legacy), this field should be ignored as we ensure your assets\n * are on device before running your application logic.\n */\n public readonly uri: string;\n /**\n * If the asset has been downloaded (by calling [`downloadAsync()`](#downloadasync)), the\n * `file://` URI pointing to the local file on the device that contains the asset data.\n */\n public localUri: string | null = null;\n /**\n * If the asset is an image, the width of the image data divided by the scale factor. The scale\n * factor is the number after `@` in the filename, or `1` if not present.\n */\n public width: number | null = null;\n /**\n * If the asset is an image, the height of the image data divided by the scale factor. The scale factor is the number after `@` in the filename, or `1` if not present.\n */\n public height: number | null = null;\n\n private downloading: boolean = false;\n\n /**\n * Whether the asset has finished downloading from a call to [`downloadAsync()`](#downloadasync).\n */\n public downloaded: boolean = false;\n\n private _downloadCallbacks: DownloadPromiseCallbacks[] = [];\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n if (hash) {\n this.localUri = getLocalAssetUri(hash, type);\n if (this.localUri?.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {\n // Treat Android embedded resources as not downloaded state, because the uri is not direct accessible.\n this.uri = this.localUri;\n this.localUri = null;\n } else if (this.localUri) {\n this.downloaded = true;\n }\n }\n\n if (Platform.OS === 'web') {\n if (!name) {\n this.name = AssetUris.getFilename(uri);\n }\n if (!type) {\n this.type = AssetUris.getFileExtension(uri);\n }\n }\n }\n\n // @needsAudit\n /**\n * A helper that wraps `Asset.fromModule(module).downloadAsync` for convenience.\n * @param moduleId An array of `require('path/to/file')` or external network URLs. Can also be\n * just one module or URL without an Array.\n * @return Returns a Promise that fulfills with an array of `Asset`s when the asset(s) has been\n * saved to disk.\n * @example\n * ```ts\n * const [{ localUri }] = await Asset.loadAsync(require('./assets/snack-icon.png'));\n * ```\n */\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n // @needsAudit\n /**\n * Returns the [`Asset`](#asset) instance representing an asset given its module or URL.\n * @param virtualAssetModule The value of `require('path/to/file')` for the asset or external\n * network URL\n * @return The [`Asset`](#asset) instance for the asset.\n */\n static fromModule(\n virtualAssetModule: number | string | { uri: string; width: number; height: number }\n ): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n }\n if (\n typeof virtualAssetModule === 'object' &&\n 'uri' in virtualAssetModule &&\n typeof virtualAssetModule.uri === 'string'\n ) {\n const extension = AssetUris.getFileExtension(virtualAssetModule.uri);\n return new Asset({\n name: '',\n type: extension.startsWith('.') ? extension.substring(1) : extension,\n hash: null,\n uri: virtualAssetModule.uri,\n width: virtualAssetModule.width,\n height: virtualAssetModule.height,\n });\n }\n\n const meta = getAssetByID(virtualAssetModule);\n if (!meta) {\n throw new Error(`Module \"${virtualAssetModule}\" is missing from the asset registry`);\n }\n\n // Outside of the managed env we need the moduleId to initialize the asset\n // because resolveAssetSource depends on it\n if (!IS_ENV_WITH_LOCAL_ASSETS) {\n // null-check is performed above with `getAssetByID`.\n const { uri } = resolveAssetSource(virtualAssetModule)!;\n\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash: meta.hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n\n // For images backward compatibility,\n // keeps localUri the same as uri for React Native's Image that\n // works fine with drawable resource names.\n if (Platform.OS === 'android' && !uri.includes(':') && (meta.width || meta.height)) {\n asset.localUri = asset.uri;\n asset.downloaded = true;\n }\n\n Asset.byHash[meta.hash] = asset;\n return asset;\n }\n\n return Asset.fromMetadata(meta);\n }\n\n // @docsMissing\n static fromMetadata(meta: AssetMetadata): Asset {\n // The hash of the whole asset, not to be confused with the hash of a specific file returned\n // from `selectAssetSource`\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n // @docsMissing\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n // @needsAudit\n /**\n * Downloads the asset data to a local file in the device's cache directory. Once the returned\n * promise is fulfilled without error, the [`localUri`](#localuri) field of this asset points\n * to a local file containing the asset data. The asset is only downloaded if an up-to-date local\n * file for the asset isn't already present due to an earlier download. The downloaded `Asset`\n * will be returned when the promise is resolved.\n * @return Returns a Promise which fulfills with an `Asset` instance.\n */\n async downloadAsync(): Promise<this> {\n if (this.downloaded) {\n return this;\n }\n if (this.downloading) {\n await new Promise<void>((resolve, reject) => {\n this._downloadCallbacks.push({ resolve, reject });\n });\n return this;\n }\n this.downloading = true;\n\n try {\n if (Platform.OS === 'web') {\n if (ImageAssets.isImageType(this.type)) {\n const { width, height, name } = await ImageAssets.getImageInfoAsync(this.uri);\n this.width = width;\n this.height = height;\n this.name = name;\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n }\n this.localUri = await downloadAsync(this.uri, this.hash, this.type);\n\n this.downloaded = true;\n this._downloadCallbacks.forEach(({ resolve }) => resolve());\n } catch (e: any) {\n this._downloadCallbacks.forEach(({ reject }) => reject(e));\n throw e;\n } finally {\n this.downloading = false;\n this._downloadCallbacks = [];\n }\n return this;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asset.server.d.ts","sourceRoot":"","sources":["../src/Asset.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAC;AAIjE,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"Asset.server.d.ts","sourceRoot":"","sources":["../src/Asset.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAC;AAIjE,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAyC;IAC9D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAyC;IAEtD,IAAI,EAAE,MAAM,CAAC;IACpB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC3C,SAAgB,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC7B,UAAU,EAAE,OAAO,CAAQ;gBAEtB,EAAE,IAAI,EAAE,IAAI,EAAE,IAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,eAAe;IA2B5E,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IA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GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,GAAG,aAAa,EAAE,CAAC;IAC/E,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QACjC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,OAAQ;QAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC;IAEH,iGAAiG;IACjG,kDAAkD;IAClD,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;QAC5D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACvB,CAAC;IAED,gGAAgG;IAChG,+FAA+F;IAC/F,kGAAkG;IAClG,4BAA4B;IAC5B,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import type { AssetDescriptor } from './Asset';\nimport type { AssetMetadata, AssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport * as ImageAssets from './ImageAssets';\n\nexport class Asset {\n private static byHash = {};\n private static byUri = {};\n\n public name: string;\n public readonly type: string;\n public readonly hash: string | null = null;\n public readonly uri: string;\n public localUri: string | null = null;\n public width: number | null = null;\n public height: number | null = null;\n public downloaded: boolean = true;\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n this.name ??= AssetUris.getFilename(uri);\n this.type ??= AssetUris.getFileExtension(uri);\n\n // Essentially run the contents of downloadAsync here.\n if (ImageAssets.isImageType(this.type)) {\n this.width = 0;\n this.height = 0;\n this.name = AssetUris.getFilename(this.uri);\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n this.localUri = this.uri;\n }\n\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n static fromModule(\n virtualAssetModule: number | string | { uri: string; width: number; height: number }\n ): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n } else if (typeof virtualAssetModule === 'number') {\n throw new Error(\n 'Cannot resolve numeric asset IDs on the server as they are non-deterministic identifiers.'\n );\n }\n if (\n typeof virtualAssetModule === 'object' &&\n 'uri' in virtualAssetModule &&\n typeof virtualAssetModule.uri === 'string'\n ) {\n const extension = AssetUris.getFileExtension(virtualAssetModule.uri);\n return new Asset({\n name: '',\n type: extension.startsWith('.') ? extension.substring(1) : extension,\n hash: null,\n uri: virtualAssetModule.uri,\n width: virtualAssetModule.width,\n height: virtualAssetModule.height,\n });\n }\n throw new Error('Unexpected asset module ID type: ' + typeof virtualAssetModule);\n }\n\n static fromMetadata(meta: AssetMetadata): Asset {\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n async downloadAsync(): Promise<this> {\n return this;\n }\n}\n\nfunction pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n}\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nfunction selectAssetSource(meta: AssetMetadata): AssetSource {\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = pickScale(meta.scales, 1);\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? (meta.fileHashes[index] ?? meta.fileHashes[0]) : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? (meta.fileUris[index] ?? meta.fileUris[0]) : meta.uri;\n if (uri) {\n return { uri, hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;\n const params = new URLSearchParams({\n platform: process.env.EXPO_OS!,\n hash: meta.hash,\n });\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix + '?' + params;\n return { uri, hash };\n }\n\n // In correctly configured apps, we arrive here if the asset is locally available on disk due to\n // being managed by expo-updates, and `getLocalAssetUri(hash)` must return a local URI for this\n // hash. Since the asset is local, we don't have a remote URL and specify an invalid URL (an empty\n // string) as a placeholder.\n return { uri: '', hash };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Asset.server.js","sourceRoot":"","sources":["../src/Asset.server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAE7C,MAAM,OAAO,KAAK;IACR,MAAM,CAAC,MAAM,GAAsC,EAAE,C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AE,CAAC;AAC3B,CAAC","sourcesContent":["import type { AssetDescriptor } from './Asset';\nimport type { AssetMetadata, AssetSource } from './AssetSources';\nimport * as AssetUris from './AssetUris';\nimport * as ImageAssets from './ImageAssets';\n\nexport class Asset {\n private static byHash: Record<string, Asset | undefined> = {};\n private static byUri: Record<string, Asset | undefined> = {};\n\n public name: string;\n public readonly type: string;\n public readonly hash: string | null = null;\n public readonly uri: string;\n public localUri: string | null = null;\n public width: number | null = null;\n public height: number | null = null;\n public downloaded: boolean = true;\n\n constructor({ name, type, hash = null, uri, width, height }: AssetDescriptor) {\n this.name = name;\n this.type = type;\n this.hash = hash;\n this.uri = uri;\n\n if (typeof width === 'number') {\n this.width = width;\n }\n if (typeof height === 'number') {\n this.height = height;\n }\n\n this.name ??= AssetUris.getFilename(uri);\n this.type ??= AssetUris.getFileExtension(uri);\n\n // Essentially run the contents of downloadAsync here.\n if (ImageAssets.isImageType(this.type)) {\n this.width = 0;\n this.height = 0;\n this.name = AssetUris.getFilename(this.uri);\n } else {\n this.name = AssetUris.getFilename(this.uri);\n }\n this.localUri = this.uri;\n }\n\n static loadAsync(moduleId: number | number[] | string | string[]): Promise<Asset[]> {\n const moduleIds = Array.isArray(moduleId) ? moduleId : [moduleId];\n return Promise.all(moduleIds.map((moduleId) => Asset.fromModule(moduleId).downloadAsync()));\n }\n\n static fromModule(\n virtualAssetModule: number | string | { uri: string; width: number; height: number }\n ): Asset {\n if (typeof virtualAssetModule === 'string') {\n return Asset.fromURI(virtualAssetModule);\n } else if (typeof virtualAssetModule === 'number') {\n throw new Error(\n 'Cannot resolve numeric asset IDs on the server as they are non-deterministic identifiers.'\n );\n }\n if (\n typeof virtualAssetModule === 'object' &&\n 'uri' in virtualAssetModule &&\n typeof virtualAssetModule.uri === 'string'\n ) {\n const extension = AssetUris.getFileExtension(virtualAssetModule.uri);\n return new Asset({\n name: '',\n type: extension.startsWith('.') ? extension.substring(1) : extension,\n hash: null,\n uri: virtualAssetModule.uri,\n width: virtualAssetModule.width,\n height: virtualAssetModule.height,\n });\n }\n throw new Error('Unexpected asset module ID type: ' + typeof virtualAssetModule);\n }\n\n static fromMetadata(meta: AssetMetadata): Asset {\n const metaHash = meta.hash;\n if (Asset.byHash[metaHash]) {\n return Asset.byHash[metaHash];\n }\n\n const { uri, hash } = selectAssetSource(meta);\n const asset = new Asset({\n name: meta.name,\n type: meta.type,\n hash,\n uri,\n width: meta.width,\n height: meta.height,\n });\n Asset.byHash[metaHash] = asset;\n return asset;\n }\n\n static fromURI(uri: string): Asset {\n if (Asset.byUri[uri]) {\n return Asset.byUri[uri];\n }\n\n // Possibly a Base64-encoded URI\n let type = '';\n if (uri.indexOf(';base64') > -1) {\n type = uri.split(';')[0].split('/')[1];\n } else {\n const extension = AssetUris.getFileExtension(uri);\n type = extension.startsWith('.') ? extension.substring(1) : extension;\n }\n\n const asset = new Asset({\n name: '',\n type,\n hash: null,\n uri,\n });\n\n Asset.byUri[uri] = asset;\n\n return asset;\n }\n\n async downloadAsync(): Promise<this> {\n return this;\n }\n}\n\nfunction pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n}\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nfunction selectAssetSource(meta: AssetMetadata): AssetSource {\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = pickScale(meta.scales, 1);\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? (meta.fileHashes[index] ?? meta.fileHashes[0]) : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? (meta.fileUris[index] ?? meta.fileUris[0]) : meta.uri;\n if (uri) {\n return { uri, hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;\n const params = new URLSearchParams({\n platform: process.env.EXPO_OS!,\n hash: meta.hash,\n });\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix + '?' + params;\n return { uri, hash };\n }\n\n // In correctly configured apps, we arrive here if the asset is locally available on disk due to\n // being managed by expo-updates, and `getLocalAssetUri(hash)` must return a local URI for this\n // hash. Since the asset is local, we don't have a remote URL and specify an invalid URL (an empty\n // string) as a placeholder.\n return { uri: '', hash };\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PackagerAsset } from '@react-native/assets-registry/registry';
|
|
2
|
+
import type { AssetMetadata } from './AssetSources';
|
|
2
3
|
export type ResolvedAssetSource = {
|
|
3
4
|
__packager_asset: boolean;
|
|
4
5
|
width?: number;
|
|
@@ -9,7 +10,7 @@ export type ResolvedAssetSource = {
|
|
|
9
10
|
export default class AssetSourceResolver {
|
|
10
11
|
private readonly serverUrl;
|
|
11
12
|
private readonly jsbundleUrl;
|
|
12
|
-
readonly asset: PackagerAsset;
|
|
13
|
+
readonly asset: PackagerAsset | AssetMetadata;
|
|
13
14
|
constructor(serverUrl: string | undefined | null, jsbundleUrl: string | undefined | null, asset: PackagerAsset);
|
|
14
15
|
isLoadedFromServer(): boolean;
|
|
15
16
|
isLoadedFromFileSystem(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetSourceResolver.d.ts","sourceRoot":"","sources":["../src/AssetSourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAI5E,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC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olver.js","sourceRoot":"","sources":["../src/AssetSourceResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"AssetSourceResolver.js","sourceRoot":"","sources":["../src/AssetSourceResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY1C,wDAAwD;AACxD,SAAS,kBAAkB,CAAC,KAAoC;IAC9D,MAAM,KAAK,GAAG,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5E,MAAM,WAAW,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;IACzD,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC,kBAAkB,GAAG,GAAG,GAAG,KAAK,CAAC,IAAI,GAAG,WAAW,GAAG,IAAI,CAAC;IAC1E,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC,IAAI,GAAG,WAAW,GAAG,IAAI,CAAC;IAClG,CAAC;AACH,CAAC;AAED,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACrB,SAAS,CAAS;IACnC,uCAAuC;IACvC,yCAAyC;IACzC,uCAAuC;IACtB,WAAW,CAA4B;IACxD,uBAAuB;IACP,KAAK,CAAgC;IAErD,YACE,S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AE,WAAmB;QACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC;gBAC7B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type { PackagerAsset } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\nimport { PixelRatio } from 'react-native';\n\nimport type { AssetMetadata } from './AssetSources';\n\nexport type ResolvedAssetSource = {\n __packager_asset: boolean;\n width?: number;\n height?: number;\n uri: string;\n scale: number;\n};\n\n// Returns the Metro dev server-specific asset location.\nfunction getScaledAssetPath(asset: PackagerAsset | AssetMetadata): string {\n const scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get());\n const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';\n const type = !asset.type ? '' : `.${asset.type}`;\n if (__DEV__) {\n return asset.httpServerLocation + '/' + asset.name + scaleSuffix + type;\n } else {\n return asset.httpServerLocation.replace(/\\.\\.\\//g, '_') + '/' + asset.name + scaleSuffix + type;\n }\n}\n\nexport default class AssetSourceResolver {\n private readonly serverUrl: string;\n // where the jsbundle is being run from\n // NOTE(EvanBacon): Never defined on web.\n // @ts-expect-error: Never read locally\n private readonly jsbundleUrl: string | undefined | null;\n // the asset to resolve\n public readonly asset: PackagerAsset | AssetMetadata;\n\n constructor(\n serverUrl: string | undefined | null,\n jsbundleUrl: string | undefined | null,\n asset: PackagerAsset\n ) {\n this.serverUrl = serverUrl || 'https://expo.dev';\n this.jsbundleUrl = null;\n this.asset = asset;\n }\n\n // Always true for web runtimes\n isLoadedFromServer(): boolean {\n return true;\n }\n\n // Always false for web runtimes\n isLoadedFromFileSystem(): boolean {\n return false;\n }\n\n defaultAsset(): ResolvedAssetSource {\n return this.assetServerURL();\n }\n\n /**\n * @returns absolute remote URL for the hosted asset.\n */\n assetServerURL(): ResolvedAssetSource {\n const fromUrl = new URL(getScaledAssetPath(this.asset), this.serverUrl);\n fromUrl.searchParams.set('platform', Platform.OS);\n fromUrl.searchParams.set('hash', this.asset.hash);\n return this.fromSource(\n // Relative on web\n fromUrl.toString().replace(fromUrl.origin, '')\n );\n }\n\n fromSource(source: string): ResolvedAssetSource {\n return {\n __packager_asset: true,\n width: this.asset.width ?? undefined,\n height: this.asset.height ?? undefined,\n uri: source,\n scale: AssetSourceResolver.pickScale(this.asset.scales, PixelRatio.get()),\n };\n }\n\n static pickScale(scales: number[], deviceScale: number): number {\n for (let i = 0; i < scales.length; i++) {\n if (scales[i] >= deviceScale) {\n return scales[i];\n }\n }\n return scales[scales.length - 1] || 1;\n }\n}\n"]}
|
package/build/AssetSources.js
CHANGED
|
@@ -47,7 +47,7 @@ export function selectAssetSource(meta) {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
// Temporary fallback for loading assets in Expo Go home
|
|
50
|
-
if (NativeModules
|
|
50
|
+
if (NativeModules['ExponentKernel']) {
|
|
51
51
|
return { uri: `https://classic-assets.eascdn.net/~assets/${encodeURIComponent(hash)}`, hash };
|
|
52
52
|
}
|
|
53
53
|
// In correctly configured apps, we arrive here if the asset is locally available on disk due to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetSources.js","sourceRoot":"","sources":["../src/AssetSources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAiBhE;;;;;GAKG;AACH,MAAM,UAA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AE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,yDAAyD;IACzD,OAAO,eAAe,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AACpE,CAAC","sourcesContent":["import type { PackagerAsset } from '@react-native/assets-registry/registry';\nimport { Platform } from 'expo-modules-core';\nimport { PixelRatio, NativeModules } from 'react-native';\n\nimport AssetSourceResolver from './AssetSourceResolver';\nimport { getManifest2, manifestBaseUrl } from './PlatformUtils';\n\n// @docsMissing\nexport type AssetMetadata = Pick<\n PackagerAsset,\n 'httpServerLocation' | 'name' | 'hash' | 'type' | 'scales' | 'width' | 'height'\n> & {\n uri?: string;\n fileHashes?: string[];\n fileUris?: string[];\n};\n\nexport type AssetSource = {\n uri: string;\n hash: string;\n};\n\n/**\n * Selects the best file for the given asset (ex: choosing the best scale for images) and returns\n * a { uri, hash } pair for the specific asset file.\n *\n * If the asset isn't an image with multiple scales, the first file is selected.\n */\nexport function selectAssetSource(meta: AssetMetadata): AssetSource {\n // This logic is based on that of AssetSourceResolver, with additional support for file hashes and\n // explicitly provided URIs\n const scale = AssetSourceResolver.pickScale(meta.scales, PixelRatio.get());\n const index = meta.scales.findIndex((s) => s === scale);\n const hash = meta.fileHashes ? (meta.fileHashes[index] ?? meta.fileHashes[0]) : meta.hash;\n\n // Allow asset processors to directly provide the URL to load\n const uri = meta.fileUris ? (meta.fileUris[index] ?? meta.fileUris[0]) : meta.uri;\n if (uri) {\n return { uri: resolveUri(uri), hash };\n }\n\n const fileScale = scale === 1 ? '' : `@${scale}x`;\n const fileExtension = meta.type ? `.${encodeURIComponent(meta.type)}` : '';\n const suffix = `/${encodeURIComponent(meta.name)}${fileScale}${fileExtension}`;\n const params = new URLSearchParams({\n platform: Platform.OS,\n hash: meta.hash,\n });\n\n // For assets with a specified absolute URL, we use the existing origin instead of prepending the\n // development server or production CDN URL origin\n if (/^https?:\\/\\//.test(meta.httpServerLocation)) {\n const uri = meta.httpServerLocation + suffix + '?' + params;\n return { uri, hash };\n }\n\n // For assets during development using manifest2, we use the development server's URL origin\n const manifest2 = getManifest2();\n\n const devServerUrl = manifest2?.extra?.expoGo?.developer\n ? 'http://' + manifest2.extra.expoGo.debuggerHost\n : null;\n if (devServerUrl) {\n const baseUrl = new URL(meta.httpServerLocation + suffix, devServerUrl);\n\n baseUrl.searchParams.set('platform', Platform.OS);\n baseUrl.searchParams.set('hash', meta.hash);\n return {\n uri: baseUrl.href,\n hash,\n };\n }\n\n // Temporary fallback for loading assets in Expo Go home\n if (NativeModules['ExponentKernel']) {\n return { uri: `https://classic-assets.eascdn.net/~assets/${encodeURIComponent(hash)}`, hash };\n }\n\n // In correctly configured apps, we arrive here if the asset is locally available on disk due to\n // being managed by expo-updates, and `getLocalAssetUri(hash)` must return a local URI for this\n // hash. Since the asset is local, we don't have a remote URL and specify an invalid URL (an empty\n // string) as a placeholder.\n return { uri: '', hash };\n}\n\n/**\n * Resolves the given URI to an absolute URI. If the given URI is already an absolute URI, it is\n * simply returned. Otherwise, if it is a relative URI, it is resolved relative to the manifest's\n * base URI.\n */\nexport function resolveUri(uri: string): string {\n // `manifestBaseUrl` is always an absolute URL or `null`.\n return manifestBaseUrl ? new URL(uri, manifestBaseUrl).href : uri;\n}\n"]}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import AssetSourceResolver, { ResolvedAssetSource } from './AssetSourceResolver';
|
|
2
2
|
export declare function setCustomSourceTransformer(transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource): void;
|
|
3
|
+
interface resolveAssetSource {
|
|
4
|
+
(source: any): ResolvedAssetSource | null;
|
|
5
|
+
setCustomSourceTransformer(transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource): ResolvedAssetSource;
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* `source` is either a number (opaque type returned by require('./foo.png'))
|
|
5
9
|
* or an `ImageSource` like { uri: '<http location || file path>' }
|
|
6
10
|
*/
|
|
7
|
-
|
|
11
|
+
declare function resolveAssetSource(source: any): ResolvedAssetSource | null;
|
|
12
|
+
declare const _default: resolveAssetSource;
|
|
13
|
+
export default _default;
|
|
8
14
|
export declare const pickScale: typeof AssetSourceResolver.pickScale;
|
|
9
15
|
//# sourceMappingURL=resolveAssetSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAssetSource.d.ts","sourceRoot":"","sources":["../src/resolveAssetSource.ts"],"names":[],"mappings":"AAEA,OAAO,mBAAmB,EAAE,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIjF,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,CAAC,QAAQ,EAAE,mBAAmB,KAAK,mBAAmB,GAClE,IAAI,CAEN;AAED
|
|
1
|
+
{"version":3,"file":"resolveAssetSource.d.ts","sourceRoot":"","sources":["../src/resolveAssetSource.ts"],"names":[],"mappings":"AAEA,OAAO,mBAAmB,EAAE,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAIjF,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,CAAC,QAAQ,EAAE,mBAAmB,KAAK,mBAAmB,GAClE,IAAI,CAEN;AAED,UAAU,kBAAkB;IAC1B,CAAC,MAAM,EAAE,GAAG,GAAG,mBAAmB,GAAG,IAAI,CAAC;IAC1C,0BAA0B,CACxB,WAAW,EAAE,CAAC,QAAQ,EAAE,mBAAmB,KAAK,mBAAmB,GAClE,mBAAmB,CAAC;CACxB;AAED;;;GAGG;AACH,iBAAS,kBAAkB,CAAC,MAAM,EAAE,GAAG,GAAG,mBAAmB,GAAG,IAAI,CAoBnE;wBAQoC,kBAAkB;AAAvD,wBAAwD;AAExD,eAAO,MAAQ,SAAS,sCAAwB,CAAC"}
|
|
@@ -8,7 +8,7 @@ export function setCustomSourceTransformer(transformer) {
|
|
|
8
8
|
* `source` is either a number (opaque type returned by require('./foo.png'))
|
|
9
9
|
* or an `ImageSource` like { uri: '<http location || file path>' }
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
function resolveAssetSource(source) {
|
|
12
12
|
if (typeof source === 'object') {
|
|
13
13
|
return source;
|
|
14
14
|
}
|
|
@@ -29,5 +29,6 @@ Object.defineProperty(resolveAssetSource, 'setCustomSourceTransformer', {
|
|
|
29
29
|
return setCustomSourceTransformer;
|
|
30
30
|
},
|
|
31
31
|
});
|
|
32
|
+
export default resolveAssetSource;
|
|
32
33
|
export const { pickScale } = AssetSourceResolver;
|
|
33
34
|
//# sourceMappingURL=resolveAssetSource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAssetSource.js","sourceRoot":"","sources":["../src/resolveAssetSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE,OAAO,mBAA4C,MAAM,uBAAuB,CAAC;AAEjF,IAAI,wBAAgF,CAAC;AAErF,MAAM,UAAU,0BAA0B,CACxC,WAAmE;IAEnE,wBAAwB,GAAG,WAAW,CAAC;AACzC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveAssetSource.js","sourceRoot":"","sources":["../src/resolveAssetSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE,OAAO,mBAA4C,MAAM,uBAAuB,CAAC;AAEjF,IAAI,wBAAgF,CAAC;AAErF,MAAM,UAAU,0BAA0B,CACxC,WAAmE;IAEnE,wBAAwB,GAAG,WAAW,CAAC;AACzC,CAAC;AASD;;;GAGG;AACH,SAAS,kBAAkB,CAAC,MAAW;IACrC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,mBAAmB;IACtC,8CAA8C;IAC9C,kBAAkB,EAClB,IAAI,EACJ,KAAK,CACN,CAAC;IACF,IAAI,wBAAwB,EAAE,CAAC;QAC7B,OAAO,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,QAAQ,CAAC,YAAY,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,kBAAkB,EAAE,4BAA4B,EAAE;IACtE,GAAG;QACD,OAAO,0BAA0B,CAAC;IACpC,CAAC;CACF,CAAC,CAAC;AAEH,eAAe,kBAAwC,CAAC;AAExD,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC","sourcesContent":["import { getAssetByID } from '@react-native/assets-registry/registry';\n\nimport AssetSourceResolver, { ResolvedAssetSource } from './AssetSourceResolver';\n\nlet _customSourceTransformer: (resolver: AssetSourceResolver) => ResolvedAssetSource;\n\nexport function setCustomSourceTransformer(\n transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource\n): void {\n _customSourceTransformer = transformer;\n}\n\ninterface resolveAssetSource {\n (source: any): ResolvedAssetSource | null;\n setCustomSourceTransformer(\n transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource\n ): ResolvedAssetSource;\n}\n\n/**\n * `source` is either a number (opaque type returned by require('./foo.png'))\n * or an `ImageSource` like { uri: '<http location || file path>' }\n */\nfunction resolveAssetSource(source: any): ResolvedAssetSource | null {\n if (typeof source === 'object') {\n return source;\n }\n\n const asset = getAssetByID(source);\n if (!asset) {\n return null;\n }\n\n const resolver = new AssetSourceResolver(\n // Doesn't matter since this is removed on web\n 'https://expo.dev',\n null,\n asset\n );\n if (_customSourceTransformer) {\n return _customSourceTransformer(resolver);\n }\n return resolver.defaultAsset();\n}\n\nObject.defineProperty(resolveAssetSource, 'setCustomSourceTransformer', {\n get() {\n return setCustomSourceTransformer;\n },\n});\n\nexport default resolveAssetSource as resolveAssetSource;\n\nexport const { pickScale } = AssetSourceResolver;\n"]}
|
package/expo-module.config.json
CHANGED
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
8f267e22e39295e2e624fa3b369e14e7
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2947321b9e69b35c617301defba4c53d422f06af
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
82235d5cbf836582d8d2ef82d4872b1719280f54c64baf8255463c29c04d8e61
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
75f89c1898bb67417053e02314231d718dddf488c0c633a0e7b9b5d3ac4ecfead8e0f4037639d2326b44639b0a3a144d9addba12015529582f429e98e507a5d8
|
package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.2/expo.modules.asset-11.1.2.aar
ADDED
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
82d2f83ee82a6a8c547c10d84143d508
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
f5432ff11be2c225aff486a2966bf3360c858a52
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ea38b65d0ea0fa2e45feee543fc85a9b28e3b1985514cf0537bad140d2092332
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
9cefd3fce8d0494c319780b8719dfcb93b7022f177b5a8e394c8550e87462bac74dd62b839c30ff8434dde3e4ace8c7ee333e7ca31d853b857e6207902d78f73
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"formatVersion": "1.1",
|
|
3
|
+
"component": {
|
|
4
|
+
"group": "expo.modules.asset",
|
|
5
|
+
"module": "expo.modules.asset",
|
|
6
|
+
"version": "11.1.2",
|
|
7
|
+
"attributes": {
|
|
8
|
+
"org.gradle.status": "release"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"createdBy": {
|
|
12
|
+
"gradle": {
|
|
13
|
+
"version": "8.13"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"variants": [
|
|
17
|
+
{
|
|
18
|
+
"name": "releaseVariantReleaseApiPublication",
|
|
19
|
+
"attributes": {
|
|
20
|
+
"org.gradle.category": "library",
|
|
21
|
+
"org.gradle.dependency.bundling": "external",
|
|
22
|
+
"org.gradle.libraryelements": "aar",
|
|
23
|
+
"org.gradle.usage": "java-api"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
{
|
|
27
|
+
"name": "expo.modules.asset-11.1.2.aar",
|
|
28
|
+
"url": "expo.modules.asset-11.1.2.aar",
|
|
29
|
+
"size": 18976,
|
|
30
|
+
"sha512": "9cefd3fce8d0494c319780b8719dfcb93b7022f177b5a8e394c8550e87462bac74dd62b839c30ff8434dde3e4ace8c7ee333e7ca31d853b857e6207902d78f73",
|
|
31
|
+
"sha256": "ea38b65d0ea0fa2e45feee543fc85a9b28e3b1985514cf0537bad140d2092332",
|
|
32
|
+
"sha1": "f5432ff11be2c225aff486a2966bf3360c858a52",
|
|
33
|
+
"md5": "82d2f83ee82a6a8c547c10d84143d508"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "releaseVariantReleaseRuntimePublication",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"org.gradle.category": "library",
|
|
41
|
+
"org.gradle.dependency.bundling": "external",
|
|
42
|
+
"org.gradle.libraryelements": "aar",
|
|
43
|
+
"org.gradle.usage": "java-runtime"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": [
|
|
46
|
+
{
|
|
47
|
+
"group": "org.jetbrains.kotlin",
|
|
48
|
+
"module": "kotlin-stdlib-jdk7",
|
|
49
|
+
"version": {
|
|
50
|
+
"requires": "2.0.21"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"files": [
|
|
55
|
+
{
|
|
56
|
+
"name": "expo.modules.asset-11.1.2.aar",
|
|
57
|
+
"url": "expo.modules.asset-11.1.2.aar",
|
|
58
|
+
"size": 18976,
|
|
59
|
+
"sha512": "9cefd3fce8d0494c319780b8719dfcb93b7022f177b5a8e394c8550e87462bac74dd62b839c30ff8434dde3e4ace8c7ee333e7ca31d853b857e6207902d78f73",
|
|
60
|
+
"sha256": "ea38b65d0ea0fa2e45feee543fc85a9b28e3b1985514cf0537bad140d2092332",
|
|
61
|
+
"sha1": "f5432ff11be2c225aff486a2966bf3360c858a52",
|
|
62
|
+
"md5": "82d2f83ee82a6a8c547c10d84143d508"
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "releaseVariantReleaseSourcePublication",
|
|
68
|
+
"attributes": {
|
|
69
|
+
"org.gradle.category": "documentation",
|
|
70
|
+
"org.gradle.dependency.bundling": "external",
|
|
71
|
+
"org.gradle.docstype": "sources",
|
|
72
|
+
"org.gradle.usage": "java-runtime"
|
|
73
|
+
},
|
|
74
|
+
"files": [
|
|
75
|
+
{
|
|
76
|
+
"name": "expo.modules.asset-11.1.2-sources.jar",
|
|
77
|
+
"url": "expo.modules.asset-11.1.2-sources.jar",
|
|
78
|
+
"size": 3123,
|
|
79
|
+
"sha512": "75f89c1898bb67417053e02314231d718dddf488c0c633a0e7b9b5d3ac4ecfead8e0f4037639d2326b44639b0a3a144d9addba12015529582f429e98e507a5d8",
|
|
80
|
+
"sha256": "82235d5cbf836582d8d2ef82d4872b1719280f54c64baf8255463c29c04d8e61",
|
|
81
|
+
"sha1": "2947321b9e69b35c617301defba4c53d422f06af",
|
|
82
|
+
"md5": "8f267e22e39295e2e624fa3b369e14e7"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
65620523e9d48a89552a9f9ec2625188
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4affb01fcd0c089e15e55e5ae25bced5010022a6
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c5a7a37ab01fdd56a516cd4872723102d61ce8ea87b558786e009e883c45c90a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
96d713075cbdfb0e7ba1f62e25e41fb8b0606c1f5b7434f3262ba38571daba54d163bc28a5a8cda26cba806bde347335979961817dc0186d6299fd771004a960
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<modelVersion>4.0.0</modelVersion>
|
|
10
10
|
<groupId>expo.modules.asset</groupId>
|
|
11
11
|
<artifactId>expo.modules.asset</artifactId>
|
|
12
|
-
<version>11.1.
|
|
12
|
+
<version>11.1.2</version>
|
|
13
13
|
<packaging>aar</packaging>
|
|
14
14
|
<name>expo.modules.asset</name>
|
|
15
15
|
<url>https://github.com/expo/expo</url>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0e5829913b0c5b8b72a981e27acf8cb1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c711d78b03f57c9b12624e3ac57edacbc870970d
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1e9220b75a1e731197d8204dc51e8ba95f8301925cb711df88f3a8e14cca7bb0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d3fc847c97697f485b847ea536dfcef727719de522d249053e27cda7c62e70b6f861637e905021d11c7028c46f0496c0207fcac8d9369feef992b93bc1310703
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
<groupId>expo.modules.asset</groupId>
|
|
4
4
|
<artifactId>expo.modules.asset</artifactId>
|
|
5
5
|
<versioning>
|
|
6
|
-
<latest>11.1.
|
|
7
|
-
<release>11.1.
|
|
6
|
+
<latest>11.1.2</latest>
|
|
7
|
+
<release>11.1.2</release>
|
|
8
8
|
<versions>
|
|
9
|
-
<version>11.1.
|
|
9
|
+
<version>11.1.2</version>
|
|
10
10
|
</versions>
|
|
11
|
-
<lastUpdated>
|
|
11
|
+
<lastUpdated>20250414185046</lastUpdated>
|
|
12
12
|
</versioning>
|
|
13
13
|
</metadata>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
7efe42e138cc7fa18468c5283c130ca1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
7b44797839c86db7140c804b50c401dcec714d0e
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
8f9663529cf9ebbeb4c011573eb91ea3201f6d231d216acca2b9b8d4d7a798e5
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4aaee52af7767e296864351b20e2ab3e940a3356457d1ebf801f5c3c180dba0794d7fc6b28bd7c293a01fb76e397e13f9620b7ecd15cb3c5718a99ea751f043f
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-asset",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.2",
|
|
4
4
|
"description": "An Expo universal module to download assets and pass them into other APIs",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -48,17 +48,19 @@
|
|
|
48
48
|
"preset": "expo-module-scripts"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@expo/image-utils": "^0.7.
|
|
52
|
-
"expo-constants": "~17.1.
|
|
51
|
+
"@expo/image-utils": "^0.7.2",
|
|
52
|
+
"expo-constants": "~17.1.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@testing-library/react-native": "^13.1.0",
|
|
56
|
-
"
|
|
56
|
+
"@types/node": "^22.14.0",
|
|
57
|
+
"@types/react-native__assets": "^1.0.3",
|
|
58
|
+
"expo-module-scripts": "^4.1.2"
|
|
57
59
|
},
|
|
58
60
|
"peerDependencies": {
|
|
59
61
|
"expo": "*",
|
|
60
62
|
"react": "*",
|
|
61
63
|
"react-native": "*"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "cb9fdd93f76f28e2ace4f66080b2386d87239553"
|
|
64
66
|
}
|
package/src/Asset.fx.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { default as AssetSourceResolver } from 'react-native/Libraries/Image/AssetSourceResolver';
|
|
2
|
+
|
|
3
|
+
import { Asset, ANDROID_EMBEDDED_URL_BASE_RESOURCE } from './Asset';
|
|
2
4
|
import { IS_ENV_WITH_LOCAL_ASSETS } from './PlatformUtils';
|
|
3
5
|
import resolveAssetSource, { setCustomSourceTransformer } from './resolveAssetSource';
|
|
4
6
|
|
|
5
7
|
// Override React Native's asset resolution for `Image` components in contexts where it matters
|
|
6
8
|
if (IS_ENV_WITH_LOCAL_ASSETS) {
|
|
7
9
|
const setTransformer =
|
|
8
|
-
// @ts-ignore
|
|
9
10
|
resolveAssetSource.setCustomSourceTransformer || setCustomSourceTransformer;
|
|
10
11
|
setTransformer((resolver) => {
|
|
11
12
|
try {
|
|
12
13
|
// Bundler is using the hashAssetFiles plugin if and only if the fileHashes property exists
|
|
13
|
-
if (resolver.asset.fileHashes) {
|
|
14
|
+
if ('fileHashes' in resolver.asset && resolver.asset.fileHashes) {
|
|
14
15
|
const asset = Asset.fromMetadata(resolver.asset);
|
|
16
|
+
if (asset.uri.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {
|
|
17
|
+
// TODO(@kitten): See https://github.com/expo/expo/commit/ec940b57a87d99ab4f1d06d87126e662c3f04f04#r155340943
|
|
18
|
+
// It's unclear whether this is sound since this may be our own AssetSourceResolver, which doesn't have this method
|
|
19
|
+
// Please compare `AssetSourceResolver` type from `react-native/Libraries/Image/AssetSourceResolver` against `./AssetSourceResolver`
|
|
20
|
+
return (
|
|
21
|
+
resolver as unknown as AssetSourceResolver
|
|
22
|
+
).resourceIdentifierWithoutScale() as any;
|
|
23
|
+
}
|
|
15
24
|
return resolver.fromSource(asset.downloaded ? asset.localUri! : asset.uri);
|
|
16
25
|
} else {
|
|
17
26
|
return resolver.defaultAsset();
|
package/src/Asset.server.ts
CHANGED
|
@@ -4,8 +4,8 @@ import * as AssetUris from './AssetUris';
|
|
|
4
4
|
import * as ImageAssets from './ImageAssets';
|
|
5
5
|
|
|
6
6
|
export class Asset {
|
|
7
|
-
private static byHash = {};
|
|
8
|
-
private static byUri = {};
|
|
7
|
+
private static byHash: Record<string, Asset | undefined> = {};
|
|
8
|
+
private static byUri: Record<string, Asset | undefined> = {};
|
|
9
9
|
|
|
10
10
|
public name: string;
|
|
11
11
|
public readonly type: string;
|
package/src/Asset.ts
CHANGED
|
@@ -26,13 +26,19 @@ type DownloadPromiseCallbacks = {
|
|
|
26
26
|
|
|
27
27
|
export { AssetMetadata };
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Android resource URL prefix.
|
|
31
|
+
* @hidden
|
|
32
|
+
*/
|
|
33
|
+
export const ANDROID_EMBEDDED_URL_BASE_RESOURCE = 'file:///android_res/';
|
|
34
|
+
|
|
29
35
|
/**
|
|
30
36
|
* The `Asset` class represents an asset in your app. It gives metadata about the asset (such as its
|
|
31
37
|
* name and type) and provides facilities to load the asset data.
|
|
32
38
|
*/
|
|
33
39
|
export class Asset {
|
|
34
|
-
private static byHash = {};
|
|
35
|
-
private static byUri = {};
|
|
40
|
+
private static byHash: Record<string, Asset | undefined> = {};
|
|
41
|
+
private static byUri: Record<string, Asset | undefined> = {};
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
44
|
* The name of the asset file without the extension. Also without the part from `@` onward in the
|
|
@@ -95,7 +101,11 @@ export class Asset {
|
|
|
95
101
|
|
|
96
102
|
if (hash) {
|
|
97
103
|
this.localUri = getLocalAssetUri(hash, type);
|
|
98
|
-
if (this.localUri) {
|
|
104
|
+
if (this.localUri?.startsWith(ANDROID_EMBEDDED_URL_BASE_RESOURCE)) {
|
|
105
|
+
// Treat Android embedded resources as not downloaded state, because the uri is not direct accessible.
|
|
106
|
+
this.uri = this.localUri;
|
|
107
|
+
this.localUri = null;
|
|
108
|
+
} else if (this.localUri) {
|
|
99
109
|
this.downloaded = true;
|
|
100
110
|
}
|
|
101
111
|
}
|
|
@@ -276,7 +286,7 @@ export class Asset {
|
|
|
276
286
|
|
|
277
287
|
this.downloaded = true;
|
|
278
288
|
this._downloadCallbacks.forEach(({ resolve }) => resolve());
|
|
279
|
-
} catch (e) {
|
|
289
|
+
} catch (e: any) {
|
|
280
290
|
this._downloadCallbacks.forEach(({ reject }) => reject(e));
|
|
281
291
|
throw e;
|
|
282
292
|
} finally {
|
|
@@ -2,6 +2,8 @@ import type { PackagerAsset } from '@react-native/assets-registry/registry';
|
|
|
2
2
|
import { Platform } from 'expo-modules-core';
|
|
3
3
|
import { PixelRatio } from 'react-native';
|
|
4
4
|
|
|
5
|
+
import type { AssetMetadata } from './AssetSources';
|
|
6
|
+
|
|
5
7
|
export type ResolvedAssetSource = {
|
|
6
8
|
__packager_asset: boolean;
|
|
7
9
|
width?: number;
|
|
@@ -11,7 +13,7 @@ export type ResolvedAssetSource = {
|
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
// Returns the Metro dev server-specific asset location.
|
|
14
|
-
function getScaledAssetPath(asset): string {
|
|
16
|
+
function getScaledAssetPath(asset: PackagerAsset | AssetMetadata): string {
|
|
15
17
|
const scale = AssetSourceResolver.pickScale(asset.scales, PixelRatio.get());
|
|
16
18
|
const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';
|
|
17
19
|
const type = !asset.type ? '' : `.${asset.type}`;
|
|
@@ -26,9 +28,10 @@ export default class AssetSourceResolver {
|
|
|
26
28
|
private readonly serverUrl: string;
|
|
27
29
|
// where the jsbundle is being run from
|
|
28
30
|
// NOTE(EvanBacon): Never defined on web.
|
|
31
|
+
// @ts-expect-error: Never read locally
|
|
29
32
|
private readonly jsbundleUrl: string | undefined | null;
|
|
30
33
|
// the asset to resolve
|
|
31
|
-
public readonly asset: PackagerAsset;
|
|
34
|
+
public readonly asset: PackagerAsset | AssetMetadata;
|
|
32
35
|
|
|
33
36
|
constructor(
|
|
34
37
|
serverUrl: string | undefined | null,
|
package/src/AssetSources.ts
CHANGED
|
@@ -72,7 +72,7 @@ export function selectAssetSource(meta: AssetMetadata): AssetSource {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Temporary fallback for loading assets in Expo Go home
|
|
75
|
-
if (NativeModules
|
|
75
|
+
if (NativeModules['ExponentKernel']) {
|
|
76
76
|
return { uri: `https://classic-assets.eascdn.net/~assets/${encodeURIComponent(hash)}`, hash };
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -10,11 +10,18 @@ export function setCustomSourceTransformer(
|
|
|
10
10
|
_customSourceTransformer = transformer;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
interface resolveAssetSource {
|
|
14
|
+
(source: any): ResolvedAssetSource | null;
|
|
15
|
+
setCustomSourceTransformer(
|
|
16
|
+
transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource
|
|
17
|
+
): ResolvedAssetSource;
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
/**
|
|
14
21
|
* `source` is either a number (opaque type returned by require('./foo.png'))
|
|
15
22
|
* or an `ImageSource` like { uri: '<http location || file path>' }
|
|
16
23
|
*/
|
|
17
|
-
|
|
24
|
+
function resolveAssetSource(source: any): ResolvedAssetSource | null {
|
|
18
25
|
if (typeof source === 'object') {
|
|
19
26
|
return source;
|
|
20
27
|
}
|
|
@@ -42,4 +49,6 @@ Object.defineProperty(resolveAssetSource, 'setCustomSourceTransformer', {
|
|
|
42
49
|
},
|
|
43
50
|
});
|
|
44
51
|
|
|
52
|
+
export default resolveAssetSource as resolveAssetSource;
|
|
53
|
+
|
|
45
54
|
export const { pickScale } = AssetSourceResolver;
|
|
@@ -3,8 +3,8 @@ declare module 'react-native/Libraries/Image/AssetSourceResolver' {
|
|
|
3
3
|
|
|
4
4
|
export type ResolvedAssetSource = {
|
|
5
5
|
__packager_asset: boolean;
|
|
6
|
-
width
|
|
7
|
-
height
|
|
6
|
+
width?: number | null;
|
|
7
|
+
height?: number | null;
|
|
8
8
|
uri: string;
|
|
9
9
|
scale: number;
|
|
10
10
|
};
|
|
@@ -41,3 +41,17 @@ declare module 'react-native/Libraries/Image/resolveAssetSource' {
|
|
|
41
41
|
transformer: (resolver: AssetSourceResolver) => ResolvedAssetSource
|
|
42
42
|
): void;
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
declare module '@react-native/assets-registry/registry' {
|
|
46
|
+
import type { PackagerAsset } from '@react-native/assets/registry';
|
|
47
|
+
export * from '@react-native/assets/registry';
|
|
48
|
+
|
|
49
|
+
// NOTE(@kitten): Custom override supported in Expo only
|
|
50
|
+
interface VirtualAssetModule {
|
|
51
|
+
uri: string;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getAssetByID(input: number | VirtualAssetModule): PackagerAsset | undefined;
|
|
57
|
+
}
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
35bc9bbfb45afd8ba98b81ba1201ffe8
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
b2f2e4eb441ad4142649a84b06ece2553e1fedfa
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a32f8f346f06472a5da200db4401fd3b66269e9d7408f84afca7bca8e9e41b86
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
12bebdf896506f7950eb93b083a390cda2b2f02485b6fa830e0d9a64cd406e746eb327965bdce198931f79098b274d2fee26fa0befb3c41810ada61548757b0f
|
package/local-maven-repo/expo/modules/asset/expo.modules.asset/11.1.1/expo.modules.asset-11.1.1.aar
DELETED
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
b49f82b07af8cd6fc23cfb5ae0ee8be6
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
385f313d0b4a85e717684a71be98cee6eb3830a2
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
61ad99c23501db4ec3dd6ae78dab9a9996bc01b44d9e333c4ac41f8ee2016e7b
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
e7a8d3a52c106e4c0ad044d4bca075cd96f7345fc6eacaf1004019c6f056017eb2b7cbaa1437f4f06c301eab6f4a3800ce8b045ead03c93d6fe6007bac39f680
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"formatVersion": "1.1",
|
|
3
|
-
"component": {
|
|
4
|
-
"group": "expo.modules.asset",
|
|
5
|
-
"module": "expo.modules.asset",
|
|
6
|
-
"version": "11.1.1",
|
|
7
|
-
"attributes": {
|
|
8
|
-
"org.gradle.status": "release"
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"createdBy": {
|
|
12
|
-
"gradle": {
|
|
13
|
-
"version": "8.13"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"variants": [
|
|
17
|
-
{
|
|
18
|
-
"name": "releaseVariantReleaseApiPublication",
|
|
19
|
-
"attributes": {
|
|
20
|
-
"org.gradle.category": "library",
|
|
21
|
-
"org.gradle.dependency.bundling": "external",
|
|
22
|
-
"org.gradle.libraryelements": "aar",
|
|
23
|
-
"org.gradle.usage": "java-api"
|
|
24
|
-
},
|
|
25
|
-
"files": [
|
|
26
|
-
{
|
|
27
|
-
"name": "expo.modules.asset-11.1.1.aar",
|
|
28
|
-
"url": "expo.modules.asset-11.1.1.aar",
|
|
29
|
-
"size": 17695,
|
|
30
|
-
"sha512": "e7a8d3a52c106e4c0ad044d4bca075cd96f7345fc6eacaf1004019c6f056017eb2b7cbaa1437f4f06c301eab6f4a3800ce8b045ead03c93d6fe6007bac39f680",
|
|
31
|
-
"sha256": "61ad99c23501db4ec3dd6ae78dab9a9996bc01b44d9e333c4ac41f8ee2016e7b",
|
|
32
|
-
"sha1": "385f313d0b4a85e717684a71be98cee6eb3830a2",
|
|
33
|
-
"md5": "b49f82b07af8cd6fc23cfb5ae0ee8be6"
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"name": "releaseVariantReleaseRuntimePublication",
|
|
39
|
-
"attributes": {
|
|
40
|
-
"org.gradle.category": "library",
|
|
41
|
-
"org.gradle.dependency.bundling": "external",
|
|
42
|
-
"org.gradle.libraryelements": "aar",
|
|
43
|
-
"org.gradle.usage": "java-runtime"
|
|
44
|
-
},
|
|
45
|
-
"dependencies": [
|
|
46
|
-
{
|
|
47
|
-
"group": "org.jetbrains.kotlin",
|
|
48
|
-
"module": "kotlin-stdlib-jdk7",
|
|
49
|
-
"version": {
|
|
50
|
-
"requires": "2.0.21"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
"files": [
|
|
55
|
-
{
|
|
56
|
-
"name": "expo.modules.asset-11.1.1.aar",
|
|
57
|
-
"url": "expo.modules.asset-11.1.1.aar",
|
|
58
|
-
"size": 17695,
|
|
59
|
-
"sha512": "e7a8d3a52c106e4c0ad044d4bca075cd96f7345fc6eacaf1004019c6f056017eb2b7cbaa1437f4f06c301eab6f4a3800ce8b045ead03c93d6fe6007bac39f680",
|
|
60
|
-
"sha256": "61ad99c23501db4ec3dd6ae78dab9a9996bc01b44d9e333c4ac41f8ee2016e7b",
|
|
61
|
-
"sha1": "385f313d0b4a85e717684a71be98cee6eb3830a2",
|
|
62
|
-
"md5": "b49f82b07af8cd6fc23cfb5ae0ee8be6"
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"name": "releaseVariantReleaseSourcePublication",
|
|
68
|
-
"attributes": {
|
|
69
|
-
"org.gradle.category": "documentation",
|
|
70
|
-
"org.gradle.dependency.bundling": "external",
|
|
71
|
-
"org.gradle.docstype": "sources",
|
|
72
|
-
"org.gradle.usage": "java-runtime"
|
|
73
|
-
},
|
|
74
|
-
"files": [
|
|
75
|
-
{
|
|
76
|
-
"name": "expo.modules.asset-11.1.1-sources.jar",
|
|
77
|
-
"url": "expo.modules.asset-11.1.1-sources.jar",
|
|
78
|
-
"size": 2665,
|
|
79
|
-
"sha512": "12bebdf896506f7950eb93b083a390cda2b2f02485b6fa830e0d9a64cd406e746eb327965bdce198931f79098b274d2fee26fa0befb3c41810ada61548757b0f",
|
|
80
|
-
"sha256": "a32f8f346f06472a5da200db4401fd3b66269e9d7408f84afca7bca8e9e41b86",
|
|
81
|
-
"sha1": "b2f2e4eb441ad4142649a84b06ece2553e1fedfa",
|
|
82
|
-
"md5": "35bc9bbfb45afd8ba98b81ba1201ffe8"
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
86e17de091224fac85a43afee967463f
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dede2128c051a59f56c3c1783db172594d6cda2f
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
716c1ed7eda9a8b9847fcbf923c0814c0485cb4c5a61f9c89a24d2b65a1c23ed
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dce00a1b93506b0af129ea1cec26f3003141b927c18e06ccc74b690ad5f2ff61b9b7ccb9c497cf9e901e169771119a66b870fda80af95e6ace378ebe7dc54364
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a36b58a3f412caadbdaa32f941e59a89
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
461a281fff2765611cc3e49b6038413e9b0af3ab
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
eb07531b2a470e8a2510020d6a56fdba2271ba78abf54ffc9bec24bfb38c56a5
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
e90cd19fb4dbe6cea28a332781664750d5fa7b3f4bc8e08109939e8bc919a450342316e220575ef9b5aeb69cd34071307d42bc4f77c84b032012bed1c57c057a
|