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

Change the dispatch click system #12

Open
dvdciri opened this issue Nov 26, 2020 · 1 comment
Open

Change the dispatch click system #12

dvdciri opened this issue Nov 26, 2020 · 1 comment

Comments

@dvdciri
Copy link

dvdciri commented Nov 26, 2020

Would you consider changing the way the library dispatches the click to the leaf nodes only by instead checking if non-leaf nodes have a click listener attached and giving priority to those?
This means that if i have a ViewGroup with a click listener and some items inside, everywhere i lift my finger in this view group, the click will be dispatched to the view group instead of the children.

Alternatively we can also inject this behavior and make it custmizable.

Happy to open a PR for this and contribute just let me know what you think.

@dvdciri
Copy link
Author

dvdciri commented Nov 26, 2020

My proposal would be to change this method like below:

private void dispatchClickToLeafsOnly(ViewGroup view, MotionEvent motionEvent) {

    // If no view or no children, return
    if (view == null || view.getChildCount() == 0) {
      return;
    }
    for (int i = 0; i < view.getChildCount(); i++) {
      View child = view.getChildAt(i);

      if (child instanceof ViewGroup && !child.hasOnClickListeners()) {

        // If a ViewGroup without click listener, search for leafs inside
        dispatchClickToLeafsOnly((ViewGroup) child, motionEvent);
      } else {

        // Else check if touch event is inside it
        if (LongPressPopupUtils.isTouchInsideView(child, motionEvent)) {

          if (mLongPressReleaseClickListener != null) {

            // Notify the given listener
            mLongPressReleaseClickListener.onClick(child);
          } else {

            // Else, dispatch the touch event on the view
            child.performClick();
          }
        } else if (child instanceof ViewGroup) {
          // If a ViewGroup without click listener, search for leafs inside
          dispatchClickToLeafsOnly((ViewGroup) child, motionEvent);
        }
      }
    }
  }

And a similar change for the focus one.

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

No branches or pull requests

1 participant