Untangle NativeAnimatedNodesManager from UIManager internals.

Reviewed By: AaaChiuuu

Differential Revision: D5861523

fbshipit-source-id: 39eb79b91d4d5e2295d03369f1be585ae7836c75
This commit is contained in:
Dmitry Zakharov
2017-09-19 09:56:18 -07:00
committed by Facebook Github Bot
parent 5180995666
commit 4fc9e20fce
4 changed files with 67 additions and 19 deletions

View File

@@ -11,7 +11,6 @@ package com.facebook.react.animated;
import android.util.SparseArray;
import com.facebook.infer.annotation.Assertions;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
@@ -59,7 +58,7 @@ import javax.annotation.Nullable;
// Mapping of a view tag and an event name to a list of event animation drivers. 99% of the time
// there will be only one driver per mapping so all code code should be optimized around that.
private final Map<String, List<EventAnimationDriver>> mEventDrivers = new HashMap<>();
private final Map<String, Map<String, String>> mCustomEventTypes;
private final UIManagerModule.CustomEventNamesResolver mCustomEventNamesResolver;
private final UIImplementation mUIImplementation;
private int mAnimatedGraphBFSColor = 0;
// Used to avoid allocating a new array on every frame in `runUpdates` and `onEventDispatch`.
@@ -68,8 +67,7 @@ import javax.annotation.Nullable;
public NativeAnimatedNodesManager(UIManagerModule uiManager) {
mUIImplementation = uiManager.getUIImplementation();
uiManager.getEventDispatcher().addListener(this);
Object customEventTypes = Assertions.assertNotNull(uiManager.getConstants()).get("customDirectEventTypes");
mCustomEventTypes = (Map<String, Map<String, String>>) customEventTypes;
mCustomEventNamesResolver = uiManager.getDirectEventNamesResolver();
}
/*package*/ @Nullable AnimatedNode getNodeById(int id) {
@@ -371,12 +369,7 @@ import javax.annotation.Nullable;
if (!mEventDrivers.isEmpty()) {
// If the event has a different name in native convert it to it's JS name.
String eventName = event.getEventName();
Map<String, String> customEventType = mCustomEventTypes.get(eventName);
if (customEventType != null) {
eventName = customEventType.get("registrationName");
}
String eventName = mCustomEventNamesResolver.resolveCustomEventName(event.getEventName());
List<EventAnimationDriver> driversForKey = mEventDrivers.get(event.getViewTag() + eventName);
if (driversForKey != null) {
for (EventAnimationDriver driver : driversForKey) {