Просмотр исходного кода

[RN] Prefetch remote avatar images 1/2

j8
Lyubo Marinov 8 лет назад
Родитель
Сommit
97832e0eef

+ 5
- 0
react/features/base/participants/components/ParticipantView.native.js Просмотреть файл

@@ -2,6 +2,7 @@ import React, { Component } from 'react';
2 2
 import { connect } from 'react-redux';
3 3
 
4 4
 import { JitsiParticipantConnectionStatus } from '../../lib-jitsi-meet';
5
+import { prefetch } from '../../../mobile/image-cache';
5 6
 import {
6 7
     MEDIA_TYPE,
7 8
     shouldRenderVideoTrack,
@@ -209,6 +210,10 @@ function _mapStateToProps(state, ownProps) {
209 210
         // runtime which means that, if their old and new avatar URLs fail to
210 211
         // download, Avatar will change their automatically-generated colors.
211 212
         avatar || participant.local || (avatar = `#${participant.id}`);
213
+
214
+        // ParticipantView knows before Avatar that an avatar URL will be used
215
+        // so it's advisable to prefetch here.
216
+        avatar && prefetch({ uri: avatar });
212 217
     }
213 218
 
214 219
     return {

+ 31
- 0
react/features/mobile/image-cache/functions.js Просмотреть файл

@@ -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
+}

+ 2
- 0
react/features/mobile/image-cache/index.js Просмотреть файл

@@ -1 +1,3 @@
1
+export * from './functions';
2
+
1 3
 import './middleware';

Загрузка…
Отмена
Сохранить