Skip to content

Commit cfe811a

Browse files
lunaleapsfacebook-github-bot
authored andcommitted
Fix natively driven animated.event for bubbling PointerEvents
Summary: Changelog: [Internal] Override logic for determining whether a dispatched `Event` triggers a native `EventAnimationDriver`. Natively driven AnimatedEvents on bubbling events is not supported. `PointerEvents` requires this and this diff adds custom matching logic such that if a parent specifies an `AnimatedEvent` on `onPointerMove` and a child view dispatches it, the `AnimatedEvent` will still fire. Reviewed By: javache Differential Revision: D38722563 fbshipit-source-id: 7cde57eaff9584b33c6ab15f1fe85c0a9bac132e
1 parent 565a743 commit cfe811a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static PointerEvent obtain(
6666
private short mCoalescingKey = UNSET_COALESCING_KEY;
6767
private @Nullable List<WritableMap> mPointersEventData;
6868
private PointerEventState mEventState;
69+
private @Nullable Event.EventAnimationDriverMatchSpec mEventAnimationDriverMatchSpec;
6970

7071
private void init(
7172
String eventName,
@@ -114,6 +115,31 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {
114115
return;
115116
}
116117

118+
@Override
119+
public Event.EventAnimationDriverMatchSpec getEventAnimationDriverMatchSpec() {
120+
if (mEventAnimationDriverMatchSpec == null) {
121+
mEventAnimationDriverMatchSpec =
122+
new EventAnimationDriverMatchSpec() {
123+
@Override
124+
public boolean match(int viewTag, String eventName) {
125+
if (!PointerEventHelper.isBubblingEvent(eventName)) {
126+
return false;
127+
}
128+
129+
List<TouchTargetHelper.ViewTarget> viewTargets =
130+
mEventState.getHitPathForActivePointer();
131+
for (TouchTargetHelper.ViewTarget viewTarget : viewTargets) {
132+
if (viewTarget.getViewId() == viewTag && eventName.equals(mEventName)) {
133+
return true;
134+
}
135+
}
136+
return false;
137+
}
138+
};
139+
}
140+
return mEventAnimationDriverMatchSpec;
141+
}
142+
117143
@Override
118144
public void onDispose() {
119145
mPointersEventData = null;
@@ -329,5 +355,9 @@ public final Map<Integer, List<TouchTargetHelper.ViewTarget>> getHitPathByPointe
329355
public final Map<Integer, float[]> getEventCoordinatesByPointerId() {
330356
return mEventCoordinatesByPointerId;
331357
}
358+
359+
public final List<TouchTargetHelper.ViewTarget> getHitPathForActivePointer() {
360+
return mHitPathByPointerId.get(mActivePointerId);
361+
}
332362
}
333363
}

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEventHelper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,18 @@ public static double getPressure(int buttonState, String eventName) {
212212
boolean inActiveButtonState = buttonState != 0;
213213
return inActiveButtonState ? 0.5 : 0;
214214
}
215+
216+
public static boolean isBubblingEvent(String eventName) {
217+
switch (eventName) {
218+
case POINTER_UP:
219+
case POINTER_DOWN:
220+
case POINTER_OVER:
221+
case POINTER_OUT:
222+
case POINTER_MOVE:
223+
case POINTER_CANCEL:
224+
return true;
225+
default:
226+
return false;
227+
}
228+
}
215229
}

0 commit comments

Comments
 (0)