Fix delay problem

This commit is contained in:
Jeremie Pardou-Piquemal 2020-06-07 22:10:56 +02:00
parent 9c6d8c151e
commit b2ad17117c

View file

@ -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(() => {