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

provide imageview single touch callback #25

Open
ghost opened this issue Mar 3, 2021 · 2 comments · May be fixed by #30
Open

provide imageview single touch callback #25

ghost opened this issue Mar 3, 2021 · 2 comments · May be fixed by #30

Comments

@ghost
Copy link

ghost commented Mar 3, 2021

when user just touch the imageview with single finger provide the callback as onClickListener()

@mosayyeb-ebrahimi mosayyeb-ebrahimi linked a pull request Oct 30, 2021 that will close this issue
@eddiemuc
Copy link

eddiemuc commented May 1, 2022

I see that there is already a PR for this issue since a year. Any progress on this?

@eddiemuc
Copy link

eddiemuc commented May 1, 2022

As a workaround I registered an own TouchListener to the imageview container (overriding the one registered by Loupe). This Listener forwards all events to Loupe, but it also uses a second GestureDetector instance to detect single taps.

A crude workaround though. I really hope this PR gets merged through.

My code (sorry, it is Java...)

            final Loupe loupe = new Loupe(binding.imageFull, binding.imageviewViewroot);
            loupe.setOnViewTranslateListener(new Loupe.OnViewTranslateListener() {
                @Override
                public void onStart(@NonNull final ImageView imageView) {
                    //empty on purpose
                }

                @Override
                public void onViewTranslate(@NonNull final ImageView imageView, final  float v) {
                    //empty on purpose
                }

                @Override
                public void onDismiss(@NonNull final ImageView imageView) {
                    //close detail view on "fling down"
                    finish();
                }

                @Override
                public void onRestore(@NonNull final ImageView imageView) {
                    //empty on purpose
                }
            });

            //Loupe is unable to detect single clicks (see https://github.com/igreenwood/loupe/issues/25)
            //As a workaround we register a second GestureDetector on top of the one installed by Loupe to detect single taps
            //Workaround START
            final GestureDetector singleTapDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onSingleTapConfirmed(final MotionEvent e) {
                    //Logic to happen on single tap:
                    inverseFullImageView(binding);
                    return true;
                }
            });
            //Registering an own touch listener overrides the TouchListener registered by Loupe
            binding.imageviewViewroot.setOnTouchListener((v, event) -> {
                //perform singleTap detection
                singleTapDetector.onTouchEvent(event);
                //pass through event to Loupe so it handles all other gestures correctly
                return loupe.onTouch(v, event);
            });
            //Workaround END 

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 a pull request may close this issue.

1 participant