mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 11:59:51 +08: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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PeekViewAnimation = 'fade' | 'zoom' | 'none';
|
export type PeekViewAnimation = 'fade' | 'fadeBottom' | 'zoom' | 'none';
|
||||||
export type PeekViewMode = 'full' | 'fit' | 'max';
|
export type PeekViewMode = 'full' | 'fit' | 'max';
|
||||||
|
|
||||||
export class PeekViewEntity extends Entity {
|
export class PeekViewEntity extends Entity {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export const PeekViewModalContainer = forwardRef<
|
|||||||
children,
|
children,
|
||||||
onAnimationStart,
|
onAnimationStart,
|
||||||
onAnimationEnd,
|
onAnimationEnd,
|
||||||
animation = 'zoom',
|
animation = 'fadeBottom',
|
||||||
mode = 'fit',
|
mode = 'fit',
|
||||||
dialogFrame = true,
|
dialogFrame = true,
|
||||||
},
|
},
|
||||||
@@ -310,6 +310,45 @@ export const PeekViewModalContainer = forwardRef<
|
|||||||
[onAnimationEnd, onAnimationStart]
|
[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(() => {
|
useEffect(() => {
|
||||||
const onKeyDown = (e: KeyboardEvent) => {
|
const onKeyDown = (e: KeyboardEvent) => {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
@@ -325,12 +364,22 @@ export const PeekViewModalContainer = forwardRef<
|
|||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (animation === 'zoom') {
|
if (animation === 'zoom') {
|
||||||
open ? animateZoomIn() : animateZoomOut();
|
open ? animateZoomIn() : animateZoomOut();
|
||||||
|
} else if (animation === 'fadeBottom') {
|
||||||
|
animateFadeBottom(open).catch(console.error);
|
||||||
} else if (animation === 'fade') {
|
} else if (animation === 'fade') {
|
||||||
animateFade(open).catch(console.error);
|
animateFade(open).catch(console.error);
|
||||||
} else if (animation === 'none') {
|
} else if (animation === 'none') {
|
||||||
setVtOpen(open);
|
setVtOpen(open);
|
||||||
}
|
}
|
||||||
}, [animateZoomOut, animation, open, target, animateZoomIn, animateFade]);
|
}, [
|
||||||
|
animateZoomOut,
|
||||||
|
animation,
|
||||||
|
open,
|
||||||
|
target,
|
||||||
|
animateZoomIn,
|
||||||
|
animateFade,
|
||||||
|
animateFadeBottom,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PeekViewContext.Provider value={emptyContext}>
|
<PeekViewContext.Provider value={emptyContext}>
|
||||||
|
|||||||
@@ -93,10 +93,7 @@ const getRendererProps = (
|
|||||||
? activePeekView.target.element
|
? activePeekView.target.element
|
||||||
: undefined,
|
: undefined,
|
||||||
mode: getMode(activePeekView.info),
|
mode: getMode(activePeekView.info),
|
||||||
animation:
|
animation: 'fadeBottom',
|
||||||
activePeekView.target.element && getMode(activePeekView.info) !== 'full'
|
|
||||||
? 'zoom'
|
|
||||||
: 'fade',
|
|
||||||
dialogFrame: activePeekView.info.type !== 'image',
|
dialogFrame: activePeekView.info.type !== 'image',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user