ISSUE-053 - Have worked out the scaled video feed element.
Didn't have to do anything to position the element, which made me pretty happy. I assumed I'd have to do some annoying amount of finagling to get it to position correctly in the frame. It just worked. Lucky me.
This commit is contained in:
1 parent
40292620d6
commit
d083df7245
4 files changed
+99
-4
No files matched your search
@@ -1,9 +1,42 @@
|
||||
import { VideoFeedFrame, BackgroundImageDiv } from "./styles";
|
||||
import useMeasure from "react-use-measure";
|
||||
|
||||
import { calculateFitSize, calculateScale } from "../../../utils/styling";
|
||||
import { theme } from "../../../shared/theme";
|
||||
|
||||
import { VideoFeedFrame, BackgroundImageDiv, DimensionsSpan, BroadcastLayout } from "./styles";
|
||||
import { MockupBlock } from "../../Common/MockupBlock.styled";
|
||||
|
||||
import bg from "../../../public/images/misc/bg-standin.jpg";
|
||||
|
||||
export default function VideoFeed() {
|
||||
return <VideoFeedFrame centered>
|
||||
<BackgroundImageDiv src={bg} />
|
||||
</VideoFeedFrame>;
|
||||
const [frameRef, {
|
||||
height: frameHeight,
|
||||
width: frameWidth,
|
||||
}] = useMeasure();
|
||||
|
||||
const {
|
||||
dimensionsWidthPx: broadcastWidth,
|
||||
dimensionsHeightPx: broadcastHeight,
|
||||
} = theme.broadcast;
|
||||
|
||||
const [layoutWidth, layoutHeight] = calculateFitSize(frameWidth, frameHeight,
|
||||
[broadcastWidth, broadcastHeight]);
|
||||
const layoutScale = calculateScale(layoutWidth, layoutHeight,
|
||||
[broadcastWidth, broadcastHeight]);
|
||||
|
||||
return (
|
||||
<VideoFeedFrame centered ref={frameRef}>
|
||||
<DimensionsSpan>
|
||||
{Math.floor(frameWidth)} x {Math.floor(frameHeight)}px
|
||||
</DimensionsSpan>
|
||||
<BackgroundImageDiv src={bg} />
|
||||
<BroadcastLayout width={broadcastWidth} height={broadcastHeight} scale={layoutScale} >
|
||||
<MockupBlock
|
||||
width="300px"
|
||||
height="900px"
|
||||
color="grey"
|
||||
/>
|
||||
</BroadcastLayout>
|
||||
</VideoFeedFrame>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import styled, { css } from "styled-components/macro";
|
||||
|
||||
import { Fraction, Px } from "../../../types/style";
|
||||
|
||||
type VideoFeedFrameProps = {
|
||||
centered?: boolean,
|
||||
};
|
||||
export const VideoFeedFrame = styled.div<VideoFeedFrameProps>`
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: ${p => p.theme.colors.videoFrameBG};
|
||||
@@ -20,6 +23,19 @@ export const VideoFeedFrame = styled.div<VideoFeedFrameProps>`
|
||||
`}
|
||||
`;
|
||||
|
||||
type BroadcastLayoutProps = {
|
||||
height: Px,
|
||||
width: Px,
|
||||
scale: Fraction,
|
||||
};
|
||||
export const BroadcastLayout = styled.div.attrs<BroadcastLayoutProps>(({
|
||||
height,
|
||||
width,
|
||||
scale,
|
||||
}) => ({ style: { height, width, transform: `scale(${scale})` } }))<BroadcastLayoutProps>`
|
||||
position: absolute;
|
||||
`;
|
||||
|
||||
export const BackgroundImage = styled.img`
|
||||
height: 100%;
|
||||
max-width: 100%;
|
||||
@@ -37,3 +53,11 @@ export const BackgroundImageDiv = styled.div<BackgroundImageDivProps>`
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0% 50%;
|
||||
`;
|
||||
|
||||
export const DimensionsSpan = styled.span`
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 10px;
|
||||
color: ${p => p.theme.colors.textWhite};
|
||||
font-family: ${p => p.theme.fonts.f1Regular};
|
||||
`;
|
||||
Reference in new issue
Block a user