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

Add scrolling support vertically and horizontally #449

Closed
wants to merge 17 commits into from
Closed

Add scrolling support vertically and horizontally #449

wants to merge 17 commits into from

Conversation

nguyenj
Copy link

@nguyenj nguyenj commented Dec 10, 2016

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

steel commented Dec 12, 2016

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

This looks fantastic.

What needs to happen for this to be mergeable?

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(); }

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(); }

Copy link
Author

@nguyenj nguyenj Dec 13, 2016

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

nguyenj commented Dec 13, 2016

I think it's pretty much ready.

@joshsmith
Copy link

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

purtuga commented Dec 23, 2016

+++1 for this...

Copy link
Owner

@bevacqua bevacqua left a comment

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

dragula.js Outdated
if (node === null) { return null; }
if (node.scrollHeight > node.clientHeight) {
return node;
} else {
Copy link
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

dragula.js Outdated
} else {
if (!/(body|html)/i.test(node.parentNode.tagName)) {
return getScrollContainer(node.parentNode);
} else {
Copy link
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

dragula.js Outdated
if (node.scrollHeight > node.clientHeight) {
return node;
} else {
if (!/(body|html)/i.test(node.parentNode.tagName)) {
Copy link
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
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
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.

Copy link
Owner

@bevacqua bevacqua Dec 23, 2016

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

purtuga commented Dec 23, 2016

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

nguyenj commented Dec 23, 2016

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

purtuga commented Dec 23, 2016

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

dragula.js Outdated
@@ -6,6 +6,7 @@ var classes = require('./classes');
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
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
Copy link
Owner

bevacqua commented Dec 23, 2016

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

@purtuga
Copy link

purtuga commented Dec 24, 2016

@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

looking forward to this PR can be merged into Dragula ASAP

@nguyenj
Copy link
Author

nguyenj commented Jan 6, 2017

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

purtuga commented Jan 7, 2017

@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

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

@nguyenj
Copy link
Author

nguyenj commented Jan 19, 2017

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

@purtuga
Copy link

purtuga commented Jan 28, 2017

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

nguyenj commented Apr 4, 2017

@gxzhou519 your issues should be fixed.

Thanks @adam-h!

@nguyenj
Copy link
Author

nguyenj commented Apr 6, 2017

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

@joshsmith
Copy link

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

@nguyenj
Copy link
Author

nguyenj commented Apr 9, 2017

@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

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

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

@nguyenj
Copy link
Author

nguyenj commented Apr 25, 2017

Good question! I have no idea.

@replete
Copy link

replete commented Jun 5, 2017

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

ESSENTIAL for this great piece of software

@shennan
Copy link

shennan commented Jun 22, 2017

@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

Any ETA?

@gardinit
Copy link

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

nguyenj commented Oct 25, 2017

@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

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

lukasjuhas commented Apr 25, 2018

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

Lukas

@jeffal
Copy link

jeffal commented Apr 25, 2018

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

@danielehrhardt
Copy link

Is there a fork with this PR?

@benelliott
Copy link

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

@nguyenj
Copy link
Author

nguyenj commented May 29, 2018

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

@nguyenj
Copy link
Author

nguyenj commented Jun 18, 2018

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

⚰️

@mdhtr
Copy link

mdhtr commented Oct 17, 2018

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.