mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-22 05:39:20 +01:00
Fix Flash of Enlarged Image (FOEI)
Let's see if this works!
This commit is contained in:
parent
145816d884
commit
885f23d405
1 changed files with 25 additions and 2 deletions
|
@ -1,5 +1,11 @@
|
||||||
import { getBlurHashAverageColor } from 'fast-blurhash';
|
import { getBlurHashAverageColor } from 'fast-blurhash';
|
||||||
import { useCallback, useMemo, useRef, useState } from 'preact/hooks';
|
import {
|
||||||
|
useCallback,
|
||||||
|
useLayoutEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'preact/hooks';
|
||||||
import QuickPinchZoom, { make3dTransformValue } from 'react-quick-pinch-zoom';
|
import QuickPinchZoom, { make3dTransformValue } from 'react-quick-pinch-zoom';
|
||||||
|
|
||||||
import Icon from './icon';
|
import Icon from './icon';
|
||||||
|
@ -95,16 +101,33 @@ function Media({ media, to, showOriginal, autoAnimate, onClick = () => {} }) {
|
||||||
[to],
|
[to],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (type === 'image' || (type === 'unknown' && previewUrl && url)) {
|
const isImage = type === 'image' || (type === 'unknown' && previewUrl);
|
||||||
|
|
||||||
|
const parentRef = useRef();
|
||||||
|
const [imageSmallerThanParent, setImageSmallerThanParent] = useState(false);
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (!isImage) return;
|
||||||
|
if (!showOriginal) return;
|
||||||
|
if (!parentRef.current) return;
|
||||||
|
const { offsetWidth, offsetHeight } = parentRef.current;
|
||||||
|
const smaller = width < offsetWidth && height < offsetHeight;
|
||||||
|
if (smaller) setImageSmallerThanParent(smaller);
|
||||||
|
}, [width, height]);
|
||||||
|
|
||||||
|
if (isImage) {
|
||||||
// Note: type: unknown might not have width/height
|
// Note: type: unknown might not have width/height
|
||||||
quickPinchZoomProps.containerProps.style.display = 'inherit';
|
quickPinchZoomProps.containerProps.style.display = 'inherit';
|
||||||
return (
|
return (
|
||||||
<Parent
|
<Parent
|
||||||
|
ref={parentRef}
|
||||||
class={`media media-image`}
|
class={`media media-image`}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
style={
|
style={
|
||||||
showOriginal && {
|
showOriginal && {
|
||||||
backgroundImage: `url(${previewUrl})`,
|
backgroundImage: `url(${previewUrl})`,
|
||||||
|
backgroundSize: imageSmallerThanParent
|
||||||
|
? `${width}px ${height}px`
|
||||||
|
: undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue