Skip to content

Commit

Permalink
feat: Disable touch event when touch range is outside the graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ootr47 committed Dec 5, 2023
1 parent ece4b5c commit 80a2045
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/app/priceguard/materialchart/Chart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Chart @JvmOverloads constructor(
private val zeroDp = Dp(1F)

private var pointX = 0f
private var pointY = 0f
private var isDragging = false

// Use Android theme
Expand Down Expand Up @@ -193,10 +194,20 @@ class Chart @JvmOverloads constructor(
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
if (dataset?.isInteractive != true) {
if (dataset?.isInteractive != true || event == null) {
return false
}
when (event?.action) {
pointX = event.x
pointY = event.y

if (pointX < xAxisMarginStart.toPx(context).value
|| pointX > width.toFloat() - xAxisMarginStart.toPx(context).value
|| pointY < yAxisMarginEnd.toPx(context).value
|| pointY > height.toFloat() - yAxisMarginEnd.toPx(context).value
) {
return true
}
when (event.action) {
MotionEvent.ACTION_DOWN -> {
parent.requestDisallowInterceptTouchEvent(true)
isDragging = true
Expand Down

0 comments on commit 80a2045

Please sign in to comment.