Comments (5)
Hi, @HakanKOCAK
react-viewport-list created for one column/row list. Not for grids.
But your case is possible with js.
First, you should check isMobile
in js (with matchMedia() for example) and then chunk items to 4 (for desktop) of 2 (for mobile).
Second, you should render chunks. Each row will render 4 or 2 items.
Will be good to add key={isMobile} for ViewportList to full re-render on isMobile
change.
Code will be like this:
const Grid = ({ items }) => {
const ref = userRef();
const isMobile = useMatchMedia('(max-width: 600px)');
const chunks = useMemo(() => _.chunk(items, isMobile ? 2 : 4), [items, isMobile]);
return (
<div className="scrollable column" ref={ref}>
<ViewportList viewportRef={ref} key={isMedia} items={chunks}>
{(row, index) => (
<div key={index} className="row">
{row.map((item) => <Item key={item.id} data={item} />)}
</div>
)}
</ViewportList>
</div>
);
};
from react-viewport-list.
Hi, @HakanKOCAK
react-viewport-list created for one column/row list. Not for grids.
But your case is possible with js.
First, you should check
isMobile
in js (with matchMedia() for example) and then chunk items to 4 (for desktop) of 2 (for mobile). Second, you should render chunks. Each row will render 4 or 2 items. Will be good to add key={isMobile} for ViewportList to full re-render onisMobile
change.Code will be like this:
const Grid = ({ items }) => { const ref = userRef(); const isMobile = useMatchMedia('(max-width: 600px)'); const chunks = useMemo(() => _.chunk(items, isMobile ? 2 : 4), [items, isMobile]); return ( <div className="scrollable column" ref={ref}> <ViewportList viewportRef={ref} key={isMedia} items={chunks}> {(row, index) => ( <div key={index} className="row"> {row.map((item) => <Item key={item.id} data={item} />)} </div> )} </ViewportList> </div> ); };
Thanks for the response. Though this solution works for listing, it will break the other requirement which is to scroll given category on tab click as you can see in the screenshot. We have to specify itemMinSize but I couldnt find a way around to achieve the perfect scroll to given category.
from react-viewport-list.
You have a list of categories where each category is a list of items, right?
What is a scroll container?
What is a scroll issue? (e.g. wrong position)
Will be good if you share some code
from react-viewport-list.
Seem to be no issue here
from react-viewport-list.
Thanks for your response, there is no issue about the library but it did not meet my requirements(or I wasnt able to implement it). The underlying structure is pretty big and I have to share a lot of code pieces but I dont think its a good idea. I tried scrollToIndex and it was working okay, not perfect since it uses scrollIntoView as base but I have a dynamic header and other elements that are fixed depending on screen size so I have calculate the perfect scrollY position and pass it to scrollToIndex function, since it uses scrollIntoView, cannot pass extra parameters and wasnt able to get the desired output. It might be very special use case but can be added as a feature maybe. Thanks for your time again.
from react-viewport-list.
Related Issues (20)
- Thank you HOT 3
- New items added to bottom of list. After refresh, appeared first. HOT 6
- Incorrect page scrolling behavior when `initialIndex` or `scrollToIndex` is used HOT 4
- Why does it work when height varies? HOT 2
- List items rendered with undefined HOT 2
- Endless Scrolling Loop HOT 28
- scroll to bottom while having async rendering items HOT 2
- Scroll to bottom on initial render HOT 2
- flew wrap not work HOT 1
- Is infinite scroll pagination supported? HOT 1
- Scroll to position HOT 3
- remove spacer in list HOT 3
- Scroll X and Scroll Y and sticky rows and columns HOT 3
- Question regarding CPU usage when idle HOT 7
- Is SSR supported? HOT 8
- Any way to show a dynamic number of columns? HOT 2
- Unexpected scroll jump with initialIndex set to last item HOT 8
- Having trouble getting axis="x" to work HOT 3
- justify-content: flex-end; hides the scroll bar. HOT 2
- Styling is breaking if used in material ui table HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-viewport-list.