Skip to content

Commit 257d9b4

Browse files
committed
update comment
1 parent c74da9b commit 257d9b4

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/hooks/useCheckIfRouteHasRemainedUnchanged.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ import useResponsiveLayout from './useResponsiveLayout';
66

77
/**
88
* Hook that returns a function to check if the currently active route remains the same as the route on which the component was initially rendered.
9-
* The `isFocused` is set to `false` every time the component experiences a 'blur' event,
10-
* except when opening an attachments modal, which is treated as an exception and does not trigger a reference update.
9+
* The `isOnInitialRenderedRouteRef` is set to `false` every time the component experiences a 'blur' event,
10+
* except when opening an attachments modal, which is treated as an exception and does not trigger a reference update because the attachments modal display overlap and we want to use shared VideoPlayer.
1111
*
12-
* @return Function that checks if the route where the component was rendered matches the currently active route.
12+
* @return Function that checks if the route where the component was initially rendered matches the current active route.
1313
*/
1414
function useCheckIfRouteHasRemainedUnchanged(videoUrl: string) {
15-
// Determines whether the component is still rendered on the initial rendered route.
15+
// Determines whether the component is still rendered on the initially rendered route.
1616
const isOnInitialRenderedRouteRef = useRef<boolean | undefined>(undefined);
1717
const navigation = useNavigation();
1818
const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout();
1919

2020
/**
21-
* Return true only when on the initial rendered route or on the attachment modal route whose source parameter equals videoUrl.
21+
* Return true only when on the initially rendered route or the video is currently playing in attachment modal.
2222
*/
2323
const hasRouteRemainedUnchanged = useCallback(() => {
2424
if (navigation.isFocused()) {
2525
return true;
2626
}
2727

28-
// If navigating away from the initial rendered route or attachment route
28+
// If navigating away from the initially rendered route or attachment route
2929
if (!isOnInitialRenderedRouteRef.current) {
3030
return false;
3131
}
3232

33-
// If on AttachmentModal, only play when the source parameters match videoUrl
33+
// If on AttachmentModal, only play when the source parameters match videoUrl ensures correct play VideoPlayer share for this one
3434
const currentRoute = navigationRef.getCurrentRoute();
3535
if (
3636
currentRoute?.name === SCREENS.ATTACHMENTS &&
@@ -64,12 +64,10 @@ function useCheckIfRouteHasRemainedUnchanged(videoUrl: string) {
6464
}, []);
6565

6666
useEffect(() => {
67-
// When the 'focus' event is emitted, it means we've returned to the initial rendered route
6867
const unsubscribeFocus = navigation.addListener('focus', () => {
6968
isOnInitialRenderedRouteRef.current = true;
7069
});
7170

72-
// Update the state indicating we've left the initial rendered route on 'blur' events, except when opening the attachments modal
7371
const unsubscribeBlur = navigation.addListener('blur', () => {
7472
const route = navigationRef.getCurrentRoute();
7573

0 commit comments

Comments
 (0)