react-native-draggable-flatlist icon indicating copy to clipboard operation
react-native-draggable-flatlist copied to clipboard

Support for RealmDB data ArrayLike<T> type

Open Martinocom opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. I faced a problem where I have a DraggableFlatList and I want to use it with Realm DB. The problem is that the query of Realm DB return ArrayLike<T> object, not the pure type of T[]. It would be great to accept also ArrayLike<T> in order to make the DraggableFlatList compatible without having to convert types every time it's needed.

Describe the solution you'd like The data parameter, data: T[], should become ArrayLike<ItemT> as in the FlatList. But I don't know if internally it would have problems with ordering.

Describe alternatives you've considered An alternative is to have a converter that I can create in order to make ArrayLike<T> become T[]. For example a DraggableFlatList.fromArrayLike<T>(arrayLike: ArrayLike<T>): T[]

Additional context Take this as an example.

export class AppBank extends Realm.Object {
  _id!: Realm.BSON.ObjectId;
  name!: string;

  static generate(name: string) {
    return {
      _id: new Realm.BSON.ObjectId(),
      name,
    };
  }

  static schema = {
    name: 'AppBank',
    primaryKey: '_id',
    properties: {
      _id: 'objectId',
      name: 'string',
    },
  };
}
const { useRealm, useQuery } = RealmConfig;

...

const queryAppBanks = useQuery(AppBank);

...

 <DraggableFlatList
    data={queryAppBanks}
    onDragEnd={({ data }) => // save in DB preserving order }
    ...
/>

Martinocom avatar Mar 09 '23 20:03 Martinocom

Same. Using @ts-expecting-error at the moment.

Also, when binding realm query to the drag list data there is a delay while realm saves that it longer than the animation time resulting in the list jumping back to the original order before being fixed when realm updates and causes a re-render. My work around is putting “cached copy” in state and using the state as drag list data instead of the realm object.

Any way to write onEndDrag() with realm.write() and avoid this render issue?

ajp8164 avatar Jan 21 '24 21:01 ajp8164