Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix video does not stop playing when going to inbox from search #54552

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/components/Attachments/AttachmentView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Str} from 'expensify-common';
import React, {memo, useContext, useEffect, useState} from 'react';
import React, {memo, useEffect, useState} from 'react';
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
import type {Attachment, AttachmentSource} from '@components/Attachments/types';
import DistanceEReceipt from '@components/DistanceEReceipt';
import EReceipt from '@components/EReceipt';
Expand All @@ -23,6 +22,7 @@ import * as FileUtils from '@libs/fileDownload/FileUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import type {ColorValue} from '@styles/utils/types';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import AttachmentViewImage from './AttachmentViewImage';
import AttachmentViewPdf from './AttachmentViewPdf';
Expand Down Expand Up @@ -108,7 +108,6 @@ function AttachmentView({
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const {translate} = useLocalize();
const {updateCurrentlyPlayingURL} = usePlaybackContext();
const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext);

const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -117,7 +116,6 @@ function AttachmentView({
const [isHighResolution, setIsHighResolution] = useState<boolean>(false);
const [hasPDFFailedToLoad, setHasPDFFailedToLoad] = useState(false);
const isVideo = (typeof source === 'string' && Str.isVideo(source)) || (file?.name && Str.isVideo(file.name));
const isUsedInCarousel = !!attachmentCarouselPagerContext?.pagerRef;

useEffect(() => {
if (!isFocused && !(file && isUsedInAttachmentModal)) {
Expand Down Expand Up @@ -290,7 +288,7 @@ function AttachmentView({
return (
<AttachmentViewVideo
source={source}
shouldUseSharedVideoElement={isUsedInCarousel}
shouldUseSharedVideoElement={!CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => source.startsWith(prefix))}
isHovered={isHovered}
duration={duration}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {isDeletedNode} from '@components/HTMLEngineProvider/htmlEngineUtils';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import VideoPlayerPreview from '@components/VideoPlayerPreview';
import useCurrentReportID from '@hooks/useCurrentReportID';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot';
import Navigation from '@navigation/Navigation';
Expand All @@ -25,7 +24,6 @@
const width = Number(htmlAttribs[CONST.ATTACHMENT_THUMBNAIL_WIDTH_ATTRIBUTE]);
const height = Number(htmlAttribs[CONST.ATTACHMENT_THUMBNAIL_HEIGHT_ATTRIBUTE]);
const duration = Number(htmlAttribs[CONST.ATTACHMENT_DURATION_ATTRIBUTE]);
const currentReportIDValue = useCurrentReportID();
const isDeleted = isDeletedNode(tnode);

return (
Expand All @@ -36,7 +34,7 @@
<VideoPlayerPreview
key={key}
videoUrl={sourceURL}
reportID={currentReportIDValue?.currentReportID ?? '-1'}
reportID={report?.reportID ?? '-1'}

Check failure on line 37 in src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suneox We cannot remove the default value of reportID here, because if we do that we cannot play the video in the search page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove reportID prop for VideoPlayerPreview and only control the playing status by videoUrl with usePlaybackContext? If not, we can open a discussion and then add this file to .eslintrc.changed.js to ignore

fileName={fileName}
thumbnailUrl={thumbnailUrl}
videoDimensions={{width, height}}
Expand All @@ -46,7 +44,7 @@
if (!sourceURL || !type) {
return;
}
const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID ?? '-1', type, sourceURL, accountID);

Check failure on line 47 in src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Navigation.navigate(route);
}}
/>
Expand Down
9 changes: 8 additions & 1 deletion src/components/VideoPlayerContexts/PlaybackContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {View} from 'react-native';
import type {VideoWithOnFullScreenUpdate} from '@components/VideoPlayer/types';
import useCurrentReportID from '@hooks/useCurrentReportID';
import usePrevious from '@hooks/usePrevious';
import isReportScreenTopmostCentralPane from '@libs/Navigation/isReportScreenTopmostCentralPane';
import Visibility from '@libs/Visibility';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import type {PlaybackContext, StatusCallback} from './types';
Expand Down Expand Up @@ -100,7 +101,13 @@ function PlaybackContextProvider({children}: ChildrenProps) {
// This prevents the video that plays when the app opens from being interrupted when currentReportID
// is initially empty or '-1', or when it changes from empty/'-1' to another value
// after the report screen in the central pane is mounted on the large screen.
if (!currentReportID || !prevCurrentReportID || currentReportID === '-1' || prevCurrentReportID === '-1' || currentReportID === prevCurrentReportID) {
if (
!currentReportID ||
!prevCurrentReportID ||
(currentReportID === '-1' && isReportScreenTopmostCentralPane()) ||
(prevCurrentReportID === '-1' && !isReportScreenTopmostCentralPane()) ||
currentReportID === prevCurrentReportID
) {
return;
}
resetVideoPlayerData();
Expand Down
Loading