muuri-react icon indicating copy to clipboard operation
muuri-react copied to clipboard

Positions of every Item reseted after opening sidepanel or modal window.

Open pfedarenka opened this issue 3 years ago • 3 comments

I'am using muuri for react and all is ok but when i open side panel or some modal windows my layout is breaking for every browser Screenshot 2020-12-16 at 22 41 34 Screenshot 2020-12-16 at 22 41 48

i see that items lost their inline styles and class muuri-item. muuri-react-flag changed as well. maybe someone has already encountered this and will quickly answer, or I will try to reproduce it somewhere separately

"react": "^16.13.1", "styled-components": "^5.1.1",

(sorry for duplicate from https://github.com/haltu/muuri/issues/437)

pfedarenka avatar Dec 16 '20 22:12 pfedarenka

Hi, did you find a solution for this? I'm having a similar problem. Thanks

erosselli avatar Feb 04 '21 16:02 erosselli

Was able to fix this by listening to resize changes on a wrapper div using the intersection observer (❤️ ), and then refreshing the items.

import useResizeObserver from 'use-resize-observer'; // https://github.com/ZeeCoder/use-resize-observer

// ...
const { ref: gridWrapperRef, width, height } = useResizeObserver<HTMLDivElement>();
const muuriGrid = React.useRef();

React.useLayoutEffect(() => {
  if (muuriGrid.current) {
    muuriGrid.current!.refreshItems();
    muuriGrid.current!.layout();
  }
}, [width, height]);

return (
  <div ref={gridWrapperRef}>
    <MuuriComponent ref={muuriGrid}>...</MuuriComponent>
  </div>
);

MZanggl avatar Feb 25 '21 07:02 MZanggl

I have a similar same problem. I've tried @MZanggl 's solution above, but in TypeScript I get the following error on the MuuriComponent ref:

Type 'MutableRefObject<undefined>' is not assignable to type 'Ref<DecoratedGrid> | undefined'.
  Type 'MutableRefObject<undefined>' is not assignable to type 'RefObject<DecoratedGrid>'.
    Types of property 'current' are incompatible.
      Type 'undefined' is not assignable to type 'DecoratedGrid | null'.ts(2322)

claytron5000 avatar Jun 28 '21 14:06 claytron5000