fix(editor): edgeless can't slider with finger (#15091)

fix bug edgeless can't slider with finger 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added mobile immersive edgeless mode with dynamic chrome auto-hide and
tap-gesture controls.
  * Added a mobile zoom ruler UI for edgeless.
* **Bug Fixes**
* Improved iOS rendering/zoom by applying low-zoom survival behavior,
gesture-aware refresh deferral, and effective-DPR canvas scaling.
* Fixed iOS webview zoom/bounce and process-termination reload behavior.
  * Improved placeholder styling with theme-aware colors.
* **Chores**
  * Updated local ignore rules and iOS app build/version configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: DarkSky <darksky2048@gmail.com>
This commit is contained in:
keepClamDown
2026-06-16 21:19:31 +08:00
committed by GitHub
parent c51bdb74de
commit a77d89bb1a
43 changed files with 4749 additions and 273 deletions

View File

@@ -19,6 +19,7 @@ import {
type LocalConnectorElementModel,
type PointStyle,
} from '@blocksuite/affine-model';
import { getAffinePlaceholderFillColor } from '@blocksuite/affine-shared/theme';
import {
getBezierParameters,
type PointLocation,
@@ -253,7 +254,7 @@ function renderLabel(
ctx.setTransform(matrix);
if (renderer.usePlaceholder) {
ctx.fillStyle = 'rgba(200, 200, 200, 0.5)';
ctx.fillStyle = getAffinePlaceholderFillColor(renderer.getColorScheme());
ctx.fillRect(0, 0, w, h);
return; // Skip actual label rendering
}

View File

@@ -10,6 +10,7 @@
"author": "toeverything",
"license": "MIT",
"dependencies": {
"@blocksuite/affine-shared": "workspace:*",
"@blocksuite/global": "workspace:*",
"@blocksuite/std": "workspace:*",
"@blocksuite/store": "workspace:*",

View File

@@ -1,5 +1,10 @@
import {
getAffinePlaceholderFillColor,
getAffinePlaceholderStrokeColor,
inferColorSchemeFromThemeMode,
} from '@blocksuite/affine-shared/theme';
import type { EditorHost, GfxBlockComponent } from '@blocksuite/std';
import { type Viewport } from '@blocksuite/std/gfx';
import { getEffectiveDpr, type Viewport } from '@blocksuite/std/gfx';
import type { BlockModel } from '@blocksuite/store';
import { BlockLayoutHandlersIdentifier } from './layout/block-layout-provider';
@@ -10,9 +15,13 @@ import type {
ViewportLayoutTree,
} from './types';
export function syncCanvasSize(canvas: HTMLCanvasElement, host: HTMLElement) {
export function syncCanvasSize(
canvas: HTMLCanvasElement,
host: HTMLElement,
zoom = 1
) {
const hostRect = host.getBoundingClientRect();
const dpr = window.devicePixelRatio;
const dpr = getEffectiveDpr(zoom);
canvas.style.position = 'absolute';
canvas.style.left = '0px';
canvas.style.top = '0px';
@@ -186,21 +195,21 @@ export function paintPlaceholder(
const ctx = canvas.getContext('2d');
if (!ctx || !layout) return;
const dpr = window.devicePixelRatio;
const dpr = getEffectiveDpr(viewport.zoom);
const { overallRect } = layout;
const layoutViewCoord = viewport.toViewCoord(overallRect.x, overallRect.y);
const offsetX = layoutViewCoord[0];
const offsetY = layoutViewCoord[1];
const colors = [
'rgba(200, 200, 200, 0.7)',
'rgba(180, 180, 180, 0.7)',
'rgba(160, 160, 160, 0.7)',
];
const colorScheme = inferColorSchemeFromThemeMode(
document.documentElement.dataset.theme
);
const fillColor = getAffinePlaceholderFillColor(colorScheme);
const strokeColor = getAffinePlaceholderStrokeColor(colorScheme);
const paintNode = (node: BlockLayoutTreeNode, depth: number = 0) => {
const paintNode = (node: BlockLayoutTreeNode) => {
const { layout: nodeLayout } = node;
ctx.fillStyle = colors[depth % colors.length];
ctx.fillStyle = fillColor;
const rect = nodeLayout.rect;
const x = ((rect.x - overallRect.x) * viewport.zoom + offsetX) * dpr;
const y = ((rect.y - overallRect.y) * viewport.zoom + offsetY) * dpr;
@@ -209,12 +218,12 @@ export function paintPlaceholder(
ctx.fillRect(x, y, width, height);
if (width > 10 && height > 5) {
ctx.strokeStyle = 'rgba(150, 150, 150, 0.3)';
ctx.strokeStyle = strokeColor;
ctx.strokeRect(x, y, width, height);
}
if (node.children.length > 0) {
node.children.forEach(childNode => paintNode(childNode, depth + 1));
node.children.forEach(childNode => paintNode(childNode));
}
};

View File

@@ -1,11 +1,14 @@
import type { Container } from '@blocksuite/global/di';
import { DisposableGroup } from '@blocksuite/global/disposable';
import { IS_IOS } from '@blocksuite/global/env';
import { ConfigExtensionFactory } from '@blocksuite/std';
import {
getEffectiveDpr,
type GfxController,
GfxExtension,
GfxExtensionIdentifier,
type GfxViewportElement,
viewportRuntimeConfig,
} from '@blocksuite/std/gfx';
import {
BehaviorSubject,
@@ -34,6 +37,26 @@ import type {
} from './types';
const debug = false; // Toggle for debug logs
const IOS_LOW_ZOOM_SURVIVAL_THRESHOLD = 0.5;
export function shouldPreferBitmapCacheDuringLowZoomGesture(params: {
isIOS: boolean;
zoom: number;
hasBitmap: boolean;
}) {
return (
params.isIOS &&
params.zoom <= IOS_LOW_ZOOM_SURVIVAL_THRESHOLD &&
params.hasBitmap
);
}
export function shouldIdleTurboBlocksDuringZooming(params: {
isIOS: boolean;
zoom: number;
}) {
return !(params.isIOS && params.zoom <= IOS_LOW_ZOOM_SURVIVAL_THRESHOLD);
}
const defaultOptions = {
zoomThreshold: 1, // With high enough zoom, fallback to DOM rendering
@@ -147,7 +170,7 @@ export class ViewportTurboRendererExtension extends GfxExtension {
this.viewport.elementReady.pipe(take(1)).subscribe(element => {
this.viewportElement = element;
syncCanvasSize(this.canvas, this.std.host);
syncCanvasSize(this.canvas, this.std.host, this.viewport.zoom);
this.state$.next('pending');
this.disposables.add(
@@ -156,6 +179,12 @@ export class ViewportTurboRendererExtension extends GfxExtension {
this.disposables.add(
this.viewport.viewportUpdated.subscribe(() => {
if (
this.viewport.SKIP_REFRESH_DURING_GESTURE &&
(this.viewport.panning$.value || this.viewport.zooming$.value)
) {
return;
}
this.refresh().catch(console.error);
})
);
@@ -166,7 +195,9 @@ export class ViewportTurboRendererExtension extends GfxExtension {
tap(isZooming => {
this.debugLog(`Zooming signal changed: ${isZooming}`);
if (isZooming) {
this.state$.next('zooming');
if (!this.viewport.SKIP_REFRESH_DURING_GESTURE) {
this.state$.next('zooming');
}
} else if (this.state$.value === 'zooming') {
this.clearOptimizedBlocks();
this.isRecentlyZoomed$.next(true);
@@ -183,6 +214,45 @@ export class ViewportTurboRendererExtension extends GfxExtension {
)
.subscribe()
);
// Post-gesture refresh for SKIP mode
if (this.viewport.SKIP_REFRESH_DURING_GESTURE) {
let pendingTimerId: ReturnType<typeof setTimeout> | null = null;
const cancelRefresh = () => {
if (pendingTimerId !== null) {
clearTimeout(pendingTimerId);
pendingTimerId = null;
}
};
const scheduleRefresh = () => {
cancelRefresh();
pendingTimerId = setTimeout(() => {
pendingTimerId = null;
if (
!this.viewport.panning$.value &&
!this.viewport.zooming$.value
) {
this.refresh().catch(console.error);
}
}, viewportRuntimeConfig.POST_GESTURE_REFRESH_DELAY);
};
this.disposables.add(
this.viewport.panning$.subscribe(panning => {
if (panning) cancelRefresh();
else if (!this.viewport.zooming$.value) scheduleRefresh();
})
);
this.disposables.add(
this.viewport.zooming$.subscribe(zooming => {
if (zooming) cancelRefresh();
else if (!this.viewport.panning$.value) scheduleRefresh();
})
);
this.disposables.add({ dispose: cancelRefresh });
}
});
// Handle selection and block updates
@@ -235,10 +305,22 @@ export class ViewportTurboRendererExtension extends GfxExtension {
nextState = 'pending';
this.clearOptimizedBlocks();
} else if (this.isZooming()) {
this.debugLog('Currently zooming, using placeholder rendering');
nextState = 'zooming';
this.paintPlaceholder();
this.updateOptimizedBlocks();
if (
shouldPreferBitmapCacheDuringLowZoomGesture({
isIOS: IS_IOS,
zoom: this.viewport.zoom,
hasBitmap: !!this.bitmap,
})
) {
this.debugLog('Currently zooming, reusing cached bitmap');
this.clearOptimizedBlocks();
this.drawCachedBitmap();
} else {
this.debugLog('Currently zooming, using placeholder rendering');
this.paintPlaceholder();
this.updateOptimizedBlocks();
}
} else if (this.canUseBitmapCache()) {
this.debugLog('Using cached bitmap');
nextState = 'ready';
@@ -286,7 +368,7 @@ export class ViewportTurboRendererExtension extends GfxExtension {
}
const layout = this.layoutCache;
const dpr = window.devicePixelRatio;
const dpr = getEffectiveDpr(this.viewport.zoom);
const currentVersion = this.layoutVersion;
this.debugLog(`Requesting bitmap painting (version=${currentVersion})`);
@@ -368,12 +450,14 @@ export class ViewportTurboRendererExtension extends GfxExtension {
layout.overallRect.y
);
const dpr = getEffectiveDpr(this.viewport.zoom);
ctx.drawImage(
bitmap,
layoutViewCoord[0] * window.devicePixelRatio,
layoutViewCoord[1] * window.devicePixelRatio,
layout.overallRect.w * window.devicePixelRatio * this.viewport.zoom,
layout.overallRect.h * window.devicePixelRatio * this.viewport.zoom
layoutViewCoord[0] * dpr,
layoutViewCoord[1] * dpr,
layout.overallRect.w * dpr * this.viewport.zoom,
layout.overallRect.h * dpr * this.viewport.zoom
);
this.debugLog('Bitmap drawn to canvas');
@@ -389,6 +473,16 @@ export class ViewportTurboRendererExtension extends GfxExtension {
private updateOptimizedBlocks() {
if (!this.canOptimize()) return;
if (
!shouldIdleTurboBlocksDuringZooming({
isIOS: IS_IOS,
zoom: this.viewport.zoom,
})
) {
this.clearOptimizedBlocks();
return;
}
requestAnimationFrame(() => {
if (!this.viewportElement || !this.layoutCache) return;
const blockElements = this.viewportElement.getModelsInViewport();
@@ -416,7 +510,7 @@ export class ViewportTurboRendererExtension extends GfxExtension {
private handleResize() {
this.debugLog('Container resized, syncing canvas size');
syncCanvasSize(this.canvas, this.std.host);
syncCanvasSize(this.canvas, this.std.host, this.viewport.zoom);
this.invalidate();
this.refresh$.next();
}

View File

@@ -7,6 +7,7 @@
},
"include": ["./src"],
"references": [
{ "path": "../../shared" },
{ "path": "../../../framework/global" },
{ "path": "../../../framework/std" },
{ "path": "../../../framework/store" }