Backed out changeset 322626be193e

Reviewed By: wutalman

Differential Revision: D6258856

fbshipit-source-id: 392dc91f87148c70817f13858a7fcd368f028b2d
This commit is contained in:
Omri Gindi 2017-11-07 04:34:41 -08:00 committed by Facebook Github Bot
parent 164591218f
commit a6465d1c17
3 changed files with 55 additions and 28 deletions

View File

@ -12,7 +12,6 @@
*/ */
'use strict'; 'use strict';
const Platform = require('Platform');
const ReactNativeBridgeEventPlugin = require('ReactNativeBridgeEventPlugin'); const ReactNativeBridgeEventPlugin = require('ReactNativeBridgeEventPlugin');
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes'); const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
const UIManager = require('UIManager'); const UIManager = require('UIManager');
@ -48,18 +47,35 @@ const warning = require('fbjs/lib/warning');
*/ */
import type {ComponentInterface} from 'verifyPropTypes'; import type {ComponentInterface} from 'verifyPropTypes';
let hasAttachedDefaultEventTypes: boolean = false;
function requireNativeComponent( function requireNativeComponent(
viewName: string, viewName: string,
componentInterface?: ?ComponentInterface, componentInterface?: ?ComponentInterface,
extraConfig?: ?{nativeOnly?: Object}, extraConfig?: ?{nativeOnly?: Object},
): React$ComponentType<any> | string { ): React$ComponentType<any> | string {
function attachDefaultEventTypes(viewConfig) { function attachBubblingEventTypes(viewConfig) {
if (Platform.OS === 'android') { if (UIManager.genericBubblingEventTypes) {
// This is supported on Android platform only, viewConfig.bubblingEventTypes = merge(
// as lazy view managers discovery is Android-specific. viewConfig.bubblingEventTypes,
viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes()); UIManager.genericBubblingEventTypes,
);
// As genericBubblingEventTypes do not change over time, and there's
// merge of all the events happening in Fiber, we need to pass
// genericBubblingEventTypes to Fiber only once. Therefore, we can delete
// it and forget about it.
delete UIManager.genericBubblingEventTypes;
}
}
function attachDirectEventTypes(viewConfig) {
if (UIManager.genericDirectEventTypes) {
viewConfig.directEventTypes = merge(
viewConfig.directEventTypes,
UIManager.genericDirectEventTypes,
);
// As genericDirectEventTypes do not change over time, and there's merge
// of all the events happening in Fiber, we need to pass genericDirectEventTypes
// to Fiber only once. Therefore, we can delete it and forget about it.
delete UIManager.genericDirectEventTypes;
} }
} }
@ -168,10 +184,8 @@ function requireNativeComponent(
); );
} }
if (!hasAttachedDefaultEventTypes) { attachBubblingEventTypes(viewConfig);
attachDefaultEventTypes(viewConfig); attachDirectEventTypes(viewConfig);
hasAttachedDefaultEventTypes = true;
}
// Register this view's event types with the ReactNative renderer. // Register this view's event types with the ReactNative renderer.
// This enables view managers to be initialized lazily, improving perf, // This enables view managers to be initialized lazily, improving perf,

View File

@ -17,6 +17,7 @@ import android.content.res.Configuration;
import com.facebook.common.logging.FLog; import com.facebook.common.logging.FLog;
import com.facebook.debug.holder.PrinterHolder; import com.facebook.debug.holder.PrinterHolder;
import com.facebook.debug.tags.ReactDebugOverlayTags; import com.facebook.debug.tags.ReactDebugOverlayTags;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.animation.Animation; import com.facebook.react.animation.Animation;
import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.Callback;
@ -116,6 +117,11 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
private int mBatchId = 0; 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( public UIManagerModule(
ReactApplicationContext reactContext, ReactApplicationContext reactContext,
ViewManagerResolver viewManagerResolver, ViewManagerResolver viewManagerResolver,
@ -229,6 +235,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
} }
} }
@DoNotStrip
@ReactMethod(isBlockingSynchronousMethod = true) @ReactMethod(isBlockingSynchronousMethod = true)
public @Nullable WritableMap getConstantsForViewManager(final String viewManagerName) { public @Nullable WritableMap getConstantsForViewManager(final String viewManagerName) {
ViewManager targetView = ViewManager targetView =
@ -245,8 +252,13 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
try { try {
Map<String, Object> viewManagerConstants = Map<String, Object> viewManagerConstants =
UIManagerModuleConstantsHelper.createConstantsForViewManager( UIManagerModuleConstantsHelper.createConstantsForViewManager(
targetView, null, mCustomDirectEvents); targetView,
mEventsWereSentToJS ? null : UIManagerModuleConstants.getBubblingEventTypeConstants(),
mEventsWereSentToJS ? null : UIManagerModuleConstants.getDirectEventTypeConstants(),
null,
mCustomDirectEvents);
if (viewManagerConstants != null) { if (viewManagerConstants != null) {
mEventsWereSentToJS = true;
return Arguments.makeNativeMap(viewManagerConstants); return Arguments.makeNativeMap(viewManagerConstants);
} }
return null; return null;
@ -255,12 +267,9 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
} }
} }
@ReactMethod(isBlockingSynchronousMethod = true) /**
public WritableMap getDefaultEventTypes() { * Resolves Direct Event name exposed to JS from the one known to the Native side.
return Arguments.makeNativeMap(UIManagerModuleConstantsHelper.getDefaultExportableEventTypes()); */
}
/** Resolves Direct Event name exposed to JS from the one known to the Native side. */
public CustomEventNamesResolver getDirectEventNamesResolver() { public CustomEventNamesResolver getDirectEventNamesResolver() {
return new CustomEventNamesResolver() { return new CustomEventNamesResolver() {
@Override @Override

View File

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