2019-10-10 12:21:38 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
export default class GIFV extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
alt: PropTypes.string,
|
2023-02-27 04:13:27 +09:00
|
|
|
lang: PropTypes.string,
|
2019-10-10 12:21:38 +09:00
|
|
|
width: PropTypes.number,
|
|
|
|
height: PropTypes.number,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
loading: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleLoadedData = () => {
|
|
|
|
this.setState({ loading: false });
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2019-10-10 12:21:38 +09:00
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (nextProps.src !== this.props.src) {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick = e => {
|
|
|
|
const { onClick } = this.props;
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
e.stopPropagation();
|
|
|
|
onClick();
|
|
|
|
}
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2019-10-10 12:21:38 +09:00
|
|
|
|
|
|
|
render () {
|
2023-02-27 04:13:27 +09:00
|
|
|
const { src, width, height, alt, lang } = this.props;
|
2019-10-10 12:21:38 +09:00
|
|
|
const { loading } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='gifv' style={{ position: 'relative' }}>
|
|
|
|
{loading && (
|
|
|
|
<canvas
|
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
role='button'
|
|
|
|
tabIndex='0'
|
|
|
|
aria-label={alt}
|
|
|
|
title={alt}
|
2023-02-27 04:13:27 +09:00
|
|
|
lang={lang}
|
2019-10-10 12:21:38 +09:00
|
|
|
onClick={this.handleClick}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<video
|
|
|
|
src={src}
|
|
|
|
role='button'
|
|
|
|
tabIndex='0'
|
|
|
|
aria-label={alt}
|
|
|
|
title={alt}
|
2023-02-27 04:13:27 +09:00
|
|
|
lang={lang}
|
2019-10-10 12:21:38 +09:00
|
|
|
muted
|
|
|
|
loop
|
|
|
|
autoPlay
|
|
|
|
playsInline
|
|
|
|
onClick={this.handleClick}
|
|
|
|
onLoadedData={this.handleLoadedData}
|
|
|
|
style={{ position: loading ? 'absolute' : 'static', top: 0, left: 0 }}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|