listen editor capture scroll event to update mask coordinates system

This commit is contained in:
Bowen Tan 2022-05-18 17:52:05 +08:00
parent 7fe0cb8343
commit 2c71f9b2bd
4 changed files with 13 additions and 8 deletions

View File

@ -160,8 +160,6 @@ export const Editor: React.FC<Props> = observer(
flexDirection="column"
width="full"
height="full"
overflow="auto"
padding="20px"
transform={`scale(${scale / 100})`}
position="relative"
>

View File

@ -132,6 +132,10 @@ export const EditorMask: React.FC<Props> = observer((props: Props) => {
observeResize(eleMap);
updateCoordinateSystem(eleMap);
});
eventBus.on('captureEditorScroll', () => {
updateCoordinateSystem(eleMap);
});
}, [eleMap, eventBus, observeResize, updateCoordinateSystem]);
// listen elements resize and update coordinates

View File

@ -30,6 +30,7 @@ export const EditorMaskWrapper: React.FC<Props> = observer(props => {
const onScroll = () => {
if (wrapperRef.current) {
setScrollOffset([wrapperRef.current.scrollLeft, wrapperRef.current.scrollTop]);
eventBus.send('captureEditorScroll');
}
};
@ -74,17 +75,18 @@ export const EditorMaskWrapper: React.FC<Props> = observer(props => {
<Box
id="editor-mask-wrapper"
width="full"
height="0"
flex="1"
overflow="visible"
overflow="auto"
position="relative"
padding="20px"
// some components stop click event propagation, so here we should capture onClick
onClickCapture={onClick}
onMouseMove={onMouseMove}
onMouseLeave={onMouseLeave}
onDragOver={onDragOver}
onDrop={onDrop}
onScroll={onScroll}
// here we use capture to detect all the components and their children's scroll event
// because every scroll event may change their children's location in coordinates system
onScrollCapture={onScroll}
ref={wrapperRef}
>
{children}

View File

@ -13,6 +13,7 @@ export type EventNames = {
// it is only used for some operations' side effect
selectComponent: string;
HTMLElementsUpdated: undefined;
captureEditorScroll: undefined;
};
export const initEventBus = () => {
@ -22,6 +23,6 @@ export const initEventBus = () => {
off: emitter.off,
send: emitter.emit,
};
}
};
export type EventBusType = ReturnType<typeof initEventBus>
export type EventBusType = ReturnType<typeof initEventBus>;