mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 11:57:46 +08:00
Fix regression in Java->C++->JS ViewManagers interaction.
Reviewed By: bvaughn Differential Revision: D5953937 fbshipit-source-id: 8bc5dd8a483054ab9830ab653f2a3b41cad6c791
This commit is contained in:
committed by
Facebook Github Bot
parent
6ba9ad8ece
commit
346af557c3
@@ -52,6 +52,61 @@ function requireNativeComponent(
|
||||
componentInterface?: ?ComponentInterface,
|
||||
extraConfig?: ?{nativeOnly?: Object},
|
||||
): React$ComponentType<any> | string {
|
||||
function attachBubblingEventTypes(viewConfig) {
|
||||
if (UIManager.genericBubblingEventTypes) {
|
||||
viewConfig.bubblingEventTypes = merge(
|
||||
viewConfig.bubblingEventTypes,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
function merge(destination: ?Object, source: ?Object): ?Object {
|
||||
if (!source) {
|
||||
return destination;
|
||||
}
|
||||
if (!destination) {
|
||||
return source;
|
||||
}
|
||||
|
||||
for (const key in source) {
|
||||
if (!source.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var sourceValue = source[key];
|
||||
if (destination.hasOwnProperty(key)) {
|
||||
const destinationValue = destination[key];
|
||||
if (
|
||||
typeof sourceValue === 'object' &&
|
||||
typeof destinationValue === 'object'
|
||||
) {
|
||||
sourceValue = merge(destinationValue, sourceValue);
|
||||
}
|
||||
}
|
||||
destination[key] = sourceValue;
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
// Don't load the ViewConfig from UIManager until it's needed for rendering.
|
||||
// Lazy-loading this can help avoid Prepack deopts.
|
||||
function getViewConfig() {
|
||||
@@ -129,6 +184,9 @@ function requireNativeComponent(
|
||||
);
|
||||
}
|
||||
|
||||
attachBubblingEventTypes(viewConfig);
|
||||
attachDirectEventTypes(viewConfig);
|
||||
|
||||
// Register this view's event types with the ReactNative renderer.
|
||||
// This enables view managers to be initialized lazily, improving perf,
|
||||
// While also enabling 3rd party components to define custom event types.
|
||||
|
||||
Reference in New Issue
Block a user