package com.adealink.weparty.commonui.gesture

import android.view.GestureDetector
import android.view.MotionEvent
import android.view.TouchDelegate
import android.view.View
import androidx.core.view.GestureDetectorCompat
import com.adealink.weparty.commonui.ext.getRect

class GestureDetectDelegate(
    targetView: View,
    onGestureListener: GestureDetector.OnGestureListener
) :
    TouchDelegate(targetView.getRect(), targetView) {

    private val detectorCompat: GestureDetectorCompat

    init {
        val context = targetView.context
        detectorCompat = GestureDetectorCompat(context, onGestureListener)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        detectorCompat.onTouchEvent(event)
        return super.onTouchEvent(event)
    }
}
