question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nested recyclerlistview: contextprovider for individual rows being reused

See original GitHub issue

EDIT: reproduced with an expo snack that appears to be related to standard usage, more so than my particular usage: https://snack.expo.io/BJ2CHQRVm

ORIGINAL: Currently working with a nested recyclerlistview, similar to this project. The difference is that the horizontal and vertical recyclerlistsviews are paginated, meaning their data sources must be updated periodically.

The way I’m currently doing this is to construct the dataproviders and contextproviders for each child row in the parent component. The issue is that the context provider doesn’t seem to pass down correctly in props. When recycling large lists, the context provider reuses the context provider from other uniqueIds. This results in a very unfun scrolling experience - as horizontal scroll positions are not preserved when the component is recycled.

Parent dataprovider:

    this.dataProvider = new DataProvider((r1, r2) => {
      return r1.userId !== r2.userId;
    });

Constructing object for each row for the parent dataProvider:

  getDataForRow = uniqueId => {
    let contextProvider;
    if (this._childrenContextProviders[uniqueId]) {
      contextProvider = this._childrenContextProviders[uniqueId];
    } else {
      this._childrenContextProviders[uniqueId] = new ContextHelper(uniqueId);
      contextProvider = this._childrenContextProviders[uniqueId];
    }

    let dataProvider;
    if (this._childrenDataProviders[uniqueId]) {
      dataProvider = this._childrenDataProviders[uniqueId];
    } else {
      this._childrenDataProviders[uniqueId] = new DataProvider((r1, r2) => {
        return r1 !== r2;
      });
      dataProvider = this._childrenDataProviders[uniqueId];
    }

    return {
      uniqueId: uniqueId,
      contextProvider,
      dataProvider,
    };
  };

Then my renderRow() function looks as follows:

  _rowRenderer = (type, data) => {
    if (data.userId === 'header') {
      return this.renderListHeader();
    }

    return (
      <CellComponent
        uniqueId={data.uniqueId}
        contextProvider={data.contextProvider}
        dataProvider={data.dataProvider}
      />
    );
  };

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
naqvitalhacommented, Aug 3, 2018

It is working fine @alexpareto. Problem is with your log statement

   this.list.scrollToOffset(
          this.props.getCachePosition(this.props.uniqueId),
          0,
          false
        );
  console.log(
          'scrolled from ',
          this.props.getCachePosition(prevProps.uniqueId),
          'to',
          this.list.getCurrentScrollOffset(),
          'supposed to scroll to',
          this.props.getCachePosition(this.props.uniqueId)
        );

Given scrollToOffset is asynchronous this.list.getCurrentScrollOffset() wouldn’t have updated by the time you are logging it. Same is true with DataProvider change.

If I wrap the log part in double rAF it works fine. Check: https://snack.expo.io/B1B0YU-HX

1reaction
alexparetocommented, Aug 3, 2018

Ah yes, you’re right! good catch. Thanks for the help + the component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is nesting React Context Provider and consuming those with ...
What problem can I encounter with a deep nested React context provider? const AllContextProvider = props => { return ( <UserProvider> ...
Read more >
Context preservation on page destruction in React Native and ...
Coming back to the post, to solve the problem of context preservation RecyclerListView uses something called as ContextProvider.
Read more >
Scrollview Smoothscrollby Not Showing The Last Item - ADocLib
RecyclerListView uses cell recycling to reuse views that are no longer visible to from GridView to ListView and vice versa; End reach detections; ......
Read more >
getsn react16 - CSDN
Well, we've said that the value of this input is going to be whatever it is in state. 好吧,我们已经说过,此输入的值将等于状态。
Read more >
packages-2.xml - Openbase
... daily 1 https://openbase.com/js/postcss-nesting daily 1 https://openbase.com/js/ioslib daily 1 https://openbase.com/js/rollup-plugin-cleanup daily 1 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found