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

[TS migration] Migrate VideoPlayerPreview, VideoPlayerControls and VideoPopoverMenu component files to TypeScript #37425

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7ef3d28
VideoPlayerThumbnail migreated to ts
smelaa Feb 27, 2024
1a70990
Migration of VideoPlayerPreview
smelaa Feb 28, 2024
aed45f8
Addressing review comments
smelaa Feb 28, 2024
0afcaae
Merge branch 'ts-migration-videoplayercontext' into ts-migration-vide…
smelaa Feb 28, 2024
d176eaf
VideoPopovermenu migrated to ts
smelaa Feb 28, 2024
03eae41
ProgressBar migrated to ts
smelaa Feb 29, 2024
2dbfe11
Merge branch 'ts-migration-videoplayercontext' into ts-migration-vide…
smelaa Feb 29, 2024
07947cd
VolumeButton migrated to ts
smelaa Feb 29, 2024
1c8b789
VideoPlayerControls migrated to ts
smelaa Feb 29, 2024
d2567a9
Changing types in VideoPlayerControls to match IconButton
smelaa Feb 29, 2024
528387f
Merging with main
smelaa Mar 1, 2024
361d4a0
Merge branch 'ts-migration-videoplayercontext' into ts-migration-vide…
smelaa Mar 1, 2024
2150628
Wrapping style in StyleProp component
smelaa Mar 1, 2024
4d84ed3
Migrate CategoryPicker to typescript
mateuuszzzzz Feb 12, 2024
b419a09
Merge branch 'ts-migration-videoplayercontext' into ts-migration-vide…
smelaa Mar 6, 2024
c768f5d
Address part of the review
smelaa Mar 13, 2024
6a50480
Address review comments
smelaa Mar 13, 2024
d2258f4
Solve typescript errors
smelaa Mar 13, 2024
fbef252
Merge branch 'main' into ts-migration-videoplayerpreview
smelaa Mar 14, 2024
db92a62
Add anchorref to VideoPopoverMenu
smelaa Mar 14, 2024
bea6377
Adress review comments
smelaa Mar 15, 2024
1a5c507
Address review comments.
smelaa Mar 15, 2024
410ef9f
Remove default value of props which are always set by a caller
smelaa Mar 18, 2024
7edb283
Merge branch 'main' into ts-migration-videoplayerpreview
smelaa Mar 18, 2024
607070c
Merge branch 'main' into ts-migration-videoplayerpreview
smelaa Mar 20, 2024
83a7bfd
Merge branch 'main' into ts-migration-videoplayerpreview
smelaa Mar 20, 2024
b0a2e69
Address review comments
smelaa Mar 20, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import Icon from '@components/Icon';
Expand All @@ -12,20 +11,9 @@ import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as ReportUtils from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {VideoPlayerThumbnailProps} from './types';

const propTypes = {
onPress: PropTypes.func.isRequired,

accessibilityLabel: PropTypes.string.isRequired,

thumbnailUrl: PropTypes.string,
};

const defaultProps = {
thumbnailUrl: undefined,
};

function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel}) {
function VideoPlayerThumbnail({thumbnailUrl = undefined, onPress, accessibilityLabel}: VideoPlayerThumbnailProps) {
const styles = useThemeStyles();
smelaa marked this conversation as resolved.
Show resolved Hide resolved

return (
Expand All @@ -48,9 +36,7 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel}) {
onPress={onPress}
onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) =>
showContextMenuForReport(event, anchor, (report && report.reportID) || '', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report))
}
onLongPress={(event) => showContextMenuForReport(event, anchor, report?.reportID ?? '', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report))}
>
<View style={[styles.videoThumbnailPlayButton]}>
<Icon
Expand All @@ -68,8 +54,6 @@ function VideoPlayerThumbnail({thumbnailUrl, onPress, accessibilityLabel}) {
);
}

VideoPlayerThumbnail.propTypes = propTypes;
VideoPlayerThumbnail.defaultProps = defaultProps;
VideoPlayerThumbnail.displayName = 'VideoPlayerThumbnail';

export default VideoPlayerThumbnail;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PropTypes from 'prop-types';
import type {VideoReadyForDisplayEvent} from 'expo-av';
import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import * as Expensicons from '@components/Icon/Expensicons';
Expand All @@ -10,32 +10,17 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useThumbnailDimensions from '@hooks/useThumbnailDimensions';
import useWindowDimensions from '@hooks/useWindowDimensions';
import CONST from '@src/CONST';
import type {VideoPlayerPreviewProps} from './types';
import VideoPlayerThumbnail from './VideoPlayerThumbnail';

const propTypes = {
videoUrl: PropTypes.string.isRequired,

videoDimensions: PropTypes.shape({
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
}),

videoDuration: PropTypes.number,

thumbnailUrl: PropTypes.string,

fileName: PropTypes.string.isRequired,

onShowModalPress: PropTypes.func.isRequired,
};

const defaultProps = {
videoDimensions: CONST.VIDEO_PLAYER.DEFAULT_VIDEO_DIMENSIONS,
thumbnailUrl: undefined,
videoDuration: 0,
};

function VideoPlayerPreview({videoUrl, thumbnailUrl, fileName, videoDimensions, videoDuration, onShowModalPress}) {
function VideoPlayerPreview({
videoUrl,
thumbnailUrl = undefined,
fileName,
smelaa marked this conversation as resolved.
Show resolved Hide resolved
videoDimensions = CONST.VIDEO_PLAYER.DEFAULT_VIDEO_DIMENSIONS,
videoDuration = 0,
onShowModalPress,
}: VideoPlayerPreviewProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {currentlyPlayingURL, updateCurrentlyPlayingURL} = usePlaybackContext();
Expand All @@ -44,8 +29,8 @@ function VideoPlayerPreview({videoUrl, thumbnailUrl, fileName, videoDimensions,
const [measuredDimensions, setMeasuredDimensions] = useState(videoDimensions);
const {thumbnailDimensionsStyles} = useThumbnailDimensions(measuredDimensions.width, measuredDimensions.height);

const onVideoLoaded = (e) => {
setMeasuredDimensions({width: e.srcElement.videoWidth, height: e.srcElement.videoHeight});
const onVideoLoaded = (event: VideoReadyForDisplayEvent & {srcElement: HTMLVideoElement}) => {
setMeasuredDimensions({width: event.srcElement.videoWidth, height: event.srcElement.videoHeight});
smelaa marked this conversation as resolved.
Show resolved Hide resolved
};

const handleOnPress = () => {
Expand Down Expand Up @@ -75,7 +60,7 @@ function VideoPlayerPreview({videoUrl, thumbnailUrl, fileName, videoDimensions,
<VideoPlayer
url={videoUrl}
onOpenInModalButtonPress={onShowModalPress}
onVideoLoaded={onVideoLoaded}
onVideoLoaded={onVideoLoaded as (event: VideoReadyForDisplayEvent) => void}
videoDuration={videoDuration}
shouldUseSmallVideoControls
style={[styles.w100, styles.h100]}
Expand All @@ -94,8 +79,6 @@ function VideoPlayerPreview({videoUrl, thumbnailUrl, fileName, videoDimensions,
);
}

VideoPlayerPreview.propTypes = propTypes;
VideoPlayerPreview.defaultProps = defaultProps;
VideoPlayerPreview.displayName = 'VideoPlayerPreview';

export default VideoPlayerPreview;
26 changes: 26 additions & 0 deletions src/components/VideoPlayerPreview/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type {GestureResponderEvent} from 'react-native';
smelaa marked this conversation as resolved.
Show resolved Hide resolved

type VideoPlayerThumbnailProps = {
thumbnailUrl: string | undefined;
onPress: (event?: GestureResponderEvent | KeyboardEvent) => void | Promise<void>;
accessibilityLabel: string;
};

type VideoPlayerPreviewProps = {
videoUrl: string;

smelaa marked this conversation as resolved.
Show resolved Hide resolved
videoDimensions: {
smelaa marked this conversation as resolved.
Show resolved Hide resolved
width: number;
height: number;
};

videoDuration: number;

thumbnailUrl?: string;

fileName: string;

onShowModalPress: (event?: GestureResponderEvent | KeyboardEvent) => void | Promise<void>;
};

export type {VideoPlayerThumbnailProps, VideoPlayerPreviewProps};
Loading