onyx-intl / OnyxAndroidDemo

148 stars 40 forks source link

Inconsistent coordinates of touch point when scrolling #117

Closed cvetelinandreev closed 1 month ago

cvetelinandreev commented 4 months ago

Hi

I have a view inside a scroll view. When the view is scrolled down sometimes I get the Y coordinates absolute, sometimes relative to the visible rectangle of the view. Take a look at the code below. When I detect a touch with the finger I call setRawDrawingEnabled twice to enable interactions with the fingers. In that case I get the Y coordinate of the touch point inside onBeginRawDrawing relative to the visible rect. If I call only touchHelper.setRawDrawingEnabled(false) and then enable raw drawing trough a button in the UI then I get the Y coordinate of the touch point inside onBeginRawDrawing in absolute coordinates (relative to the visible rect + the scroll)

 GestureDetector.SimpleOnGestureListener() {
    override fun onDown(e: MotionEvent): Boolean {
        if (e.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER &&
            touchHelper.isRawDrawingInputEnabled) {

            touchHelper.setRawDrawingEnabled(false)
            touchHelper.setRawDrawingEnabled(true)
        }
        return super.onDown(e)
    }
}
...
        override fun onBeginRawDrawing(p0: Boolean, touchPoint: TouchPoint) {
            Log.d(javaClass.name, touchPoint.toString())
            TouchUtils.disableFingerTouch(context)
        }

The behaviour in the case when setRawDrawingEnabled is called twice is inconsistent and depends somehow on the way the view is scrolled.

Any ideas how to workaround it? Both getting consistent coordinates or another way of enabling finger actions when the raw input is on work.

Thank you!

cvetelinandreev commented 3 months ago

Onyx, team, Seems that you are very busy to look at this. I solved it by detecting local 'jumps' in the touch points. If there is a larger gap between two points it means we are off and need to be adjusted.

It works. The result is better than before but sometimes the first stroke gets cut a bit.

cvetelinandreev commented 1 month ago

The issue was that I was using a scrollable view to creat the touchHelper (TouchHelper.create(View, callback)) I fixed the issue by passing a hostView that has the size of the screen.