From 8e5a73468ed4f51cd718bb22096d2522efa637c2 Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Fri, 15 Nov 2024 11:36:46 +0530 Subject: [PATCH] fix: animate resize to prevent flickers (#3303) --- packages/roomkit-react/package.json | 1 + .../Prebuilt/components/VideoLayouts/Grid.tsx | 61 ++++++++++--------- .../src/VideoTile/StyledVideoTile.tsx | 21 +++++-- yarn.lock | 7 +++ 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/packages/roomkit-react/package.json b/packages/roomkit-react/package.json index a816c1bea7..5c6e1c1253 100644 --- a/packages/roomkit-react/package.json +++ b/packages/roomkit-react/package.json @@ -102,6 +102,7 @@ "@stitches/react": "1.3.1-1", "emoji-mart": "^5.2.2", "eventemitter2": "^6.4.9", + "framer-motion":"^11.11.0", "lodash.merge": "^4.6.2", "qrcode.react": "^3.1.0", "react-dom": "^18.2.0", diff --git a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/Grid.tsx b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/Grid.tsx index 751d5eed8b..dfd47f9b0c 100644 --- a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/Grid.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/Grid.tsx @@ -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 @@ -9,35 +10,37 @@ export const Grid = React.forwardRef { const videoTileProps = useVideoTileContext(); return ( - - {tiles?.map(tile => { - return ( - - ); - })} - + + + {tiles?.map(tile => { + return ( + + ); + })} + + ); }, ); diff --git a/packages/roomkit-react/src/VideoTile/StyledVideoTile.tsx b/packages/roomkit-react/src/VideoTile/StyledVideoTile.tsx index a78fa6dbb2..731e33ec8b 100644 --- a/packages/roomkit-react/src/VideoTile/StyledVideoTile.tsx +++ b/packages/roomkit-react/src/VideoTile/StyledVideoTile.tsx @@ -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%', @@ -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; @@ -139,7 +148,7 @@ interface VideoTileType { } export const StyledVideoTile: VideoTileType = { - Root, + Root: MotionRoot, Container, Overlay, Info, diff --git a/yarn.lock b/yarn.lock index a4ab58ed6b..e5e417a61a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" + fresh@0.5.2: version "0.5.2" resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"