Skip to content

Commit

Permalink
feat: added ratio prop
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmch committed Sep 19, 2023
1 parent 6b9019e commit ca82669
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/components/Media/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Media = (props: MediaAllProps) => {
playButton,
customBarControlsClassName,
qa,
ratio,
} = props;

const [hasVideoFallback, setHasVideoFallback] = useState(false);
Expand Down Expand Up @@ -80,6 +81,7 @@ export const Media = (props: MediaAllProps) => {
customBarControlsClassName,
hasVideoFallback,
setHasVideoFallback,
ratio,
};

if (fullscreen) {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Media/Video/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const Video = (props: VideoAllProps) => {
setHasVideoFallback,
hasVideoFallback,
qa,
ratio,
} = props;

const qaAttributes = getQaAttrubutes(qa, 'source');
Expand Down Expand Up @@ -105,6 +106,7 @@ const Video = (props: VideoAllProps) => {
height={height}
ariaLabel={ariaLabel}
customControlsOptions={customControlsOptions}
ratio={ratio}
/>
);
}, [
Expand All @@ -117,6 +119,7 @@ const Video = (props: VideoAllProps) => {
customBarControlsClassName,
metrika,
analyticsEvents,
ratio,
]);

const defaultVideoBlock = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReactPlayer/CustomBarControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const CustomBarControls = (props: CustomBarControlsProps) => {
)}
</button>
);
}, [elapsedTimePercent, mute, muteIcon, type, unmuteIcon]);
}, [elapsedTimePercent, isMuteButtonHidden, mute, muteIcon, type, unmuteIcon]);

const playPauseButton = useMemo(() => {
const icon = isPaused ? playIcon : pauseIcon;
Expand Down
8 changes: 5 additions & 3 deletions src/components/ReactPlayer/ReactPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface ReactPlayerBlockProps
showPreview?: boolean;
onClickPreview?: () => void;
height?: number;
ratio?: number;
children?: React.ReactNode;
}

Expand Down Expand Up @@ -83,6 +84,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
analyticsEvents,
height,
ariaLabel,
ratio,
} = props;

const {
Expand Down Expand Up @@ -177,7 +179,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
parseFloat(paddingRight);

setWidth(newWidth);
setCurrentHeight(Math.floor(getHeight(newWidth)));
setCurrentHeight(Math.floor(getHeight(newWidth, ratio)));
}
}, 200);

Expand Down Expand Up @@ -418,8 +420,8 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
},
);

function getHeight(width: number): number {
return (width / 16) * 9;
function getHeight(width: number, ratio: number = 9 / 16): number {
return width * ratio;
}

function getParentElement(element: HTMLElement): HTMLElement {
Expand Down
1 change: 1 addition & 0 deletions src/models/constructor-items/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export type ThemedMediaVideoProps = ThemeSupporting<MediaVideoProps>;
export interface MediaComponentVideoProps extends AnalyticsEventsBase {
video: MediaVideoProps;
height?: number;
ratio?: number;
metrika?: MetrikaVideo;
previewImg?: string;
}
Expand Down

0 comments on commit ca82669

Please sign in to comment.