Fix delay problem
This commit is contained in:
parent
9c6d8c151e
commit
b2ad17117c
1 changed files with 7 additions and 11 deletions
|
@ -73,8 +73,7 @@ const getComponent = (type) => {
|
||||||
const Item = ({ id, ...props }) => {
|
const Item = ({ id, ...props }) => {
|
||||||
const [itemState, setItemState] = useRecoilState(ItemWithId(id));
|
const [itemState, setItemState] = useRecoilState(ItemWithId(id));
|
||||||
const [c2c, _] = useC2C();
|
const [c2c, _] = useC2C();
|
||||||
const itemStateRef = React.useRef(itemState);
|
const itemStateRef = React.useRef({ ...itemState });
|
||||||
itemStateRef.current = itemState;
|
|
||||||
const panZoomRotate = useRecoilValue(PanZoomRotateState);
|
const panZoomRotate = useRecoilValue(PanZoomRotateState);
|
||||||
|
|
||||||
React.useState(() => {
|
React.useState(() => {
|
||||||
|
@ -83,16 +82,13 @@ const Item = ({ id, ...props }) => {
|
||||||
|
|
||||||
const onDrag = (e, data) => {
|
const onDrag = (e, data) => {
|
||||||
const { deltaX, deltaY } = data;
|
const { deltaX, deltaY } = data;
|
||||||
|
itemStateRef.current.x += deltaX / panZoomRotate.scale;
|
||||||
|
itemStateRef.current.y += deltaY / panZoomRotate.scale;
|
||||||
|
setItemState({ ...itemStateRef.current });
|
||||||
|
|
||||||
c2c.publish(
|
c2c.publish(`itemStateUpdate.${id}`, {
|
||||||
`itemStateUpdate.${id}`,
|
...itemStateRef.current,
|
||||||
{
|
});
|
||||||
...itemStateRef.current,
|
|
||||||
x: itemStateRef.current.x + deltaX / panZoomRotate.scale,
|
|
||||||
y: itemStateRef.current.y + deltaY / panZoomRotate.scale,
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|
Loading…
Reference in a new issue