-
Notifications
You must be signed in to change notification settings - Fork 3
/
Assets.ios.js
106 lines (81 loc) · 3.2 KB
/
Assets.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
*
*
* @providesModule ResourceDowloader
* @flow
*/
'use strict';
var RCTAssetManager = require('NativeModules').AssetManager;
var invariant = require('invariant');
class Assets {
/**
* Saves the resource file dowloaded from url into cache directory
* @param {string} url
* @param {string} cacheDir cache directory where we're going to store the resource file
* @param {function} sucessfull callback -Invoked with arg of filename given to dowloaded resource in cache
* directory.
* @param {function} error callback - Invoked with error message on error.
*
*/
static downloadResourceFromUrl( url: string, cacheDir: string, successCallback: Function, errorCallback: Function) {
invariant(
typeof url === 'string',
'RCTAssetManager.downloadResourceFromUrl url must be a valid string.'
);
invariant(
typeof cacheDir === 'string',
'RCTAssetManager.downloadResourceFromUrl cacheDir must be a valid string.'
);
RCTAssetManager.downloadResourceFromUrl(
url,cacheDir,
(localFileName) => {
successCallback && successCallback(localFileName);
},
(errorMessage) => {
errorCallback && errorCallback(errorMessage);
});
}
/**
* Lists resource file names in cache directory
* @param {string} cacheDir cache directory where is stored the resource file.
* @param {function} sucessfull callback -Invoked with arg of list of resource filenames stored
* in cache directory.
* @param {function} error callback - Invoked with error message on error.
*/
static listResourcesInCache(cacheDir: string, successCallback: Function, errorCallback:Function) {
invariant(
typeof cacheDir === 'string',
'RCTAssetManager.downloadResourceFromUrl cacheDir must be a valid string.'
);
RCTAssetManager.listResourcesInCache(cacheDir,
(arrayFilenames) => {
successCallback && successCallback(arrayFilenames);
},
(errorMessage) => {
errorCallback && errorCallback(errorMessage);
});
}
/**
* Delete resource file in cache directory
* @param {string} cacheDir cache directory where is stored the resource file.
* @param {function} sucessfull callback -Invoked with arg of list of resource filenames stored
* in cache directory.
* @param {function} error callback - Invoked with error message on error.
*/
static deleteResourceInCache(filename:string, cacheDir: string, successCallback:Function) {
invariant(
typeof cacheDir === 'string',
'RCTAssetManager.deleteResourceInCache cacheDir must be a valid string.'
);
invariant(
typeof filename === 'string',
'RCTAssetManager.deleteResourceInCache filename must be a valid string.'
);
RCTAssetManager.deleteResourceInCache(filename,cacheDir,
(deleted) => {
successCallback && successCallback(deleted);
}
);
}
}
module.exports = Assets;