PhotoView icon indicating copy to clipboard operation
PhotoView copied to clipboard

Added AdditionalOnTouchListener

Open siralam opened this issue 7 years ago • 4 comments

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!

siralam avatar Mar 13 '18 04:03 siralam

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 ?

MrCanan avatar Jan 01 '19 10:01 MrCanan

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.

shahsurajk avatar Feb 28 '19 11:02 shahsurajk

I am also interested in this! (in case any maintainers are listening...)

retwedt avatar Aug 28 '19 16:08 retwedt

@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)
        }
    }
}

bendikv avatar Jan 17 '20 15:01 bendikv