Giter Site home page Giter Site logo

Comments (5)

oleggrishechkin avatar oleggrishechkin commented on May 27, 2024 1

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.

HakanKOCAK avatar HakanKOCAK commented on May 27, 2024

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>
   );
};

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.

Screen Shot 2022-09-06 at 10 47 55

from react-viewport-list.

oleggrishechkin avatar oleggrishechkin commented on May 27, 2024

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.

oleggrishechkin avatar oleggrishechkin commented on May 27, 2024

Seem to be no issue here

from react-viewport-list.

HakanKOCAK avatar HakanKOCAK commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.