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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Drag & Drop Reordering? #146

Open
lxcid opened this issue Apr 5, 2018 · 19 comments
Open

Support Drag & Drop Reordering? #146

lxcid opened this issue Apr 5, 2018 · 19 comments

Comments

@lxcid
Copy link

lxcid commented Apr 5, 2018

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?

@naqvitalha
Copy link
Collaborator

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.

@lxcid
Copy link
Author

lxcid commented Apr 8, 2018

Amazing @naqvitalha thanks for the explanation!

@bradbyte
Copy link

bradbyte commented May 23, 2018

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!

@naqvitalha
Copy link
Collaborator

@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.

@dkpalmer
Copy link

dkpalmer commented May 28, 2018

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
Copy link

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?

@naqvitalha
Copy link
Collaborator

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

@dkpalmer
Copy link

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

@bradbyte
Copy link

@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;
...
}

@dkpalmer
Copy link

dkpalmer commented Jun 1, 2018

@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".

@bradbyte
Copy link

bradbyte commented Jun 4, 2018

@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.

@naqvitalha
Copy link
Collaborator

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.

@bradbyte
Copy link

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

@dkpalmer
Copy link

@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.

@bradbyte
Copy link

bradbyte commented Oct 3, 2018

@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
Copy link

bradbyte commented Jun 8, 2020

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

@elan
Copy link

elan commented Jun 9, 2020

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

@elan
Copy link

elan commented Mar 31, 2021

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.

@marf
Copy link

marf commented Mar 14, 2022

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

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

6 participants