project-nv / night-vision

Highly customizable charting library, created for professional traders
https://nightvision.dev
MIT License
252 stars 58 forks source link

Cursor behavior on mobile device #106

Closed muduxd closed 1 year ago

muduxd commented 1 year ago

Description

I tried creating a moving cursor in Night Vision for when the user enters the application from the phone. I am aware that Night Vision doesn't still have a mobile support, and this feature is in the roadmap.

When on a mobile device, I attached to the div on which the canvas renders, some functions on touch start, end and move events, and then simulated a trackpad similar to the one on TradingView, but sometimes when a default touch is generated, the night-vision cursor overrides mine and moves in the position of my finger, even tough I don't want this behavior to occur.

I tried disabling it by emitting the event "cursor-locked" with a "true" value as the second parameter but to no avail. The pointer object in "/core/input/pointer.js" has a method from HammerJS which by default on a tap overrides my cursor.

Is there a way in which I could disable this default behavior of the cursor?

Here is a demo of the issue:

Here is a oversimplified version of my code:

  // Function to move the cursor based on the touch input
  const moveCursor = (x, y) => {
      const obj = {
          gridId: 0,
          x,
          y,
          visible: true,
          show: true
      }

      chart.events.emit('cursor-changed', obj)
      chart.events.emit('cursor-locked', true)
      chart.events.emit('scroll-lock', true)
  }

  // Function to turn on the cursor
    const activateCursor = (x, y) => {
            const obj = {
                gridId: 0,
                x,
                y,
                visible: true,
                show: true
            }

            chart.events.emit('cursor-changed', obj)
            chart.events.emit('cursor-locked', true)
            chart.events.emit('scroll-lock', true)

            cursorActive = true
        }
    }

Suggested solution

I know that the solution is in the making as seen in the roadmap, but maybe a new path to achieve this behavior.

Alternative

No response

Additional context

No response

Validations

C451 commented 1 year ago

Not properly ported to mobile yet.