|
@@ -0,0 +1,31 @@
|
|
1
|
+import { ImageCache } from 'react-native-img-cache';
|
|
2
|
+
|
|
3
|
+/**
|
|
4
|
+ * Notifies about the successful download of an <tt>Image</tt> source. The name
|
|
5
|
+ * is inspired by <tt>Image</tt>. The downloaded <tt>Image</tt> source is not
|
|
6
|
+ * available because (1) I do not know how to get it from {@link ImageCache} and
|
|
7
|
+ * (2) we do not need it bellow. The function was explicitly introduced to cut
|
|
8
|
+ * down on unnecessary <tt>ImageCache</tt> <tt>observer</tt> instances.
|
|
9
|
+ *
|
|
10
|
+ * @private
|
|
11
|
+ * @returns {void}
|
|
12
|
+ */
|
|
13
|
+function _onLoad() {
|
|
14
|
+ // ImageCache requires an observer; otherwise, we do not need it because we
|
|
15
|
+ // merely want to initiate the download and do not care what happens with it
|
|
16
|
+ // afterwards.
|
|
17
|
+}
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ * Initiates the retrieval of a specific <tt>Image</tt> source (if it has not
|
|
21
|
+ * been initiated already). Due to limitations of {@link ImageCache}, the source
|
|
22
|
+ * may have at most one <tt>uri</tt>. The name is inspired by <tt>Image</tt>.
|
|
23
|
+ *
|
|
24
|
+ * @param {Object} source - The <tt>Image</tt> source with preferably exactly
|
|
25
|
+ * one <tt>uri</tt>.
|
|
26
|
+ * @public
|
|
27
|
+ * @returns {void}
|
|
28
|
+ */
|
|
29
|
+export function prefetch(source) {
|
|
30
|
+ ImageCache.get().on(source, /* observer */ _onLoad, /* immutable */ true);
|
|
31
|
+}
|