mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
- Add offsetX, offsetY values
Summary: Changelog: [Internal] Provide Android backing for offsetX, offsetY values. Reviewed By: javache Differential Revision: D37734498 fbshipit-source-id: f0f6daea3a2da27c79d42b9546eafa757ec448e7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c81a3c5242
commit
4f522be373
@@ -128,7 +128,11 @@ public class JSPointerDispatcher {
|
||||
if (listeningForDown) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
PointerEvent.obtain(
|
||||
PointerEventHelper.POINTER_DOWN, surfaceId, activeTargetTag, motionEvent));
|
||||
PointerEventHelper.POINTER_DOWN,
|
||||
surfaceId,
|
||||
activeTargetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -149,7 +153,11 @@ public class JSPointerDispatcher {
|
||||
if (listeningForDown) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
PointerEvent.obtain(
|
||||
PointerEventHelper.POINTER_DOWN, surfaceId, activeTargetTag, motionEvent));
|
||||
PointerEventHelper.POINTER_DOWN,
|
||||
surfaceId,
|
||||
activeTargetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -167,6 +175,7 @@ public class JSPointerDispatcher {
|
||||
surfaceId,
|
||||
activeTargetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates,
|
||||
coalescingKey));
|
||||
}
|
||||
|
||||
@@ -182,7 +191,11 @@ public class JSPointerDispatcher {
|
||||
if (listeningForUp) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
PointerEvent.obtain(
|
||||
PointerEventHelper.POINTER_UP, surfaceId, activeTargetTag, motionEvent));
|
||||
PointerEventHelper.POINTER_UP,
|
||||
surfaceId,
|
||||
activeTargetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -200,7 +213,11 @@ public class JSPointerDispatcher {
|
||||
if (listeningForUp) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
PointerEvent.obtain(
|
||||
PointerEventHelper.POINTER_UP, surfaceId, activeTargetTag, motionEvent));
|
||||
PointerEventHelper.POINTER_UP,
|
||||
surfaceId,
|
||||
activeTargetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates));
|
||||
}
|
||||
|
||||
if (!supportsHover) {
|
||||
@@ -279,7 +296,7 @@ public class JSPointerDispatcher {
|
||||
return dispatchableViewTargets;
|
||||
}
|
||||
|
||||
private static void dispatchEventForViewTargets(
|
||||
private void dispatchEventForViewTargets(
|
||||
String eventName,
|
||||
List<ViewTarget> viewTargets,
|
||||
EventDispatcher dispatcher,
|
||||
@@ -288,7 +305,8 @@ public class JSPointerDispatcher {
|
||||
|
||||
for (ViewTarget viewTarget : viewTargets) {
|
||||
int viewId = viewTarget.getViewId();
|
||||
dispatcher.dispatchEvent(PointerEvent.obtain(eventName, surfaceId, viewId, motionEvent));
|
||||
dispatcher.dispatchEvent(
|
||||
PointerEvent.obtain(eventName, surfaceId, viewId, motionEvent, mTargetCoordinates));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +434,12 @@ public class JSPointerDispatcher {
|
||||
if (listeningToMove) {
|
||||
eventDispatcher.dispatchEvent(
|
||||
PointerEvent.obtain(
|
||||
PointerEventHelper.POINTER_MOVE, surfaceId, targetTag, motionEvent, coalescingKey));
|
||||
PointerEventHelper.POINTER_MOVE,
|
||||
surfaceId,
|
||||
targetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates,
|
||||
coalescingKey));
|
||||
}
|
||||
|
||||
mLastHitPath = hitPath;
|
||||
@@ -443,7 +466,11 @@ public class JSPointerDispatcher {
|
||||
Assertions.assertNotNull(eventDispatcher)
|
||||
.dispatchEvent(
|
||||
PointerEvent.obtain(
|
||||
PointerEventHelper.POINTER_CANCEL, surfaceId, targetTag, motionEvent));
|
||||
PointerEventHelper.POINTER_CANCEL,
|
||||
surfaceId,
|
||||
targetTag,
|
||||
motionEvent,
|
||||
mTargetCoordinates));
|
||||
}
|
||||
|
||||
List<ViewTarget> leaveViewTargets =
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactSoftExceptionLogger;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -26,12 +27,22 @@ public class PointerEvent extends Event<PointerEvent> {
|
||||
private static final int UNSET_COALESCING_KEY = -1;
|
||||
|
||||
public static PointerEvent obtain(
|
||||
String eventName, int surfaceId, int viewTag, MotionEvent motionEventToCopy) {
|
||||
String eventName,
|
||||
int surfaceId,
|
||||
int viewTag,
|
||||
MotionEvent motionEventToCopy,
|
||||
float[] offsetCoords) {
|
||||
PointerEvent event = EVENTS_POOL.acquire();
|
||||
if (event == null) {
|
||||
event = new PointerEvent();
|
||||
}
|
||||
event.init(eventName, surfaceId, viewTag, Assertions.assertNotNull(motionEventToCopy), 0);
|
||||
event.init(
|
||||
eventName,
|
||||
surfaceId,
|
||||
viewTag,
|
||||
Assertions.assertNotNull(motionEventToCopy),
|
||||
offsetCoords,
|
||||
0);
|
||||
return event;
|
||||
}
|
||||
|
||||
@@ -40,30 +51,42 @@ public class PointerEvent extends Event<PointerEvent> {
|
||||
int surfaceId,
|
||||
int viewTag,
|
||||
MotionEvent motionEventToCopy,
|
||||
float[] offsetCoords,
|
||||
int coalescingKey) {
|
||||
PointerEvent event = EVENTS_POOL.acquire();
|
||||
if (event == null) {
|
||||
event = new PointerEvent();
|
||||
}
|
||||
event.init(
|
||||
eventName, surfaceId, viewTag, Assertions.assertNotNull(motionEventToCopy), coalescingKey);
|
||||
eventName,
|
||||
surfaceId,
|
||||
viewTag,
|
||||
Assertions.assertNotNull(motionEventToCopy),
|
||||
offsetCoords,
|
||||
coalescingKey);
|
||||
return event;
|
||||
}
|
||||
|
||||
private @Nullable MotionEvent mMotionEvent;
|
||||
private @Nullable String mEventName;
|
||||
private int mCoalescingKey = UNSET_COALESCING_KEY;
|
||||
private float mOffsetX;
|
||||
private float mOffsetY;
|
||||
|
||||
private void init(
|
||||
String eventName,
|
||||
int surfaceId,
|
||||
int viewTag,
|
||||
MotionEvent motionEventToCopy,
|
||||
float[] offsetCoords,
|
||||
int coalescingKey) {
|
||||
|
||||
super.init(surfaceId, viewTag, motionEventToCopy.getEventTime());
|
||||
mEventName = eventName;
|
||||
mMotionEvent = MotionEvent.obtain(motionEventToCopy);
|
||||
mCoalescingKey = coalescingKey;
|
||||
mOffsetX = offsetCoords[0];
|
||||
mOffsetY = offsetCoords[1];
|
||||
}
|
||||
|
||||
private PointerEvent() {}
|
||||
@@ -126,6 +149,10 @@ public class PointerEvent extends Event<PointerEvent> {
|
||||
pointerEvent.putDouble("clientX", mMotionEvent.getX(index));
|
||||
pointerEvent.putDouble("clientY", mMotionEvent.getY(index));
|
||||
|
||||
// Offset refers to upper left edge of the target view
|
||||
pointerEvent.putDouble("offsetX", PixelUtil.toDIPFromPixel(mOffsetX));
|
||||
pointerEvent.putDouble("offsetY", PixelUtil.toDIPFromPixel(mOffsetY));
|
||||
|
||||
pointerEvent.putInt("target", this.getViewTag());
|
||||
pointerEvent.putDouble("timestamp", this.getTimestampMs());
|
||||
return pointerEvent;
|
||||
|
||||
Reference in New Issue
Block a user