chore(core): use fadeBottom animation for center peek (#10072)

close AF-2184, AF-2186

![CleanShot 2025-02-11 at 09.31.39.gif](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/LakojjjzZNf6ogjOVwKE/81ed6601-33ff-4eee-bb35-636a2a27cd85.gif)
This commit is contained in:
CatsJuice
2025-02-13 05:58:09 +00:00
parent 473f8bd167
commit d3e0cd1369
3 changed files with 53 additions and 7 deletions

View File

@@ -217,7 +217,7 @@ function resolvePeekInfoFromPeekTarget(
return;
}
export type PeekViewAnimation = 'fade' | 'zoom' | 'none';
export type PeekViewAnimation = 'fade' | 'fadeBottom' | 'zoom' | 'none';
export type PeekViewMode = 'full' | 'fit' | 'max';
export class PeekViewEntity extends Entity {

View File

@@ -77,7 +77,7 @@ export const PeekViewModalContainer = forwardRef<
children,
onAnimationStart,
onAnimationEnd,
animation = 'zoom',
animation = 'fadeBottom',
mode = 'fit',
dialogFrame = true,
},
@@ -310,6 +310,45 @@ export const PeekViewModalContainer = forwardRef<
[onAnimationEnd, onAnimationStart]
);
const animateFadeBottom = useCallback(
(animateIn: boolean) => {
setAnimeState('animating');
return new Promise<void>(resolve => {
if (animateIn) setVtOpen(true);
setTimeout(() => {
const overlay = overlayRef.current;
const contentClip = contentClipRef.current;
if (!overlay || !contentClip) {
resolve();
return;
}
anime({
targets: [overlay],
opacity: animateIn ? [0, 1] : [1, 0],
easing: 'easeOutQuad',
duration: 230,
});
anime({
targets: [contentClip],
opacity: animateIn ? [0, 1] : [1, 0],
y: animateIn ? ['-2%', '0%'] : ['0%', '-2%'],
scale: animateIn ? [0.96, 1] : [1, 0.96],
easing: 'cubicBezier(0.42, 0, 0.58, 1)',
duration: 230,
complete: () => {
if (!animateIn) setVtOpen(false);
setAnimeState('idle');
onAnimationEnd?.();
resolve();
},
});
});
});
},
[onAnimationEnd]
);
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
@@ -325,12 +364,22 @@ export const PeekViewModalContainer = forwardRef<
useLayoutEffect(() => {
if (animation === 'zoom') {
open ? animateZoomIn() : animateZoomOut();
} else if (animation === 'fadeBottom') {
animateFadeBottom(open).catch(console.error);
} else if (animation === 'fade') {
animateFade(open).catch(console.error);
} else if (animation === 'none') {
setVtOpen(open);
}
}, [animateZoomOut, animation, open, target, animateZoomIn, animateFade]);
}, [
animateZoomOut,
animation,
open,
target,
animateZoomIn,
animateFade,
animateFadeBottom,
]);
return (
<PeekViewContext.Provider value={emptyContext}>

View File

@@ -93,10 +93,7 @@ const getRendererProps = (
? activePeekView.target.element
: undefined,
mode: getMode(activePeekView.info),
animation:
activePeekView.target.element && getMode(activePeekView.info) !== 'full'
? 'zoom'
: 'fade',
animation: 'fadeBottom',
dialogFrame: activePeekView.info.type !== 'image',
};
};