Added AdditionalOnTouchListener
Since PhotoViewAttacher also uses OnTouchListener, instead of PhotoViewoverriding onTouchEvent, this made user of PhotoView unable to set their own OnTouchListener on top of PhotoView.
For example, if I want to also be able to start a drag and drop (but not by long press, which is already available as a custom listener) when my drag action has gone outside of the view bound, PhotoView has no way to deal with this now.
So I simply added an additional OnTouchListener.
If user does not add it, it won't affect any of the existing functionality of this library.
If user adds it and returned true, the on-going code in OnTouch of PhotoViewAttacher will not continue to execute.
See if you agree to add this additional functionality. Thanks!
This is a great idea. =) I really need it, @chrisbanes can you merge it ? @siralam Can you make a new release in your repo, because your alternate version is also very interesting ?
This solves a couple of problems i'm facing, which is detecting when the image was done scaling by the user, which technically is an ACTION_UP/ ACTION_CANCEL event on the custom touch listener attached.
I am also interested in this! (in case any maintainers are listening...)
@retwedt @siralam @shahsurajk You can just extend PhotoView like this:
class CustomPhotoView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : PhotoView(context, attrs, defStyleAttr) {
init {
setOnTouchListener { _, event ->
if (event.actionMasked == MotionEvent.ACTION_UP
|| event.actionMasked == MotionEvent.ACTION_CANCEL) {
...
return@setOnTouchListener true
}
return@setOnTouchListener attacher.onTouch(view, event)
}
}
}