Skip to content

Commit ff44253

Browse files
authored
fix: image gallery crash when many videos are present (#3380)
## 🎯 Goal This PR fixes an issue only present in the in-development V9 version, where we rely on videos refs to determine our interactions with a video component. As our clean-up function within the video player pool depends on the `videoRef` being up to date, we have to respect React's lifecycle when we want to run it (and make sure that the `videoRef` is always up to date accordingly). ## 🛠 Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## 🧪 Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## ☑️ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
1 parent 37a2543 commit ff44253

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export const AnimatedGalleryVideo = React.memo(
8585
if (videoRef.current) {
8686
videoPlayer.initPlayer({ playerRef: videoRef.current });
8787
}
88+
89+
return () => {
90+
videoPlayer.playerRef = null;
91+
};
8892
}, [videoPlayer]);
8993

9094
const { isPlaying } = useStateStore(videoPlayer.state, videoPlayerSelector);

package/src/components/ImageGallery/components/ImageGalleryHeader.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useState } from 'react';
1+
import React, { useEffect, useMemo, useState } from 'react';
22

33
import { Pressable, StyleSheet, Text, View, ViewStyle } from 'react-native';
44

@@ -92,9 +92,14 @@ export const ImageGalleryHeader = (props: Props) => {
9292

9393
const hideOverlay = () => {
9494
setOverlay('none');
95-
imageGalleryStateStore.clear();
9695
};
9796

97+
useEffect(() => {
98+
return () => {
99+
imageGalleryStateStore.clear();
100+
};
101+
}, [imageGalleryStateStore]);
102+
98103
return (
99104
<View
100105
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}

package/src/components/ImageGallery/hooks/useImageGalleryGestures.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ export const useImageGalleryGestures = ({
159159
const assetsLength = imageGalleryStateStore.assets.length;
160160

161161
const clearImageGallery = () => {
162-
runOnJS(imageGalleryStateStore.clear)();
163162
runOnJS(setOverlay)('none');
164163
};
165164

package/src/state-store/image-gallery-state-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class ImageGalleryStateStore {
219219
};
220220

221221
clear = () => {
222-
this.state.partialNext(INITIAL_STATE);
223222
this.videoPlayerPool.clear();
223+
this.state.partialNext(INITIAL_STATE);
224224
};
225225
}

0 commit comments

Comments
 (0)