1 | import { Asset } from 'expo-asset';
|
2 | import { resolveAsync } from 'expo-asset-utils';
|
3 | export default async function resolveAsset(fileReference) {
|
4 | let urls = [];
|
5 | if (Array.isArray(fileReference)) {
|
6 | for (let file of fileReference) {
|
7 | const asset = await resolveAsync(file);
|
8 | urls.push(asset);
|
9 | }
|
10 | }
|
11 | else {
|
12 | const asset = await resolveAsync(fileReference);
|
13 | urls.push(asset);
|
14 | }
|
15 | return urls;
|
16 | }
|
17 | export async function stringFromAsset(asset) {
|
18 | if (asset instanceof Asset) {
|
19 | if (!asset.localUri) {
|
20 | await asset.downloadAsync();
|
21 | }
|
22 | if (!asset.localUri) {
|
23 | console.log("Error: You tried to download an Expo.Asset and for some reason it didn't cache... Known reasons are: it's an .mtl file");
|
24 | }
|
25 | return asset.localUri || asset.uri;
|
26 | }
|
27 | else if (typeof asset === 'string') {
|
28 | return asset;
|
29 | }
|
30 | return null;
|
31 | }
|
32 |
|
\ | No newline at end of file |