Make RN Events registered disregarding ViewManager use pattern.

Reviewed By: bvaughn

Differential Revision: D6223864

fbshipit-source-id: 322626be193e5fa840d3e5477e86adaa90f2726d
This commit is contained in:
Dmitry Zakharov
2017-11-06 06:16:38 -08:00
committed by Facebook Github Bot
parent 3f1b021506
commit fdf04953c0
3 changed files with 28 additions and 55 deletions

View File

@@ -17,7 +17,6 @@ import android.content.res.Configuration;
import com.facebook.common.logging.FLog;
import com.facebook.debug.holder.PrinterHolder;
import com.facebook.debug.tags.ReactDebugOverlayTags;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.animation.Animation;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
@@ -117,11 +116,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
private int mBatchId = 0;
// Defines if events were already exported to JS. We do not send them more
// than once as they are stored and mixed in with Fiber for every ViewManager
// on JS side.
private boolean mEventsWereSentToJS = false;
public UIManagerModule(
ReactApplicationContext reactContext,
ViewManagerResolver viewManagerResolver,
@@ -235,7 +229,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
}
}
@DoNotStrip
@ReactMethod(isBlockingSynchronousMethod = true)
public @Nullable WritableMap getConstantsForViewManager(final String viewManagerName) {
ViewManager targetView =
@@ -252,13 +245,8 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
try {
Map<String, Object> viewManagerConstants =
UIManagerModuleConstantsHelper.createConstantsForViewManager(
targetView,
mEventsWereSentToJS ? null : UIManagerModuleConstants.getBubblingEventTypeConstants(),
mEventsWereSentToJS ? null : UIManagerModuleConstants.getDirectEventTypeConstants(),
null,
mCustomDirectEvents);
targetView, null, mCustomDirectEvents);
if (viewManagerConstants != null) {
mEventsWereSentToJS = true;
return Arguments.makeNativeMap(viewManagerConstants);
}
return null;
@@ -267,9 +255,12 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
}
}
/**
* Resolves Direct Event name exposed to JS from the one known to the Native side.
*/
@ReactMethod(isBlockingSynchronousMethod = true)
public WritableMap getDefaultEventTypes() {
return Arguments.makeNativeMap(UIManagerModuleConstantsHelper.getDefaultExportableEventTypes());
}
/** Resolves Direct Event name exposed to JS from the one known to the Native side. */
public CustomEventNamesResolver getDirectEventNamesResolver() {
return new CustomEventNamesResolver() {
@Override

View File

@@ -24,6 +24,9 @@ import javax.annotation.Nullable;
*/
/* package */ class UIManagerModuleConstantsHelper {
private static final String BUBBLING_EVENTS_KEY = "bubblingEventTypes";
private static final String DIRECT_EVENTS_KEY = "directEventTypes";
/**
* Generates a lazy discovery enabled version of {@link UIManagerModule} constants. It only
* contains a list of view manager names, so that JS side is aware of the managers there are.
@@ -38,6 +41,12 @@ import javax.annotation.Nullable;
return constants;
}
/* package */ static Map<String, Object> getDefaultExportableEventTypes() {
return MapBuilder.<String, Object>of(
BUBBLING_EVENTS_KEY, UIManagerModuleConstants.getBubblingEventTypeConstants(),
DIRECT_EVENTS_KEY, UIManagerModuleConstants.getDirectEventTypeConstants());
}
/**
* Generates map of constants that is then exposed by {@link UIManagerModule}.
* Provided list of {@param viewManagers} is then used to populate content of
@@ -84,8 +93,6 @@ import javax.annotation.Nullable;
try {
Map viewManagerConstants = createConstantsForViewManager(
viewManager,
null,
null,
allBubblingEventTypes,
allDirectEventTypes);
if (!viewManagerConstants.isEmpty()) {
@@ -103,31 +110,20 @@ import javax.annotation.Nullable;
/* package */ static Map<String, Object> createConstantsForViewManager(
ViewManager viewManager,
@Nullable Map defaultBubblingEvents,
@Nullable Map defaultDirectEvents,
@Nullable Map cumulativeBubblingEventTypes,
@Nullable Map cumulativeDirectEventTypes) {
final String BUBBLING_EVENTS_KEY = "bubblingEventTypes";
final String DIRECT_EVENTS_KEY = "directEventTypes";
Map<String, Object> viewManagerConstants = MapBuilder.newHashMap();
Map viewManagerBubblingEvents = viewManager.getExportedCustomBubblingEventTypeConstants();
if (viewManagerBubblingEvents != null) {
recursiveMerge(cumulativeBubblingEventTypes, viewManagerBubblingEvents);
recursiveMerge(viewManagerBubblingEvents, defaultBubblingEvents);
viewManagerConstants.put(BUBBLING_EVENTS_KEY, viewManagerBubblingEvents);
} else if (defaultBubblingEvents != null) {
viewManagerConstants.put(BUBBLING_EVENTS_KEY, defaultBubblingEvents);
}
Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
if (viewManagerDirectEvents != null) {
recursiveMerge(cumulativeDirectEventTypes, viewManagerDirectEvents);
recursiveMerge(viewManagerDirectEvents, defaultDirectEvents);
viewManagerConstants.put(DIRECT_EVENTS_KEY, viewManagerDirectEvents);
} else if (defaultDirectEvents != null) {
viewManagerConstants.put(DIRECT_EVENTS_KEY, defaultDirectEvents);
}
Map customViewConstants = viewManager.getExportedViewConstants();