forked from upstream-mirrors/quik
#1067 - Fix long-clicks for messages with links
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
@@ -55,3 +56,36 @@ fun View.setVisible(visible: Boolean, invisible: Int = View.GONE) {
|
||||
visibility = if (visible) View.VISIBLE else invisible
|
||||
}
|
||||
|
||||
/**
|
||||
* If a view captures clicks at all, then the parent won't ever receive touch events. This is a
|
||||
* problem when we're trying to capture link clicks, but tapping or long pressing other areas of
|
||||
* the view no longer work. Also problematic when we try to long press on an image in the message
|
||||
* view
|
||||
*/
|
||||
fun View.forwardTouches(parent: View) {
|
||||
var isLongClick = false
|
||||
|
||||
setOnLongClickListener {
|
||||
isLongClick = true
|
||||
true
|
||||
}
|
||||
|
||||
setOnTouchListener { v, event ->
|
||||
parent.onTouchEvent(event)
|
||||
|
||||
when {
|
||||
event.action == MotionEvent.ACTION_UP && isLongClick -> {
|
||||
isLongClick = true
|
||||
true
|
||||
}
|
||||
|
||||
event.action == MotionEvent.ACTION_DOWN -> {
|
||||
isLongClick = false
|
||||
v.onTouchEvent(event)
|
||||
}
|
||||
|
||||
else -> v.onTouchEvent(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user