From 4505e3931a4c0454a12ec3f5948f9ad2f799ab5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1rbara=20de=20Castro=20Fernandes?= Date: Thu, 28 May 2020 08:16:32 -0300 Subject: [PATCH] Fix autoPlayGif --- app/gabsocial/components/media_gallery.js | 20 ++++++++++-- app/styles/gabsocial/components.scss | 38 +++++++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/app/gabsocial/components/media_gallery.js b/app/gabsocial/components/media_gallery.js index 2b35b81db..50a3bf38b 100644 --- a/app/gabsocial/components/media_gallery.js +++ b/app/gabsocial/components/media_gallery.js @@ -61,7 +61,8 @@ class Item extends React.PureComponent { hoverToPlay() { 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) => { @@ -72,7 +73,7 @@ class Item extends React.PureComponent { e.preventDefault(); } else { if (e.button === 0 && !(e.ctrlKey || e.metaKey)) { - if (this.hoverToPlay()) { + if (!this.canvas && this.hoverToPlay()) { e.target.pause(); e.target.currentTime = 0; } @@ -112,8 +113,19 @@ class Item extends React.PureComponent { this.canvas = c; } + setImageRef = i => { + this.image = i; + } + handleImageLoad = () => { 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() { @@ -168,7 +180,7 @@ class Item extends React.PureComponent { thumbnail = ( + {this.hoverToPlay() && } ); } else if (attachment.get('type') === 'gifv') { diff --git a/app/styles/gabsocial/components.scss b/app/styles/gabsocial/components.scss index 28f9fb638..1886b8adf 100644 --- a/app/styles/gabsocial/components.scss +++ b/app/styles/gabsocial/components.scss @@ -3525,14 +3525,48 @@ a.status-card.compact:hover { z-index: 1; &, - img { + img, + canvas { height: 100%; width: 100%; } - img { + img, + canvas { 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 {