fix(core): peek view animation (#8858)
This commit is contained in:
@@ -220,10 +220,10 @@ export type PeekViewMode = 'full' | 'fit' | 'max';
|
|||||||
export class PeekViewEntity extends Entity {
|
export class PeekViewEntity extends Entity {
|
||||||
private readonly _active$ = new LiveData<ActivePeekView | null>(null);
|
private readonly _active$ = new LiveData<ActivePeekView | null>(null);
|
||||||
private readonly _show$ = new LiveData<{
|
private readonly _show$ = new LiveData<{
|
||||||
animation: PeekViewAnimation;
|
animation: boolean;
|
||||||
value: boolean;
|
value: boolean;
|
||||||
}>({
|
}>({
|
||||||
animation: 'zoom',
|
animation: true,
|
||||||
value: false,
|
value: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ export class PeekViewEntity extends Entity {
|
|||||||
this._active$.next({ target, info: resolvedInfo });
|
this._active$.next({ target, info: resolvedInfo });
|
||||||
this._show$.next({
|
this._show$.next({
|
||||||
value: true,
|
value: true,
|
||||||
animation: target.element ? 'zoom' : 'fade',
|
animation: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (abortSignal) {
|
if (abortSignal) {
|
||||||
@@ -281,10 +281,10 @@ export class PeekViewEntity extends Entity {
|
|||||||
return firstValueFrom(race(this._active$, this.show$).pipe(map(() => {})));
|
return firstValueFrom(race(this._active$, this.show$).pipe(map(() => {})));
|
||||||
};
|
};
|
||||||
|
|
||||||
close = (animation?: PeekViewAnimation) => {
|
close = (animation = true) => {
|
||||||
this._show$.next({
|
this._show$.next({
|
||||||
value: false,
|
value: false,
|
||||||
animation: animation ?? this._show$.value.animation,
|
animation,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,24 @@ export const PeekViewModalContainer = forwardRef<
|
|||||||
contentWrapper?: AnimeParams;
|
contentWrapper?: AnimeParams;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
|
// if target has no bounding client rect,
|
||||||
|
// find its parent that has bounding client rect
|
||||||
|
let iteration = 0;
|
||||||
|
while (
|
||||||
|
target &&
|
||||||
|
!target.getBoundingClientRect().width &&
|
||||||
|
iteration < 10
|
||||||
|
) {
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
target = target.parentElement || undefined;
|
||||||
|
iteration++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
// fallback to fade animation
|
||||||
|
return animateFade(!!zoomIn);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise<void>(resolve => {
|
return new Promise<void>(resolve => {
|
||||||
const contentClip = contentClipRef.current;
|
const contentClip = contentClipRef.current;
|
||||||
const content = contentRef.current;
|
const content = contentRef.current;
|
||||||
@@ -130,23 +148,6 @@ export const PeekViewModalContainer = forwardRef<
|
|||||||
const targets = contentClip;
|
const targets = contentClip;
|
||||||
const lockSizeEl = content;
|
const lockSizeEl = content;
|
||||||
|
|
||||||
// if target has no bounding client rect, find its parent that has bounding client rect
|
|
||||||
let iteration = 0;
|
|
||||||
while (
|
|
||||||
target &&
|
|
||||||
!target.getBoundingClientRect().width &&
|
|
||||||
iteration < 10
|
|
||||||
) {
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
target = target.parentElement || undefined;
|
|
||||||
iteration++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!target) {
|
|
||||||
resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const from = zoomIn ? target : contentClip;
|
const from = zoomIn ? target : contentClip;
|
||||||
const to = zoomIn ? contentClip : target;
|
const to = zoomIn ? contentClip : target;
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export const DocPeekViewControls = ({
|
|||||||
nameKey: 'open',
|
nameKey: 'open',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
workbench.openDoc(docRef);
|
workbench.openDoc(docRef);
|
||||||
peekView.close('none');
|
peekView.close(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ export const DocPeekViewControls = ({
|
|||||||
name: t['com.affine.peek-view-controls.open-doc-in-new-tab'](),
|
name: t['com.affine.peek-view-controls.open-doc-in-new-tab'](),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
workbench.openDoc(docRef, { at: 'new-tab' });
|
workbench.openDoc(docRef, { at: 'new-tab' });
|
||||||
peekView.close('none');
|
peekView.close(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
BUILD_CONFIG.isElectron && {
|
BUILD_CONFIG.isElectron && {
|
||||||
@@ -131,7 +131,7 @@ export const DocPeekViewControls = ({
|
|||||||
name: t['com.affine.peek-view-controls.open-doc-in-split-view'](),
|
name: t['com.affine.peek-view-controls.open-doc-in-split-view'](),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
workbench.openDoc(docRef, { at: 'beside' });
|
workbench.openDoc(docRef, { at: 'beside' });
|
||||||
peekView.close('none');
|
peekView.close(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -178,7 +178,7 @@ export const AttachmentPeekViewControls = ({
|
|||||||
if (docId && blockId) {
|
if (docId && blockId) {
|
||||||
workbench.openAttachment(docId, blockId);
|
workbench.openAttachment(docId, blockId);
|
||||||
}
|
}
|
||||||
peekView.close('none');
|
peekView.close(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -190,7 +190,7 @@ export const AttachmentPeekViewControls = ({
|
|||||||
if (docId && blockId) {
|
if (docId && blockId) {
|
||||||
workbench.openAttachment(docId, blockId, { at: 'new-tab' });
|
workbench.openAttachment(docId, blockId, { at: 'new-tab' });
|
||||||
}
|
}
|
||||||
peekView.close('none');
|
peekView.close(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
BUILD_CONFIG.isElectron && {
|
BUILD_CONFIG.isElectron && {
|
||||||
@@ -204,7 +204,7 @@ export const AttachmentPeekViewControls = ({
|
|||||||
if (docId && blockId) {
|
if (docId && blockId) {
|
||||||
workbench.openAttachment(docId, blockId, { at: 'beside' });
|
workbench.openAttachment(docId, blockId, { at: 'beside' });
|
||||||
}
|
}
|
||||||
peekView.close('none');
|
peekView.close(false);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
].filter((opt): opt is ControlButtonProps => Boolean(opt));
|
].filter((opt): opt is ControlButtonProps => Boolean(opt));
|
||||||
|
|||||||
@@ -93,6 +93,10 @@ const getRendererProps = (
|
|||||||
? activePeekView.target.element
|
? activePeekView.target.element
|
||||||
: undefined,
|
: undefined,
|
||||||
mode: getMode(activePeekView.info),
|
mode: getMode(activePeekView.info),
|
||||||
|
animation:
|
||||||
|
activePeekView.target.element && getMode(activePeekView.info) !== 'full'
|
||||||
|
? 'zoom'
|
||||||
|
: 'fade',
|
||||||
dialogFrame: activePeekView.info.type !== 'image',
|
dialogFrame: activePeekView.info.type !== 'image',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -124,8 +128,8 @@ export const PeekViewManagerModal = () => {
|
|||||||
return (
|
return (
|
||||||
<PeekViewModalContainer
|
<PeekViewModalContainer
|
||||||
{...renderProps}
|
{...renderProps}
|
||||||
|
animation={show?.animation ? renderProps?.animation : 'none'}
|
||||||
open={!!show?.value && !!renderProps}
|
open={!!show?.value && !!renderProps}
|
||||||
animation={show?.animation || 'none'}
|
|
||||||
onOpenChange={open => {
|
onOpenChange={open => {
|
||||||
if (!open) {
|
if (!open) {
|
||||||
peekViewEntity.close();
|
peekViewEntity.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user