Giter VIP home page Giter VIP logo

Comments (7)

naqvitalha avatar naqvitalha commented on July 26, 2024

It is already possible. DataProvider can be extended into something custom. Check the following file: https://github.com/Flipkart/recyclerlistview/blob/master/src/core/dependencies/DataProvider.ts

Inherit DataProvider and override getDataForIndex(). Start using immutable collection instead of array. Let me know if you need further help.

from recyclerlistview.

punksta avatar punksta commented on July 26, 2024

Worked, thanks.
this data: any[] stopped me. Maybe better to have an interface and then make existing DataProvider basic implementation.

from recyclerlistview.

black7375 avatar black7375 commented on July 26, 2024

@naqvitalha have one question.

I looked at the source to override.

public getDataForIndex(index: number): any {
return this._data[index];
}

To redefine the function, need to access the _data, but it is private.

private _data: any[] = [];

What about creating any[], any types to interfaces in generics, abstract functions?

from recyclerlistview.

wxsms avatar wxsms commented on July 26, 2024

@black7375 Use getAllData instead.

from recyclerlistview.

black7375 avatar black7375 commented on July 26, 2024

@wxsms
I asked because I couldn't write a data type like List<T> because of the type of _data(any[]), but I solved the problem by creating it again exclude interface.

Like this.

export abstract class GenericDataProvider<T, K = keyof T> extends BaseDataProvider{
  public rowHasChanged: (r1: T | any, r2: T | any) => boolean;

  // In JS context make sure stable id is a string
  public getStableId: (index: number) => string;
  protected m_firstIndexToProcess: number = 0;
  protected m_size: number = 0;
  protected m_data: K | any = List<T>([]);
  protected m_hasStableIds = false;
  protected m_requiresDataChangeHandling = false;

  constructor(rowHasChanged: (r1: T | any, r2: T | any) => boolean,
              getStableId?:  (index: number) => string) {
    super(rowHasChanged, getStableId);
    this.rowHasChanged = rowHasChanged;
    if (getStableId) {
      this.getStableId = getStableId;
      this.m_hasStableIds = true;
    } else {
      this.getStableId = (index) => index.toString();
    }
  }

  public abstract newInstance(
    rowHasChanged: (r1: T, r2: T) => boolean,
    getStableId?: (index: number) => string    ): GenericDataProvider<T, K>;
  public abstract getDataForIndex(index: number): T | undefined;
  public abstract cloneWithRows(newData: K | any,
                    firstModifiedIndex?: number): DataProvider;

  public getAllData(): K | any {
    return this.m_data;
  }
...

from recyclerlistview.

wxsms avatar wxsms commented on July 26, 2024

@punksta Hi, could you pls show your solution here? I've tried the solution provided by @naqvitalha , by it doesn't work. It just show a blank screen without any errors. Thank you in advance!

from recyclerlistview.

wxsms avatar wxsms commented on July 26, 2024

Never mind. found out that I have to override not only getDataForIndex , but also newInstance and cloneWithRows. and should extends BaseDataProvider, not DataProvider. This is not frinedly enough 😢 . But anyway, works now.

from recyclerlistview.

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.