Skip to content

Commit

Permalink
Fix non-touch event dispatching not being blocked by pointer-events
Browse files Browse the repository at this point in the history
Summary: Changelog: [Android][Fixed] Scroll views would still receive scroll events when nested in a view with `pointer-events: "none"`

Differential Revision: D36423921

fbshipit-source-id: 87b8a236e15dda7b648b6fc649187e95a9a2cc42
  • Loading branch information
javache authored and facebook-github-bot committed May 18, 2022
1 parent 7b703eb commit fced96b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,16 @@ public boolean onTouchEvent(MotionEvent ev) {
return super.onTouchEvent(ev);
}

@Override
public boolean dispatchGenericPointerEvent(MotionEvent ev) {
// We do not dispatch the pointer event if its children are not supposed to receive it
if (!PointerEvents.canChildrenBeTouchTarget(mPointerEvents)) {
return false;
}

return super.dispatchGenericPointerEvent(ev);
}

@Override
public boolean executeKeyEvent(KeyEvent event) {
int eventKeyCode = event.getKeyCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ public boolean onTouchEvent(MotionEvent ev) {
return super.onTouchEvent(ev);
}

@Override
public boolean dispatchGenericPointerEvent(MotionEvent ev) {
// We do not dispatch the pointer event if its children are not supposed to receive it
if (!PointerEvents.canChildrenBeTouchTarget(mPointerEvents)) {
return false;
}

return super.dispatchGenericPointerEvent(ev);
}

@Override
public boolean executeKeyEvent(KeyEvent event) {
int eventKeyCode = event.getKeyCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
// We intercept the touch event if the children are not supposed to receive it.
if (mPointerEvents == PointerEvents.NONE || mPointerEvents == PointerEvents.BOX_ONLY) {
if (!PointerEvents.canChildrenBeTouchTarget(mPointerEvents)) {
return true;
}
return super.onInterceptTouchEvent(ev);
Expand All @@ -233,7 +233,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
@Override
public boolean onTouchEvent(MotionEvent ev) {
// We do not accept the touch event if this view is not supposed to receive it.
if (mPointerEvents == PointerEvents.NONE || mPointerEvents == PointerEvents.BOX_NONE) {
if (!PointerEvents.canBeTouchTarget(mPointerEvents)) {
return false;
}
// The root view always assumes any view that was tapped wants the touch
Expand All @@ -244,6 +244,16 @@ public boolean onTouchEvent(MotionEvent ev) {
return true;
}

@Override
public boolean dispatchGenericPointerEvent(MotionEvent ev) {
// We do not dispatch the pointer event if its children are not supposed to receive it
if (!PointerEvents.canChildrenBeTouchTarget(mPointerEvents)) {
return false;
}

return super.dispatchGenericPointerEvent(ev);
}

/**
* We override this to allow developers to determine whether they need offscreen alpha compositing
* or not. See the documentation of needsOffscreenAlphaCompositing in View.js.
Expand Down

0 comments on commit fced96b

Please sign in to comment.