Skip to content

Commit

Permalink
NFT collection view: animation/image (#2202)
Browse files Browse the repository at this point in the history
Fixes #2196
  • Loading branch information
tom2drum authored Sep 6, 2024
1 parent 6ef6e39 commit fc1deed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ui/shared/nft/NftMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const NftMedia = ({ imageUrl, animationUrl, className, isLoading, withFullscreen

switch (type) {
case 'video':
return <NftVideo { ...props } autoPlay={ autoplayVideo }/>;
return <NftVideo { ...props } autoPlay={ autoplayVideo } poster={ imageUrl || undefined }/>;
case 'html':
return <NftHtml { ...props }/>;
case 'image':
Expand Down
17 changes: 16 additions & 1 deletion ui/shared/nft/NftVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ import { mediaStyleProps, videoPlayProps } from './utils';

interface Props {
src: string;
poster?: string;
autoPlay?: boolean;
onLoad: () => void;
onError: () => void;
onClick?: () => void;
}

const NftVideo = ({ src, autoPlay = true, onLoad, onError, onClick }: Props) => {
const NftVideo = ({ src, poster, autoPlay = true, onLoad, onError, onClick }: Props) => {
const ref = React.useRef<HTMLVideoElement>(null);

const handleMouseEnter = React.useCallback(() => {
!autoPlay && ref.current?.play();
}, [ autoPlay ]);

const handleMouseLeave = React.useCallback(() => {
!autoPlay && ref.current?.pause();
}, [ autoPlay ]);

return (
<chakra.video
ref={ ref }
{ ...videoPlayProps }
autoPlay={ autoPlay }
poster={ poster }
src={ src }
onCanPlayThrough={ onLoad }
onError={ onError }
borderRadius="md"
onClick={ onClick }
onMouseEnter={ handleMouseEnter }
onMouseLeave={ handleMouseLeave }
{ ...mediaStyleProps }
/>
);
Expand Down

0 comments on commit fc1deed

Please sign in to comment.