Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AdditionalOnTouchListener #590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

siralam
Copy link

@siralam siralam commented Mar 13, 2018

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!

@MrCanan
Copy link

MrCanan commented Jan 1, 2019

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 ?

@shahsurajk
Copy link

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.

@retwedt
Copy link

retwedt commented Aug 28, 2019

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

@bendikv
Copy link

bendikv commented Jan 17, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants