mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-09 22:50:21 +08:00
Fix touch target computation
Differential Revision: D2516811 fb-gh-sync-id: 1f3490f969912f1eb8f4d49a5daa976314bbc25f
This commit is contained in:
committed by
facebook-github-bot-7
parent
fb90ba6ded
commit
c805157cac
@@ -79,17 +79,27 @@ public class TouchTargetHelper {
|
||||
// parent, therefore `getGlobalVisibleRect` call will return bogus result as it treat view
|
||||
// with no parent as a root of the view hierarchy. To prevent this from happening we check
|
||||
// that view has a parent before visiting it.
|
||||
if (child.getParent() != null && child.getGlobalVisibleRect(mVisibleRect)) {
|
||||
if (eventX >= mVisibleRect.left && eventX <= mVisibleRect.right
|
||||
&& eventY >= mVisibleRect.top && eventY <= mVisibleRect.bottom) {
|
||||
View targetView = findTouchTargetViewWithPointerEvents(eventX, eventY, child);
|
||||
if (targetView != null) {
|
||||
return targetView;
|
||||
}
|
||||
if (child.getParent() != null && isTouchPointInView(eventX, eventY, viewGroup, child)) {
|
||||
// Apply offset to event coordinates to transform them into the coordinate space of the
|
||||
// child view, taken from {@link ViewGroup#dispatchTransformedTouchEvent()}.
|
||||
eventX += viewGroup.getScrollX() - child.getLeft();
|
||||
eventY += viewGroup.getScrollY() - child.getTop();
|
||||
View targetView = findTouchTargetViewWithPointerEvents(eventX, eventY, child);
|
||||
if (targetView != null) {
|
||||
return targetView;
|
||||
}
|
||||
}
|
||||
}
|
||||
return viewGroup;
|
||||
}
|
||||
|
||||
// Taken from {@link ViewGroup#isTransformedTouchPointInView()}
|
||||
private static boolean isTouchPointInView(float x, float y, ViewGroup parent, View child) {
|
||||
float localX = x + parent.getScrollX() - child.getLeft();
|
||||
float localY = y + parent.getScrollY() - child.getTop();
|
||||
// Taken from {@link View#pointInView()}.
|
||||
return localX >= 0 && localX < (child.getRight() - child.getLeft())
|
||||
&& localY >= 0 && localY < (child.getBottom() - child.getTop());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user