Skip to content

Commit a6465d1

Browse files
ginandifacebook-github-bot
authored andcommitted
Backed out changeset 322626be193e
Reviewed By: wutalman Differential Revision: D6258856 fbshipit-source-id: 392dc91f87148c70817f13858a7fcd368f028b2d
1 parent 1645912 commit a6465d1

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

Libraries/ReactNative/requireNativeComponent.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
'use strict';
1414

15-
const Platform = require('Platform');
1615
const ReactNativeBridgeEventPlugin = require('ReactNativeBridgeEventPlugin');
1716
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
1817
const UIManager = require('UIManager');
@@ -48,18 +47,35 @@ const warning = require('fbjs/lib/warning');
4847
*/
4948
import type {ComponentInterface} from 'verifyPropTypes';
5049

51-
let hasAttachedDefaultEventTypes: boolean = false;
52-
5350
function requireNativeComponent(
5451
viewName: string,
5552
componentInterface?: ?ComponentInterface,
5653
extraConfig?: ?{nativeOnly?: Object},
5754
): React$ComponentType<any> | string {
58-
function attachDefaultEventTypes(viewConfig) {
59-
if (Platform.OS === 'android') {
60-
// This is supported on Android platform only,
61-
// as lazy view managers discovery is Android-specific.
62-
viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes());
55+
function attachBubblingEventTypes(viewConfig) {
56+
if (UIManager.genericBubblingEventTypes) {
57+
viewConfig.bubblingEventTypes = merge(
58+
viewConfig.bubblingEventTypes,
59+
UIManager.genericBubblingEventTypes,
60+
);
61+
// As genericBubblingEventTypes do not change over time, and there's
62+
// merge of all the events happening in Fiber, we need to pass
63+
// genericBubblingEventTypes to Fiber only once. Therefore, we can delete
64+
// it and forget about it.
65+
delete UIManager.genericBubblingEventTypes;
66+
}
67+
}
68+
69+
function attachDirectEventTypes(viewConfig) {
70+
if (UIManager.genericDirectEventTypes) {
71+
viewConfig.directEventTypes = merge(
72+
viewConfig.directEventTypes,
73+
UIManager.genericDirectEventTypes,
74+
);
75+
// As genericDirectEventTypes do not change over time, and there's merge
76+
// of all the events happening in Fiber, we need to pass genericDirectEventTypes
77+
// to Fiber only once. Therefore, we can delete it and forget about it.
78+
delete UIManager.genericDirectEventTypes;
6379
}
6480
}
6581

@@ -168,10 +184,8 @@ function requireNativeComponent(
168184
);
169185
}
170186

171-
if (!hasAttachedDefaultEventTypes) {
172-
attachDefaultEventTypes(viewConfig);
173-
hasAttachedDefaultEventTypes = true;
174-
}
187+
attachBubblingEventTypes(viewConfig);
188+
attachDirectEventTypes(viewConfig);
175189

176190
// Register this view's event types with the ReactNative renderer.
177191
// This enables view managers to be initialized lazily, improving perf,

ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.facebook.common.logging.FLog;
1818
import com.facebook.debug.holder.PrinterHolder;
1919
import com.facebook.debug.tags.ReactDebugOverlayTags;
20+
import com.facebook.proguard.annotations.DoNotStrip;
2021
import com.facebook.react.animation.Animation;
2122
import com.facebook.react.bridge.Arguments;
2223
import com.facebook.react.bridge.Callback;
@@ -116,6 +117,11 @@ public interface CustomEventNamesResolver {
116117

117118
private int mBatchId = 0;
118119

120+
// Defines if events were already exported to JS. We do not send them more
121+
// than once as they are stored and mixed in with Fiber for every ViewManager
122+
// on JS side.
123+
private boolean mEventsWereSentToJS = false;
124+
119125
public UIManagerModule(
120126
ReactApplicationContext reactContext,
121127
ViewManagerResolver viewManagerResolver,
@@ -229,6 +235,7 @@ private static Map<String, Object> createConstants(
229235
}
230236
}
231237

238+
@DoNotStrip
232239
@ReactMethod(isBlockingSynchronousMethod = true)
233240
public @Nullable WritableMap getConstantsForViewManager(final String viewManagerName) {
234241
ViewManager targetView =
@@ -245,8 +252,13 @@ private static Map<String, Object> createConstants(
245252
try {
246253
Map<String, Object> viewManagerConstants =
247254
UIManagerModuleConstantsHelper.createConstantsForViewManager(
248-
targetView, null, mCustomDirectEvents);
255+
targetView,
256+
mEventsWereSentToJS ? null : UIManagerModuleConstants.getBubblingEventTypeConstants(),
257+
mEventsWereSentToJS ? null : UIManagerModuleConstants.getDirectEventTypeConstants(),
258+
null,
259+
mCustomDirectEvents);
249260
if (viewManagerConstants != null) {
261+
mEventsWereSentToJS = true;
250262
return Arguments.makeNativeMap(viewManagerConstants);
251263
}
252264
return null;
@@ -255,12 +267,9 @@ private static Map<String, Object> createConstants(
255267
}
256268
}
257269

258-
@ReactMethod(isBlockingSynchronousMethod = true)
259-
public WritableMap getDefaultEventTypes() {
260-
return Arguments.makeNativeMap(UIManagerModuleConstantsHelper.getDefaultExportableEventTypes());
261-
}
262-
263-
/** Resolves Direct Event name exposed to JS from the one known to the Native side. */
270+
/**
271+
* Resolves Direct Event name exposed to JS from the one known to the Native side.
272+
*/
264273
public CustomEventNamesResolver getDirectEventNamesResolver() {
265274
return new CustomEventNamesResolver() {
266275
@Override

ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
*/
2525
/* package */ class UIManagerModuleConstantsHelper {
2626

27-
private static final String BUBBLING_EVENTS_KEY = "bubblingEventTypes";
28-
private static final String DIRECT_EVENTS_KEY = "directEventTypes";
29-
3027
/**
3128
* Generates a lazy discovery enabled version of {@link UIManagerModule} constants. It only
3229
* contains a list of view manager names, so that JS side is aware of the managers there are.
@@ -41,12 +38,6 @@
4138
return constants;
4239
}
4340

44-
/* package */ static Map<String, Object> getDefaultExportableEventTypes() {
45-
return MapBuilder.<String, Object>of(
46-
BUBBLING_EVENTS_KEY, UIManagerModuleConstants.getBubblingEventTypeConstants(),
47-
DIRECT_EVENTS_KEY, UIManagerModuleConstants.getDirectEventTypeConstants());
48-
}
49-
5041
/**
5142
* Generates map of constants that is then exposed by {@link UIManagerModule}.
5243
* Provided list of {@param viewManagers} is then used to populate content of
@@ -93,6 +84,8 @@
9384
try {
9485
Map viewManagerConstants = createConstantsForViewManager(
9586
viewManager,
87+
null,
88+
null,
9689
allBubblingEventTypes,
9790
allDirectEventTypes);
9891
if (!viewManagerConstants.isEmpty()) {
@@ -110,20 +103,31 @@
110103

111104
/* package */ static Map<String, Object> createConstantsForViewManager(
112105
ViewManager viewManager,
106+
@Nullable Map defaultBubblingEvents,
107+
@Nullable Map defaultDirectEvents,
113108
@Nullable Map cumulativeBubblingEventTypes,
114109
@Nullable Map cumulativeDirectEventTypes) {
110+
final String BUBBLING_EVENTS_KEY = "bubblingEventTypes";
111+
final String DIRECT_EVENTS_KEY = "directEventTypes";
112+
115113
Map<String, Object> viewManagerConstants = MapBuilder.newHashMap();
116114

117115
Map viewManagerBubblingEvents = viewManager.getExportedCustomBubblingEventTypeConstants();
118116
if (viewManagerBubblingEvents != null) {
119117
recursiveMerge(cumulativeBubblingEventTypes, viewManagerBubblingEvents);
118+
recursiveMerge(viewManagerBubblingEvents, defaultBubblingEvents);
120119
viewManagerConstants.put(BUBBLING_EVENTS_KEY, viewManagerBubblingEvents);
120+
} else if (defaultBubblingEvents != null) {
121+
viewManagerConstants.put(BUBBLING_EVENTS_KEY, defaultBubblingEvents);
121122
}
122123

123124
Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
124125
if (viewManagerDirectEvents != null) {
125126
recursiveMerge(cumulativeDirectEventTypes, viewManagerDirectEvents);
127+
recursiveMerge(viewManagerDirectEvents, defaultDirectEvents);
126128
viewManagerConstants.put(DIRECT_EVENTS_KEY, viewManagerDirectEvents);
129+
} else if (defaultDirectEvents != null) {
130+
viewManagerConstants.put(DIRECT_EVENTS_KEY, defaultDirectEvents);
127131
}
128132

129133
Map customViewConstants = viewManager.getExportedViewConstants();

0 commit comments

Comments
 (0)