Commit fc1deede authored by tom goriunov's avatar tom goriunov Committed by GitHub

NFT collection view: animation/image (#2202)

Fixes #2196
parent 6ef6e39d
...@@ -72,7 +72,7 @@ const NftMedia = ({ imageUrl, animationUrl, className, isLoading, withFullscreen ...@@ -72,7 +72,7 @@ const NftMedia = ({ imageUrl, animationUrl, className, isLoading, withFullscreen
switch (type) { switch (type) {
case 'video': case 'video':
return <NftVideo { ...props } autoPlay={ autoplayVideo }/>; return <NftVideo { ...props } autoPlay={ autoplayVideo } poster={ imageUrl || undefined }/>;
case 'html': case 'html':
return <NftHtml { ...props }/>; return <NftHtml { ...props }/>;
case 'image': case 'image':
......
...@@ -5,22 +5,37 @@ import { mediaStyleProps, videoPlayProps } from './utils'; ...@@ -5,22 +5,37 @@ import { mediaStyleProps, videoPlayProps } from './utils';
interface Props { interface Props {
src: string; src: string;
poster?: string;
autoPlay?: boolean; autoPlay?: boolean;
onLoad: () => void; onLoad: () => void;
onError: () => void; onError: () => void;
onClick?: () => 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 ( return (
<chakra.video <chakra.video
ref={ ref }
{ ...videoPlayProps } { ...videoPlayProps }
autoPlay={ autoPlay } autoPlay={ autoPlay }
poster={ poster }
src={ src } src={ src }
onCanPlayThrough={ onLoad } onCanPlayThrough={ onLoad }
onError={ onError } onError={ onError }
borderRadius="md" borderRadius="md"
onClick={ onClick } onClick={ onClick }
onMouseEnter={ handleMouseEnter }
onMouseLeave={ handleMouseLeave }
{ ...mediaStyleProps } { ...mediaStyleProps }
/> />
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment