mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-11 22:32:38 +08:00
Update Android Touch events
Summary: public This moves Android touch events to parity with iOS. The locationX,Y value passed to js now is view relative to the view that is handling the touch. The pageX,Y is now relative to the root view. Reviewed By: andreicoman11 Differential Revision: D2670028 fb-gh-sync-id: 5438640d6c78633629b9a308a59cc306bb07815e
This commit is contained in:
committed by
facebook-github-bot-3
parent
e0d53e1c48
commit
0c2ee5d480
@@ -39,17 +39,34 @@ public class TouchTargetHelper {
|
||||
float eventY,
|
||||
float eventX,
|
||||
ViewGroup viewGroup) {
|
||||
return findTargetTagAndCoordinatesForTouch(eventY, eventX, viewGroup, mEventCoords);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find touch event target view within the provided container given the coordinates provided
|
||||
* via {@link MotionEvent}.
|
||||
*
|
||||
* @param eventY the Y screen coordinate of the touch location
|
||||
* @param eventX the X screen coordinate of the touch location
|
||||
* @param viewGroup the container view to traverse
|
||||
* @param viewCoords an out parameter that will return the Y,X value in the target view
|
||||
* @return the react tag ID of the child view that should handle the event
|
||||
*/
|
||||
public static int findTargetTagAndCoordinatesForTouch(
|
||||
float eventY,
|
||||
float eventX,
|
||||
ViewGroup viewGroup,
|
||||
float[] viewCoords) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
int targetTag = viewGroup.getId();
|
||||
// Store eventCoords in array so that they are modified to be relative to the targetView found.
|
||||
float[] eventCoords = mEventCoords;
|
||||
eventCoords[0] = eventY;
|
||||
eventCoords[1] = eventX;
|
||||
View nativeTargetView = findTouchTargetView(eventCoords, viewGroup);
|
||||
viewCoords[0] = eventY;
|
||||
viewCoords[1] = eventX;
|
||||
View nativeTargetView = findTouchTargetView(viewCoords, viewGroup);
|
||||
if (nativeTargetView != null) {
|
||||
View reactTargetView = findClosestReactAncestor(nativeTargetView);
|
||||
if (reactTargetView != null) {
|
||||
targetTag = getTouchTargetForView(reactTargetView, eventCoords[0], eventCoords[1]);
|
||||
targetTag = getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]);
|
||||
}
|
||||
}
|
||||
return targetTag;
|
||||
|
||||
Reference in New Issue
Block a user