Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

If VirtualScroll is wrapped inside AutoSize dragging an item doesn't trigger scroll #5

Closed
ahmedelgabri opened this issue Jun 10, 2016 · 6 comments

Comments

@ahmedelgabri
Copy link
Contributor

ahmedelgabri commented Jun 10, 2016

Awesome job @clauderic 馃憤

I'm having a huge list that I'm using react-virtualized but if I want the width to be dynamic, for this I must wrap it with AutoSize You should already know this 馃槉

class VirtualList extends Component {
  render() {
    const { items } = this.props;

    return (
      <AutoSizer disableHeight>
        {({ width }) => (
          <VirtualScroll
            ref="VirtualScroll"
            estimatedRowSize={70}
            rowHeight={70}
            rowRenderer={({ index }) => {
              const { product } = items[index];
              return <SortableItem index={index} product={product} />;
            }}
            rowCount={items.length}
            width={width}
            height={500}
          />
        )}
      </AutoSizer>
    );
  }
}

So when I do, I lose the ability to scroll while dragging & item, any hints how to fix this?

@ahmedelgabri
Copy link
Contributor Author

Managed to solve it by wrapping the <Sortablelist> itself with <AutoSizer/> and passing the width to the <VirtualScroll />

<AutoSizer disableHeight>
  {({ width }) => (
    <SortableList ref="SortableList" items={items} width={width} onSortEnd={this.onSortEnd} />
  )}
</AutoSizer>
class VirtualList extends Component {
  render() {
    const { items, width } = this.props;

    return (
          <VirtualScroll
            ref="VirtualScroll"
            estimatedRowSize={70}
            rowHeight={70}
            rowRenderer={({ index }) => {
              const { product } = items[index];
              return <SortableItem index={index} product={product} />;
            }}
            rowCount={items.length}
            width={width}
            height={500}
          />
    );
  }
}

@clauderic
Copy link
Owner

Sounds like you've solved this :)

@burtyish
Copy link

burtyish commented Sep 5, 2016

Hi @ahmedelgabri, it may be the late hour but I can't seem to grok your solution.
There's the Autosizer'd SortableList and then there's the VirtualScroll.
How is the end result composed?
I know this ticket is pretty stale, but would you (or anyone else for that matter) mind expanding on your answer?

Thanks!

@ahmedelgabri
Copy link
Contributor Author

Simply the hierarchy for the solution looks like this and width is getting passed from top to bottom, I hope it makes sense.

AutoSizer                 
|__SortableList         
     |__ VirtualList

@burtyish
Copy link

burtyish commented Sep 6, 2016

Ah, thanks @ahmedelgabri, I really appreciate your quick answer. I was missing that you apparently also had:

const SortableList = SortableContainer(VirtualList, {withRef: true});

Unfortunately, after following the pattern you described, I still have two big problems:

1. this.refs.SortableList is undefined (I need that in my onSortEnd function)
2. I still can't get autoscroll to work 馃

Update: I fixed the first problem by adding a ref to Autosizer: <AutoSizer ref="AutoSizer"> and then accessing this.refs.AutoSizer.refs.SortableList

@mitchellwarr
Copy link

Thank you for this Issue thread, it fixed my issue. I suggest adding this to the docs somewhere as I only found this fix thanks to Google after reading through the docs and examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants