Fix autoPlayGif
This commit is contained in:
parent
2319d9f080
commit
4505e3931a
2 changed files with 53 additions and 5 deletions
|
@ -61,7 +61,8 @@ class Item extends React.PureComponent {
|
||||||
|
|
||||||
hoverToPlay() {
|
hoverToPlay() {
|
||||||
const { attachment, autoPlayGif } = this.props;
|
const { attachment, autoPlayGif } = this.props;
|
||||||
return !autoPlayGif && attachment.get('type') === 'gifv';
|
return !autoPlayGif &&
|
||||||
|
(attachment.get('type') === 'gifv' || attachment.getIn(['pleroma', 'mime_type']) === 'image/gif');
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick = (e) => {
|
handleClick = (e) => {
|
||||||
|
@ -72,7 +73,7 @@ class Item extends React.PureComponent {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
} else {
|
} else {
|
||||||
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
||||||
if (this.hoverToPlay()) {
|
if (!this.canvas && this.hoverToPlay()) {
|
||||||
e.target.pause();
|
e.target.pause();
|
||||||
e.target.currentTime = 0;
|
e.target.currentTime = 0;
|
||||||
}
|
}
|
||||||
|
@ -112,8 +113,19 @@ class Item extends React.PureComponent {
|
||||||
this.canvas = c;
|
this.canvas = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setImageRef = i => {
|
||||||
|
this.image = i;
|
||||||
|
}
|
||||||
|
|
||||||
handleImageLoad = () => {
|
handleImageLoad = () => {
|
||||||
this.setState({ loaded: true });
|
this.setState({ loaded: true });
|
||||||
|
if (this.hoverToPlay()) {
|
||||||
|
const image = this.image;
|
||||||
|
const canvas = this.canvas;
|
||||||
|
canvas.width = image.naturalWidth;
|
||||||
|
canvas.height = image.naturalHeight;
|
||||||
|
canvas.getContext('2d').drawImage(image, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -168,7 +180,7 @@ class Item extends React.PureComponent {
|
||||||
|
|
||||||
thumbnail = (
|
thumbnail = (
|
||||||
<a
|
<a
|
||||||
className='media-gallery__item-thumbnail'
|
className={classNames('media-gallery__item-thumbnail', { 'media-gallery__item-thumbnail--play-on-hover': this.hoverToPlay() })}
|
||||||
href={attachment.get('remote_url') || originalUrl}
|
href={attachment.get('remote_url') || originalUrl}
|
||||||
onClick={this.handleClick}
|
onClick={this.handleClick}
|
||||||
target='_blank'
|
target='_blank'
|
||||||
|
@ -181,7 +193,9 @@ class Item extends React.PureComponent {
|
||||||
title={attachment.get('description')}
|
title={attachment.get('description')}
|
||||||
style={{ objectPosition: `${x}% ${y}%` }}
|
style={{ objectPosition: `${x}% ${y}%` }}
|
||||||
onLoad={this.handleImageLoad}
|
onLoad={this.handleImageLoad}
|
||||||
|
ref={this.setImageRef}
|
||||||
/>
|
/>
|
||||||
|
{this.hoverToPlay() && <canvas ref={this.setCanvasRef} style={{ objectPosition: `${x}% ${y}%` }} />}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
} else if (attachment.get('type') === 'gifv') {
|
} else if (attachment.get('type') === 'gifv') {
|
||||||
|
|
|
@ -3525,14 +3525,48 @@ a.status-card.compact:hover {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
||||||
&,
|
&,
|
||||||
img {
|
img,
|
||||||
|
canvas {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
img,
|
||||||
|
canvas {
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--play-on-hover {
|
||||||
|
&::before {
|
||||||
|
content: 'GIF';
|
||||||
|
position: absolute;
|
||||||
|
color: $primary-text-color;
|
||||||
|
background: rgba($base-overlay-background, 0.5);
|
||||||
|
bottom: 6px;
|
||||||
|
left: 6px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 2px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 0.9;
|
||||||
|
transition: opacity 0.1s ease;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
img,
|
||||||
|
&:hover::before {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover img {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.media-gallery__preview {
|
.media-gallery__preview {
|
||||||
|
|
Loading…
Reference in a new issue