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

@@ -70,6 +70,17 @@ import javax.annotation.Nullable;
public class UIManagerModule extends ReactContextBaseJavaModule implements
OnBatchCompleteListener, LifecycleEventListener, PerformanceCounter {
/**
* Resolves a name coming from native side to a name of the event that is exposed to JS.
*/
public interface CustomEventNamesResolver {
/**
* Returns custom event name by the provided event name.
*/
@Nullable String resolveCustomEventName(String eventName);
}
protected static final String NAME = "UIManager";
private static final boolean DEBUG = false;
@@ -164,6 +175,27 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
}
}
/**
* Resolves Direct Event name exposed to JS from the one known to the Native side.
*/
public CustomEventNamesResolver getDirectEventNamesResolver() {
return new CustomEventNamesResolver() {
@Override
public @Nullable String resolveCustomEventName(String eventName) {
Map<String, Map> directEventTypes =
(Map<String, Map>) getConstants().get(
UIManagerModuleConstantsHelper.CUSTOM_DIRECT_EVENT_TYPES_KEY);
if (directEventTypes != null) {
Map<String, String> customEventType = (Map<String, String>) directEventTypes.get(eventName);
if (customEventType != null) {
return customEventType.get("registrationName");
}
}
return eventName;
}
};
}
@Override
public Map<String, Long> getPerformanceCounters() {
return mUIImplementation.getProfiledBatchPerfCounters();

View File

@@ -12,7 +12,6 @@ package com.facebook.react.uimanager;
import java.util.List;
import java.util.Map;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.common.MapBuilder;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
@@ -25,8 +24,8 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
*/
/* package */ class UIManagerModuleConstantsHelper {
private static final String CUSTOM_BUBBLING_EVENT_TYPES_KEY = "customBubblingEventTypes";
private static final String CUSTOM_DIRECT_EVENT_TYPES_KEY = "customDirectEventTypes";
/* package */ static final String CUSTOM_BUBBLING_EVENT_TYPES_KEY = "customBubblingEventTypes";
/* package */ static final String CUSTOM_DIRECT_EVENT_TYPES_KEY = "customDirectEventTypes";
/**
* Generates map of constants that is then exposed by {@link UIManagerModule}.
@@ -41,8 +40,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
* TODO(6845124): Create a test for this
*/
/* package */ static Map<String, Object> createConstants(
List<ViewManager> viewManagers,
boolean lazyViewManagersEnabled) {
List<ViewManager> viewManagers, boolean lazyViewManagersEnabled) {
Map<String, Object> constants = UIManagerModuleConstants.getConstants();
// Generic/default event types:
@@ -69,18 +67,20 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
if (viewManagerBubblingEvents != null) {
recursiveMerge(allBubblingEventTypes, viewManagerBubblingEvents);
recursiveMerge(viewManagerBubblingEvents, genericBubblingEventTypes);
viewManagerConstants.put("bubblingEventTypes", viewManagerBubblingEvents);
} else {
viewManagerConstants.put("bubblingEventTypes", genericBubblingEventTypes);
viewManagerBubblingEvents = genericBubblingEventTypes;
}
viewManagerConstants.put("bubblingEventTypes", viewManagerBubblingEvents);
Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
if (viewManagerDirectEvents != null) {
recursiveMerge(allDirectEventTypes, viewManagerDirectEvents);
recursiveMerge(viewManagerDirectEvents, genericDirectEventTypes);
viewManagerConstants.put("directEventTypes", viewManagerDirectEvents);
} else {
viewManagerConstants.put("directEventTypes", genericDirectEventTypes);
viewManagerDirectEvents = genericDirectEventTypes;
}
viewManagerConstants.put("directEventTypes", viewManagerDirectEvents);
Map customViewConstants = viewManager.getExportedViewConstants();
if (customViewConstants != null) {
viewManagerConstants.put("Constants", customViewConstants);