Pointer input not received by the child UI in jetpack compose

23 Views Asked by At

I am Developing an app for android stylus tablet. I have a list of canvas in a column. I am trying to achieve the scrolling of the list if the pointer input is not stylus, else the canvas (child) below the list should get the pointer input, which is used for drawing using the stylus.

Below is the code for the column modifier which has the number of Canvas.

.pointerInput(Unit) {
                            detectVerticalDragGestures { change, dragAmount ->
                                if(change.type != PointerType.Stylus){
                                    scope.launch {
                                        verticalScroller.scrollTo(verticalScroller.value - dragAmount.toInt())
                                    }
                                }
                            }
                        }

The canvas in the list has View Surface, each surface has the ontouchlistner to it. So when something is drawn onthe surface with the stylus it will be rendered on the surface.

Below is the code for FastRenderer of the canvas.

@RequiresApi(Build.VERSION_CODES.Q)
    @SuppressLint("ClickableViewAccessibility")
    val onTouchListener = View.OnTouchListener { view, motionEvent ->
        if(frontBufferRenderer?.isValid() == true){
            if (viewModel.isReadOnly.not()) {
                val isStylus =
                    MotionEvent.TOOL_TYPE_STYLUS == motionEvent.getToolType(motionEvent.pointerCount - 1)
                if (isStylus) {
                    val strokeWidthFactor = motionEvent.pressure
                    when (motionEvent.actionMasked) {
                        MotionEvent.ACTION_DOWN -> {

                            viewModel.checkNewWritingArea(
                                motionEvent,
                                drawAreaType,
                                canvasWidth
                            )

                            if (isFastRendererRegistered.not()) {
                                viewModel.registerFastRenderer(this)
                                isFastRendererRegistered = true
                            }

                            view.requestUnbufferedDispatch(motionEvent)

                            val currentLine = Line(
                                Offset(motionEvent.x, motionEvent.y),
                                Offset(motionEvent.x, motionEvent.y),
                                strokeWidthFactor
                            )
                            frontBufferRenderer?.renderFrontBufferedLayer(currentLine)
                            viewModel.previousLinePointer = Offset(motionEvent.x, motionEvent.y)
                        }

                        MotionEvent.ACTION_MOVE -> {
                            val currentLine =
                                Line(
                                    viewModel.previousLinePointer,
                                    Offset(motionEvent.x, motionEvent.y),
                                    strokeWidthFactor
                                )
                            frontBufferRenderer?.renderFrontBufferedLayer(currentLine)
                            viewModel.previousLinePointer = Offset(motionEvent.x, motionEvent.y)
                        }

                        MotionEvent.ACTION_UP -> {
                            Log.d(TAG, "actionUp $drawAreaType")
                            val currentLine =
                                Line(
                                    viewModel.previousLinePointer,
                                    Offset(motionEvent.x, motionEvent.y),
                                    strokeWidthFactor
                                )
                            frontBufferRenderer?.renderFrontBufferedLayer(currentLine)
                            frontBufferRenderer?.commit()
                        }
                    }

//                runBlocking {
//                    launch(Dispatchers.Default) {
                        viewModel.processStylusMotionEvent(
                            motionEvent,
                            Offset(
                                globalPostion.x + motionEvent.x,
                                globalPostion.y + motionEvent.y
                            ),
                            Pair(viewModel.writingArea.value, drawAreaType.second)
                        )
//                    }
//                }

                } else {
                    runBlocking {
                        launch(Dispatchers.Default) {
                            viewModel.processHandMotionEvent(
                                motionEvent,
                                drawAreaType,
                                canvasWidth
                            )
                        }
                    }
                }
            }
        }
        true
    }

The probem is due to the overlapping of the pointer input for the list scrolling, and surface ontouchlistner, the scrolling behaviour works fine, but when I try to write using the stylus the pointer input is not reaching the ontouchlistner.

Please help me with this.

0

There are 0 best solutions below