-
-
Notifications
You must be signed in to change notification settings - Fork 205
Open
Description
Hi guys,
Could you please provide an example of how to use ScrollBox (https://pixijs.io/ui/ScrollBox.html) with Pixi React?
Currently, I have the following:
const App = () => {
const containerRef = useRef();
return (
<div ref={containerRef} className="h-full w-full">
<Application
className="h-full w-full"
resizeTo={containerRef}
resolution={window.devicePixelRatio}
autoStart
autoDensity
sharedTicker
antialias
>
<GridRenderer items={...} />
</Application>
</div>
);
};
and
const GridRenderer = ({ items }) => {
const { app } = useApplication();
const scrollRef = useRef(null);
const itemRefs = useRef([]);
useEffect(() => {
const box = scrollRef.current;
box.removeItems();
const refs = itemRefs.current;
box.addItems(refs);
box.resize(true);
}, [items, app.screen.width, app.screen.height]);
return (
<pixiScrollBox
ref={scrollRef}
width={app.screen.width}
height={app.screen.height}
elementsMargin={1}
>
{items.map((props, i) => (
<GridItem ref={el => { itemRefs.current[i] = el; }} key={i} {...props} />
))}
</pixiScrollBox>
);
};
So
-
I have to use useEffect to move items into the scrollable area, which feels a bit hacky and causes bugs, e.g. resizing makes the scroll position get lost, and adding new items resets it as well.
-
How can I resize the ScrollBox when the Application's dimensions change and preserve the current scroll position?
Metadata
Metadata
Assignees
Labels
No labels