Skip to content

Commit

Permalink
Use RCTModernEventEmitter in EventAnimationDriver (#42388)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42388

This was our last call site still using the legacy `dispatch` API.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D52906894

fbshipit-source-id: b1c838ee695ce4c60aaed409e7dc46a0dd3f6c2e
  • Loading branch information
javache authored and facebook-github-bot committed Jan 22, 2024
1 parent 6d77d7b commit 94c72d5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import com.facebook.react.bridge.UnexpectedNativeTypeException;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.uimanager.events.EventCategoryDef;
import com.facebook.react.uimanager.events.RCTModernEventEmitter;
import com.facebook.react.uimanager.events.TouchEvent;
import java.util.List;

/** Handles updating a {@link ValueAnimatedNode} when an event gets dispatched. */
/* package */ class EventAnimationDriver implements RCTEventEmitter {
/* package */ class EventAnimationDriver implements RCTModernEventEmitter {
private List<String> mEventPath;
/* package */ ValueAnimatedNode mValueNode;
/* package */ String mEventName;
Expand All @@ -33,7 +35,39 @@ public EventAnimationDriver(
}

@Override
public void receiveEvent(int targetTag, String eventName, @Nullable WritableMap event) {
public void receiveEvent(int targetReactTag, String eventName, @Nullable WritableMap event) {
receiveEvent(-1, targetReactTag, eventName, event);
}

@Override
public void receiveEvent(
int surfaceId, int targetTag, String eventName, @Nullable WritableMap event) {
// We assume this event can't be coalesced. `customCoalesceKey` has no meaning in Fabric.
receiveEvent(surfaceId, targetTag, eventName, false, 0, event, EventCategoryDef.UNSPECIFIED);
}

@Override
public void receiveTouches(
String eventName, WritableArray touches, WritableArray changedIndices) {
throw new UnsupportedOperationException(
"receiveTouches is not support by native animated events");
}

@Override
public void receiveTouches(TouchEvent touchEvent) {
throw new UnsupportedOperationException(
"receiveTouches is not support by native animated events");
}

@Override
public void receiveEvent(
int surfaceId,
int targetTag,
String eventName,
boolean canCoalesceEvent,
int customCoalesceKey,
@Nullable WritableMap event,
@EventCategoryDef int category) {
if (event == null) {
throw new IllegalArgumentException("Native animated events must have event data.");
}
Expand Down Expand Up @@ -79,10 +113,4 @@ public void receiveEvent(int targetTag, String eventName, @Nullable WritableMap
mValueNode.mValue = currArray.getDouble(lastIndex);
}
}

@Override
public void receiveTouches(
String eventName, WritableArray touches, WritableArray changedIndices) {
throw new RuntimeException("receiveTouches is not support by native animated events");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private void handleEvent(Event event) {
if (matchSpec.match(driver.mViewTag, driver.mEventName)) {
foundAtLeastOneDriver = true;
stopAnimationsForNode(driver.mValueNode);
event.dispatch(driver);
event.dispatchModern(driver);
mRunUpdateNodeList.add(driver.mValueNode);
}
}
Expand Down

0 comments on commit 94c72d5

Please sign in to comment.