recyclerlistview icon indicating copy to clipboard operation
recyclerlistview copied to clipboard

Support Drag & Drop Reordering?

Open lxcid opened this issue 7 years ago • 19 comments

This project looks awesome! I was wondering if it can do drag & drop reordering?

I'm been searching around and wasn't able to find a good solution to it. Do you think this is possible with this project?

lxcid avatar Apr 05 '18 17:04 lxcid

Yes, if you look at the ViewRenderer class there is scope to accept it from outside as a dependency. If you do that you will then be able to move it using transforms and compute it's current index using the layout information. If you update the data set things will animate in the right positions automatically. For this, however, you will need the stableIds feature which is an open PR right now. I'm working on it and few bugs have to be ironed out.

naqvitalha avatar Apr 05 '18 19:04 naqvitalha

Amazing @naqvitalha thanks for the explanation!

lxcid avatar Apr 08 '18 06:04 lxcid

Hi @naqvitalha, thanks for all the work on the project. We're already using recyclerlistview for our app (react-native) and I'm now working to implement dragging. I'm having a hard time seeing how ViewRenderer can accept a prop to manipulate the position (on master). Has this changed since you initially posted this? Thank you!

bradbyte avatar May 23 '18 12:05 bradbyte

@bradbumbalough You will have to accept ViewRenderer's internal cell externally as a prop. Basically RLV will get one more method called getViewHolderForType() where you return your container. In this component you will implement dragging and compute new positions RLV will animate to.

naqvitalha avatar May 27 '18 14:05 naqvitalha

I'm also currently searching for drag and drop support. It looks like stableIds has been merged, but it looks like getViewHolderForType() is not yet supported?

Edit: Looks like stableIds is part of a beta release. Still digging in 😇

dkpalmer avatar May 28 '18 23:05 dkpalmer

In the travelMate sample app, I added stableIds on v1.4.0-beta.2 and tried to insert an item. RE your comment @naqvitalha If you update the data set things will animate in the right positions automatically, does this require an ItemAnimator?

dkpalmer avatar May 29 '18 00:05 dkpalmer

@dkpalmer Yeah and to just try out set shouldAnimateOnce to false inside code and try inserting items.

naqvitalha avatar May 29 '18 06:05 naqvitalha

@naqvitalha Do you have any references/examples for using an ItemAnimator?

dkpalmer avatar May 29 '18 07:05 dkpalmer

@dkpalmer were you able to find anything on getViewHolderForType? I'm wondering if a fork is needed. I'm able to do some choppy reordering by attaching a PanResponder to the view rendered from rowRenderer but I believe it would be better to handle directly in the ViewRenderer. Here's how I handled the ItemAnimator, though I'm not 100% sure it's animating (it's updating positions when I update the dataset).


constructor(props) {
    super(props);

    // Item Animator
    const itemAnimator = new DefaultNativeItemAnimator();

    itemAnimator.shouldAnimateOnce = false;
    this.itemAnimator = itemAnimator;
...
}

bradbyte avatar May 31 '18 20:05 bradbyte

@bradbumbalough I was not able to find anything. I was getting ready to start exploring PanResponder as well. Do you have a gist/project you can share?

I tried the same thing for ItemAnimator. When you say "it's updating positions", is it just abruptly updating (no nice animation)? That's the behavior I see when I add items to the list or try swapping row data, but per your point I guess that could be the default "animation".

dkpalmer avatar Jun 01 '18 18:06 dkpalmer

@dkpalmer here's a gist for a component I made called Draggable. I'm wrapping the list item I want to drag with it. https://gist.github.com/bradbumbalough/70a79dddc922215044071dc1ff7775e7. It passes an onLongPress to its child and then is called with a TouchableHighlight.

The main issue with this is that when the dataset updates the order the RLV also updates the position, and since I'm using a transform and not say top, it gets pushed up from where you are currently touching. Definitely WIP...

I'm ok with the animations not being 👌 while getting the basic reordering to work as intended.

bradbyte avatar Jun 04 '18 10:06 bradbyte

getViewHolderForType is not yet there but should be pretty easy to build. @bradbumbalough That will be needed for you to be able to discard RLV transform. With a custom item animator you can animate changes in data set. But you'll need a stable id on your items to make it better.

naqvitalha avatar Jun 05 '18 05:06 naqvitalha

@dkpalmer have you started anything by means of a fork? I'm going to be picking back on this now.

bradbyte avatar Jun 20 '18 19:06 bradbyte

@bradbumbalough I have not. We switched to an interim solution for re-ordering to be able to ship. I'll switch back to drag and drop soon, though.

dkpalmer avatar Jun 22 '18 12:06 dkpalmer

@naqvitalha I've been unable to get drag and drop working as of yet... is there plans in the future for this to be supported as a first class citizen with RLV? Thanks again for the work on this!

bradbyte avatar Oct 03 '18 14:10 bradbyte

@naqvitalha do you have any feedback on an updated approach on how to handle drag and drop based on the latest version? Thank you!

bradbyte avatar Jun 08 '20 20:06 bradbyte

Would love to see drag and drop support for this component.

elan avatar Jun 09 '20 04:06 elan

Ran across https://github.com/shufflingB/rn_draggable_swipeable_list_example for anyone looking.

However, it seems to have a few issues:

  • Lack of animation of the rows under the dragged on.
  • Lots of list re-renders (one per reorder) which seems expensive even in release mode.

elan avatar Mar 31 '21 18:03 elan

Hello, any possibility for this component to support a draggable feature?

marf avatar Mar 14 '22 14:03 marf