mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
chore(core): use fadeBottom animation for center peek (#10072)
close AF-2184, AF-2186 
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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}>
|
||||
|
||||
@@ -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',
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user