mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
feat(editor): add animation for switching to edgeless mode firstly (#10021)
Close [BS-2327](https://linear.app/affine-design/issue/BS-2327/page-block-%E5%9C%A8-edgeless-%E5%88%87%E6%8D%A2%E7%BC%A9%E6%94%BE%E5%8A%A8%E7%94%BB) ### What Changes: - Add a zoom animation when switching to edgeless mode firstly - Move viewport record from `sessionStorage` to `localStorage` https://github.com/user-attachments/assets/dac11aab-76bd-44b1-8c0e-4a8a10919841
This commit is contained in:
@@ -365,14 +365,13 @@ export class Viewport {
|
||||
});
|
||||
}
|
||||
|
||||
smoothTranslate(x: number, y: number) {
|
||||
smoothTranslate(x: number, y: number, numSteps = 10) {
|
||||
const { center } = this;
|
||||
const delta = { x: x - center.x, y: y - center.y };
|
||||
const innerSmoothTranslate = () => {
|
||||
if (this._rafId) cancelAnimationFrame(this._rafId);
|
||||
this._rafId = requestAnimationFrame(() => {
|
||||
const rate = 10;
|
||||
const step = { x: delta.x / rate, y: delta.y / rate };
|
||||
const step = { x: delta.x / numSteps, y: delta.y / numSteps };
|
||||
const nextCenter = {
|
||||
x: this.centerX + step.x,
|
||||
y: this.centerY + step.y,
|
||||
@@ -389,15 +388,14 @@ export class Viewport {
|
||||
innerSmoothTranslate();
|
||||
}
|
||||
|
||||
smoothZoom(zoom: number, focusPoint?: IPoint) {
|
||||
smoothZoom(zoom: number, focusPoint?: IPoint, numSteps = 10) {
|
||||
const delta = zoom - this.zoom;
|
||||
if (this._rafId) cancelAnimationFrame(this._rafId);
|
||||
|
||||
const innerSmoothZoom = () => {
|
||||
this._rafId = requestAnimationFrame(() => {
|
||||
const sign = delta > 0 ? 1 : -1;
|
||||
const total = 10;
|
||||
const step = delta / total;
|
||||
const step = delta / numSteps;
|
||||
const nextZoom = cutoff(this.zoom + step, zoom, sign);
|
||||
|
||||
this.setZoom(nextZoom, focusPoint);
|
||||
|
||||
Reference in New Issue
Block a user