Giter Site home page Giter Site logo

Comments (2)

mlshv avatar mlshv commented on May 21, 2024 1

I have the same problem! This issue definitely needs a fix

Upd
Just looked into the code and it seems like I have a problem of another kind but it looks similar. I'm trying to use drag-and-drop handler together with scrollbooster. I have shouldScroll function defined like this:

new ScrollBooster({
    viewport: containerRef.current,
    content: contentRef.current,
    scrollMode: 'native',
    direction: 'horizontal',
    textSelection: true,
    shouldScroll: (state, event) => {
        const isDragHandleToched = event.path.some(checkIsDragHandle)

        return !isDragHandleToched
    },
})

But it disables click handlers on a draggable element after a first scroll move with scrollbooster. And state.isDragging is always true on single click because of this line in scrollboster:

this.events.pointerdown = (event) => {
     // ....
     this.isDragging = true
}

I'm going to investigate further

Upd2
I think I've found the problem:

this.events.click = (event) => {
    const state = this.getState()
    const dragOffsetX = this.props.direction !== 'vertical' ? state.dragOffset.x : 0
    const dragOffsetY = this.props.direction !== 'horizontal' ? state.dragOffset.y : 0
    if (Math.max(Math.abs(dragOffsetX), Math.abs(dragOffsetY)) > CLICK_EVENT_THRESHOLD_PX) {
        // this is always true if you have scrolled to any amount of pixels more than 5
        // ...even if this.isDragging equals false
        event.preventDefault()
        event.stopPropagation()
    }
    this.props.onClick(state, event, isTouch)
}

My solution is to add this.isDragging to the if statement:

    if (this.isDragging && Math.max(Math.abs(dragOffsetX), Math.abs(dragOffsetY)) > CLICK_EVENT_THRESHOLD_PX) {
        event.preventDefault()
        event.stopPropagation()
    }

I didn't dig in enough to say it should be patched on the main branch or if it going to work in your case, but it worked for me

from scrollbooster.

asmedberg avatar asmedberg commented on May 21, 2024

Upd2 I think I've found the problem:

this.events.click = (event) => {
    const state = this.getState()
    const dragOffsetX = this.props.direction !== 'vertical' ? state.dragOffset.x : 0
    const dragOffsetY = this.props.direction !== 'horizontal' ? state.dragOffset.y : 0
    if (Math.max(Math.abs(dragOffsetX), Math.abs(dragOffsetY)) > CLICK_EVENT_THRESHOLD_PX) {
        // this is always true if you have scrolled to any amount of pixels more than 5
        // ...even if this.isDragging equals false
        event.preventDefault()
        event.stopPropagation()
    }
    this.props.onClick(state, event, isTouch)
}

My solution is to add this.isDragging to the if statement:

    if (this.isDragging && Math.max(Math.abs(dragOffsetX), Math.abs(dragOffsetY)) > CLICK_EVENT_THRESHOLD_PX) {
        event.preventDefault()
        event.stopPropagation()
    }

I didn't dig in enough to say it should be patched on the main branch or if it going to work in your case, but it worked for me

Not sure this project is getting updated but this solution worked for my project as well.

from scrollbooster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.