Browse Source

fix(rn,filmstrip) simplify code

viewableItems always comes in order and indexes are always ascending. In
addition, if the array comes empty (I saw it happen on Android at least, when
scrolling like a maniac) we'd calculate the right value, instead of Infinity.
master
Saúl Ibarra Corretgé 4 years ago
parent
commit
20a1833c6c

+ 18
- 8
react/features/filmstrip/components/native/Filmstrip.js View File

170
      * @returns {void}
170
      * @returns {void}
171
      */
171
      */
172
     _onViewableItemsChanged({ viewableItems = [] }) {
172
     _onViewableItemsChanged({ viewableItems = [] }) {
173
-        const indexArray: Array<number> = viewableItems.map(i => i.index);
174
-
175
-        // If the local video placed at the beginning we need to shift the start index of the remoteParticipants array
176
-        // with 1 because and in the same time we don't need to adjust the end index because the end index will not be
177
-        // included.
178
-        const startIndex
179
-            = this._separateLocalThumbnail ? Math.min(...indexArray) : Math.max(Math.min(...indexArray) - 1, 0);
180
-        const endIndex = Math.max(...indexArray) + (this._separateLocalThumbnail ? 1 : 0);
173
+        if (!this._separateLocalThumbnail && viewableItems[0]?.index === 0) {
174
+            // Skip the local thumbnail.
175
+            viewableItems.shift();
176
+        }
177
+
178
+        if (viewableItems.length === 0) {
179
+            // User might be fast-scrolling, it will stabilize.
180
+            return;
181
+        }
182
+
183
+        let startIndex = viewableItems[0].index;
184
+        let endIndex = viewableItems[viewableItems.length - 1].index;
185
+
186
+        if (!this._separateLocalThumbnail) {
187
+            // We are off by one in the remote participants array.
188
+            startIndex -= 1;
189
+            endIndex -= 1;
190
+        }
181
 
191
 
182
         this.props.dispatch(setVisibleRemoteParticipants(startIndex, endIndex));
192
         this.props.dispatch(setVisibleRemoteParticipants(startIndex, endIndex));
183
     }
193
     }

+ 12
- 6
react/features/filmstrip/components/native/TileView.js View File

146
      * @returns {void}
146
      * @returns {void}
147
      */
147
      */
148
     _onViewableItemsChanged({ viewableItems = [] }: { viewableItems: Array<Object> }) {
148
     _onViewableItemsChanged({ viewableItems = [] }: { viewableItems: Array<Object> }) {
149
-        const indexArray = viewableItems.map(i => i.index);
149
+        if (viewableItems[0]?.index === 0) {
150
+            // Skip the local thumbnail.
151
+            viewableItems.shift();
152
+        }
153
+
154
+        if (viewableItems.length === 0) {
155
+            // User might be fast-scrolling, it will stabilize.
156
+            return;
157
+        }
150
 
158
 
151
-        // We need to shift the start index of the remoteParticipants array with 1 because of the local video placed
152
-        // at the beginning and in the same time we don't need to adjust the end index because the end index will not be
153
-        // included.
154
-        const startIndex = Math.max(Math.min(...indexArray) - 1, 0);
155
-        const endIndex = Math.max(...indexArray);
159
+        // We are off by one in the remote participants array.
160
+        const startIndex = viewableItems[0].index - 1;
161
+        const endIndex = viewableItems[viewableItems.length - 1].index - 1;
156
 
162
 
157
         this.props.dispatch(setVisibleRemoteParticipants(startIndex, endIndex));
163
         this.props.dispatch(setVisibleRemoteParticipants(startIndex, endIndex));
158
     }
164
     }

Loading…
Cancel
Save