Skip to content

Add scrolling support vertically and horizontally#449

Closed
nguyenj wants to merge 17 commits into
bevacqua:masterfrom
nguyenj:fix/scroll
Closed

Add scrolling support vertically and horizontally#449
nguyenj wants to merge 17 commits into
bevacqua:masterfrom
nguyenj:fix/scroll

Conversation

@nguyenj

@nguyenj nguyenj commented Dec 10, 2016

Copy link
Copy Markdown

This PR will be addressing these drag and scrolling issues: #327, #121.

TODOS:

  • Add support scrolling containers
  • Add support for horizontal scrolling
  • Allow auto scrolling at scroll edge
  • Add touch support

@steel

steel commented Dec 12, 2016

Copy link
Copy Markdown

This PR is just full of awesome!

TODO: When hovering the dragged item at scrollEdge, the scrolling should
automatically begin to scroll.

Drag and scrolling code is inspired by jQuery UI's sortable and
draggable widgets.
@joshsmith

Copy link
Copy Markdown

This looks fantastic.

What needs to happen for this to be mergeable?

Comment thread dragula.js Outdated
// For iframe. When dragging an item and mouse moves out of the iframe and
// mouseup, then decides to move back, the event will be 0 so we should
// just call cancel.
if (whichMouseButton(e) === 0 { cancel(); }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenj this has a syntax error.

Should be:

if (whichMouseButton(e) === 0) { cancel(); }

@nguyenj nguyenj Dec 13, 2016

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have this fixed. Thanks for the catch!

@nguyenj

nguyenj commented Dec 13, 2016

Copy link
Copy Markdown
Author

I think it's pretty much ready.

@joshsmith

Copy link
Copy Markdown

@nguyenj more asking the maintainers.

@bevacqua can you or someone else take a look at this when you have a free moment? Thanks!

Happy to help triage, as well.

@purtuga

purtuga commented Dec 23, 2016

Copy link
Copy Markdown

+++1 for this...

@bevacqua bevacqua left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice, but has me worried about jank. Can you replace setInterval with requestAnimationFrame?

We can use this module: raf

Comment thread dragula.js Outdated
if (node === null) { return null; }
if (node.scrollHeight > node.clientHeight) {
return node;
} else {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else here is redundant, please remove

Comment thread dragula.js Outdated
} else {
if (!/(body|html)/i.test(node.parentNode.tagName)) {
return getScrollContainer(node.parentNode);
} else {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else here is redundant, please remove

Comment thread dragula.js Outdated
if (node.scrollHeight > node.clientHeight) {
return node;
} else {
if (!/(body|html)/i.test(node.parentNode.tagName)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract regexp to a variable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why I need a variable for this. Why would you want to hold on to the reference if it's not going to be used unless we're scrolling?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a commit for it, e9e4e5a; but I'm not sure if I'm happy with this path. I'm open to suggestions.

@bevacqua bevacqua Dec 23, 2016

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenj I just meant putting it in a variable like this:

var rbodyhtml = /(body|html)/i
if (!rbodyhtml.test(node.parentNode.tagName)) {
  // ...

I avoid inline regular expressions in conditionals because they dampen readability. There's no need to hoist it to the top of the file, certainly.

@purtuga

purtuga commented Dec 23, 2016

Copy link
Copy Markdown

Just wanted to pass along some info...
I just pulled this fork into a Kanban board application I have and I'm not getting expected results... Does this fix support only scrolling when it reaches the edge of the browser? or also of the containers, which themselves could have fixed height with scrolling bars?
The issue (for me) seems to be around the getScrollContainer function... it seem to be returning the node provided on input every time... To give you an idea of my use case, I am working with the following screen:

image

Looks like for my use case, where I want each container to be able to scroll vertically when I move the card over it, I will likely need to write something custom... Hopefully dragula provides me with enough events to be able to do it without having to fork the library.

/Paul

@nguyenj

nguyenj commented Dec 23, 2016

Copy link
Copy Markdown
Author

@purtuga can you provide me a jsbin example? I have an example setup on the index.html for scrolling within a container. It would be easier to debug your issue if I'm able to see the markup and css.

@purtuga

purtuga commented Dec 23, 2016

Copy link
Copy Markdown

Hi @nguyenj, thanks for responding...
I don't have a public version of this app, but let me see if can setup something so you can take a look...

Comment thread dragula.js Outdated
var doc = document;
var documentElement = doc.documentElement;
var _autoScrollingInterval; // reference to auto scrolling
var BODY_HTML_TAG_REGEX = new RegExp(/(body|html)/, 'i');

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just keep it as a literal /(body|html)/i

@bevacqua

bevacqua commented Dec 23, 2016

Copy link
Copy Markdown
Owner

@nguyenj Could use use requestAnimationFrame / cancel via raf? This way we can support older browsers too 👍

@purtuga

purtuga commented Dec 24, 2016

Copy link
Copy Markdown

@nguyenj I setup a quick prototype here: http://jsbin.com/mahuwitani
I included the latest code from your fork's dist folder... I do see the containers scrolling as you drag a container child close to the edge of them, but am also seeing some weird behavior on multiple containers... Example: if you pickup a item and drag it across multiple containers, but close to the bottom edge of each container, they start to scroll by themselves... sometimes not stopping..

This prototype is also setup where the body of the window does not have a horizontal scroll, but rather, the element around the containers does... I don't believe your push is meant to address this use case (custom viewport elements), but wanted to provide you with a sample...

Thanks for your time on this and for contributing back.

@belovedllj

Copy link
Copy Markdown

looking forward to this PR can be merged into Dragula ASAP

@nguyenj

nguyenj commented Jan 6, 2017

Copy link
Copy Markdown
Author

@purtuga That's interesting; thanks for pointing that out. I'm not sure if I'll be able to address your particular issue with dragging in multi-directions. I suspect the issue to be that, it's only looking for the closest container "type" to that item and checking to see if it's scrollable-that's probably why it's not scrolling horizontal because the parent to the item is vertically scrollable.

@purtuga

purtuga commented Jan 7, 2017

Copy link
Copy Markdown

@nguyenj Thanks for the reply.
Yes, I figure my need would be a little different - basically dragula would have to support an input option that told it what the "scrolling view port" is... Your changes, I hope, will help me in my use case, since they will handle the scrolling of each individual droppable area... I think that I can then get my other need working by listening to dragula events and scrolling the horizontal viewing container myself.

@gerbermichi

Copy link
Copy Markdown

Hi guys, when do you add this PR into dragula? I am looking foreward to use this awesome feature :)

@nguyenj

nguyenj commented Jan 19, 2017

Copy link
Copy Markdown
Author

@bevacqua Let me know if there is anything else–I pushed up a simple raf polyfill.

@purtuga

purtuga commented Jan 28, 2017

Copy link
Copy Markdown

@nguyenj
I was able to fix my use case: scroll the area horizontally (a fixed-width DIV) when user drags card close the left/right edge using the drag and dragend events... Now I'm looking forward to @bevacqua merging your change in, which will complete my UX goal for what I'm working with...

@nguyenj

nguyenj commented Apr 4, 2017

Copy link
Copy Markdown
Author

@gxzhou519 your issues should be fixed.

Thanks @adam-h!

@nguyenj

nguyenj commented Apr 6, 2017

Copy link
Copy Markdown
Author

Tests are passing locally; but not entirely sure why CI is failing.

@joshsmith

Copy link
Copy Markdown

@nguyenj are you running the tests locally with the same configuration options as on Travis?

@nguyenj

nguyenj commented Apr 9, 2017

Copy link
Copy Markdown
Author

@joshsmith The only thing that is the same that I am running from .travis.yml file is node 4, everything else is on a mac.

@jasonruesch

Copy link
Copy Markdown

When will this be getting merged?

Also simplify animationFrame polyfills as browser support is excellent and older browsers are buggy (some have no support for cancelling) so it's better to fallback.
@jasonruesch

Copy link
Copy Markdown

I see that there was some activity. Is there an ETA on this being merged?

@nguyenj

nguyenj commented Apr 25, 2017

Copy link
Copy Markdown
Author

Good question! I have no idea.

@replete

replete commented Jun 5, 2017

Copy link
Copy Markdown

Wow, what do we need to do to get this merged? :O

ESSENTIAL for this great piece of software

@shennan

shennan commented Jun 22, 2017

Copy link
Copy Markdown

@nguyenj Does this cover the case where the elements that you want to scroll are not always Dragula containers? For example, you have a Kanban style board, which has overflowed the viewport, and you want to scroll the viewport when you approach the top/bottom edges such that you can place cards in different vertices? Essentially, initiating a page scroll on an entire page instead of just the containers.

@pmnevill

Copy link
Copy Markdown

Any ETA?

@gardinit

Copy link
Copy Markdown

Awesome. I tried out these change though and couldn't get it to work when i wanted to scroll to a container that wasn't currently in view. I made some modifications, but I'm unsure if this would make the package better or if this a use case specific to me.

Essentially I'm checking the need to scroll when looking to see if I'm over a target that is dropable, and removing the mouseEvents from the startScroll function and grabing them from the params passed into findDropTarget.

function findDropTarget (elementBehindCursor, clientX, clientY) {
   startScroll(_item, clientX , clientY, o);
   var target = elementBehindCursor;
   while (target && !accepted()) {
      target = getParent(target);
     }
   return target;
 ...

 function startScroll(item, pageX, pageY, options) {
    var scrollContainer = getScrollContainer(item);
    caf(_autoScrollingInterval);
    / / If a container contains the list that is scrollable
    if (scrollContainer) {
      var scrollingElement = null;
      var scrollEdge = options.scrollEdge;
      var scrollSpeed = 20;
      // Scrolling vertically
      if (pageY - getOffset(scrollContainer).top < scrollEdge)
          ...

@nguyenj

nguyenj commented Oct 25, 2017

Copy link
Copy Markdown
Author

@gardinit sorry I’ve lost interest in pursuing to modify this PR as it seems that this library is in active and the author seems to have stopped maintaining this project-just take a look at all the unresolved issues and open PRs.

benelliott pushed a commit to benelliott/dragula that referenced this pull request Nov 13, 2017
Merge remote-tracking branch 'scrollfork2/fix/scroll' into scroll

# Conflicts:
#	dist/dragula.js
#	dist/dragula.min.js
@pete-hotchkiss

Copy link
Copy Markdown

I'd say that sadly this library should be considered dead. Given the lack of response form the author to PRs and issues he's moved his focus else where.

So those looking for a similar solution (with working scroll when dragging no less) would be well served with draggable

https://github.com/Shopify/draggable

@lukasjuhas

lukasjuhas commented Apr 25, 2018

Copy link
Copy Markdown

That's indeed what I've switched to @pete-hotchkiss
It works great!

Lukas

@jeffal

jeffal commented Apr 25, 2018

Copy link
Copy Markdown

I have switched to https://github.com/clauderic/react-sortable-hoc with great success!

@danielehrhardt

Copy link
Copy Markdown

Is there a fork with this PR?

@benelliott

Copy link
Copy Markdown

@danielehrhardt You can see if https://github.com/benelliott/dragula works for you

@nguyenj

nguyenj commented May 29, 2018

Copy link
Copy Markdown
Author

@danielehrhardt have you looked into https://github.com/Shopify/draggable? The community there is a little more vibrant.

@nguyenj

nguyenj commented Jun 18, 2018

Copy link
Copy Markdown
Author

Closing this as this project is DEAD.

@nguyenj nguyenj closed this Jun 18, 2018
@nguyenj nguyenj deleted the fix/scroll branch June 18, 2018 20:27
@lukasjuhas

Copy link
Copy Markdown

⚰️

@mdhtr

mdhtr commented Oct 17, 2018

Copy link
Copy Markdown

For those that are stuck with dragula: try dom-autoscroller.
It's this easy to set it up to work with dragula (example taken from the link above):

autoScroll([
        document.querySelector('#list-container'),
        document.querySelector('#container2')
    ],{
        margin: 20,
        maxSpeed: 5,
        scrollWhenOutside: true,
        autoScroll: function(){
            //Only scroll when the pointer is down, and there is a child being dragged.
            return this.down && drake.dragging;
        }
    }
);

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

Successfully merging this pull request may close these issues.