Skip to content

Commit

Permalink
fix: animate resize to prevent flickers (#3303)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 authored Nov 15, 2024
1 parent 1f1796d commit 8e5a734
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
1 change: 1 addition & 0 deletions packages/roomkit-react/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { AnimatePresence } from 'framer-motion';
import { TrackWithPeerAndDimensions } from '@100mslive/react-sdk';
import { Box } from '../../../Layout';
// @ts-ignore: No implicit Any
Expand All @@ -9,35 +10,37 @@ export const Grid = React.forwardRef<HTMLDivElement, { tiles: TrackWithPeerAndDi
({ tiles, edgeToEdge }, ref) => {
const videoTileProps = useVideoTileContext();
return (
<Box
ref={ref}
css={{
flex: '1 1 0',
gap: '$4',
display: 'flex',
placeContent: 'center',
alignItems: 'center',
justifyContent: 'center',
flexFlow: 'row wrap',
minHeight: 0,
'@lg': { gap: edgeToEdge ? 0 : '$4' },
}}
>
{tiles?.map(tile => {
return (
<VideoTile
key={tile.track?.id || tile.peer?.id}
width={tile.width}
height={tile.height}
peerId={tile.peer?.id}
trackId={tile.track?.id}
rootCSS={{ padding: 0 }}
objectFit="contain"
{...videoTileProps}
/>
);
})}
</Box>
<AnimatePresence>
<Box
ref={ref}
css={{
flex: '1 1 0',
gap: '$4',
display: 'flex',
placeContent: 'center',
alignItems: 'center',
justifyContent: 'center',
flexFlow: 'row wrap',
minHeight: 0,
'@lg': { gap: edgeToEdge ? 0 : '$4' },
}}
>
{tiles?.map(tile => {
return (
<VideoTile
key={tile.track?.id || tile.peer?.id}
width={tile.width}
height={tile.height}
peerId={tile.peer?.id}
trackId={tile.track?.id}
rootCSS={{ padding: 0 }}
objectFit="contain"
{...videoTileProps}
/>
);
})}
</Box>
</AnimatePresence>
);
},
);
21 changes: 15 additions & 6 deletions packages/roomkit-react/src/VideoTile/StyledVideoTile.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { motion } from 'framer-motion';
import { Box } from '../Layout';
import { styled } from '../Theme';
import { flexCenter } from '../utils';

export const Root = styled('div', {
padding: '0.75rem',
// show videotile context menu on hover
// [`&:hover .tile-menu`]: {
// display: 'inline-block',
// },
});

const MotionRoot = motion(Root);
MotionRoot.defaultProps = {
layout: true,
transition: {
type: 'spring',
stiffness: 300,
damping: 30,
mass: 1,
duration: 0.15,
},
};

const Container = styled('div', {
width: '100%',
height: '100%',
Expand Down Expand Up @@ -128,7 +137,7 @@ const AvatarContainer = styled(Box, {
});

interface VideoTileType {
Root: typeof Root;
Root: typeof MotionRoot;
Container: typeof Container;
Overlay: typeof Overlay;
Info: typeof Info;
Expand All @@ -139,7 +148,7 @@ interface VideoTileType {
}

export const StyledVideoTile: VideoTileType = {
Root,
Root: MotionRoot,
Container,
Overlay,
Info,
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10433,6 +10433,13 @@ fragment-cache@^0.2.1:
dependencies:
map-cache "^0.2.2"

framer-motion@^11.11.0:
version "11.11.9"
resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-11.11.9.tgz#a60ddf5abbd924812df923068628537a5c6ad8b9"
integrity sha512-XpdZseuCrZehdHGuW22zZt3SF5g6AHJHJi7JwQIigOznW4Jg1n0oGPMJQheMaKLC+0rp5gxUKMRYI6ytd3q4RQ==
dependencies:
tslib "^2.4.0"

[email protected]:
version "0.5.2"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
Expand Down

0 comments on commit 8e5a734

Please sign in to comment.