From da982aa0b421b2539fca943722923977d89ca403 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 14 Mar 2018 11:07:45 -0400 Subject: [PATCH] Make generic event types less platform-specific A previous PR (#18308) enabled lazy loading of view manager constants. This PR enables any platform to use of generic bubbling and direct event types by exposing the constants `genericBubblingEventTypes` or `genericDirectEventTypes` on the UIManagerModule. --- .../ReactNative/requireFabricComponent.js | 31 +++++++++---------- .../ReactNative/requireNativeComponent.js | 31 +++++++++---------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Libraries/ReactNative/requireFabricComponent.js b/Libraries/ReactNative/requireFabricComponent.js index 1544c6fdff976e..a83c60f5e78fd4 100644 --- a/Libraries/ReactNative/requireFabricComponent.js +++ b/Libraries/ReactNative/requireFabricComponent.js @@ -53,22 +53,21 @@ function requireNativeComponent( extraConfig?: ?{nativeOnly?: Object}, ): React$ComponentType | string { function attachDefaultEventTypes(viewConfig: any) { - if (Platform.OS === 'android') { - // This is supported on Android platform only, - // as lazy view managers discovery is Android-specific. - if (UIManager.ViewManagerNames) { - // Lazy view managers enabled. - viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes()); - } else { - viewConfig.bubblingEventTypes = merge( - viewConfig.bubblingEventTypes, - UIManager.genericBubblingEventTypes, - ); - viewConfig.directEventTypes = merge( - viewConfig.directEventTypes, - UIManager.genericDirectEventTypes, - ); - } + // This is used for lazy view managers discovery. + if (UIManager.ViewManagerNames) { + // Lazy view managers enabled. + viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes()); + } else if (UIManager.genericBubblingEventTypes || UIManager.genericDirectEventTypes) { + // This is used when a generic set of events + // is configured for all view managers. + viewConfig.bubblingEventTypes = merge( + viewConfig.bubblingEventTypes, + UIManager.genericBubblingEventTypes, + ); + viewConfig.directEventTypes = merge( + viewConfig.directEventTypes, + UIManager.genericDirectEventTypes, + ); } } diff --git a/Libraries/ReactNative/requireNativeComponent.js b/Libraries/ReactNative/requireNativeComponent.js index 2a6c7c8ca71e8d..b5fcdc948319d0 100644 --- a/Libraries/ReactNative/requireNativeComponent.js +++ b/Libraries/ReactNative/requireNativeComponent.js @@ -51,22 +51,21 @@ function requireNativeComponent( extraConfig?: ?{nativeOnly?: Object}, ): React$ComponentType | string { function attachDefaultEventTypes(viewConfig: any) { - if (Platform.OS === 'android') { - // This is supported on Android platform only, - // as lazy view managers discovery is Android-specific. - if (UIManager.ViewManagerNames) { - // Lazy view managers enabled. - viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes()); - } else { - viewConfig.bubblingEventTypes = merge( - viewConfig.bubblingEventTypes, - UIManager.genericBubblingEventTypes, - ); - viewConfig.directEventTypes = merge( - viewConfig.directEventTypes, - UIManager.genericDirectEventTypes, - ); - } + // This is used for lazy view managers discovery. + if (UIManager.ViewManagerNames) { + // Lazy view managers enabled. + viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes()); + } else if (UIManager.genericBubblingEventTypes || UIManager.genericDirectEventTypes) { + // This is used when a generic set of events + // is configured for all view managers. + viewConfig.bubblingEventTypes = merge( + viewConfig.bubblingEventTypes, + UIManager.genericBubblingEventTypes, + ); + viewConfig.directEventTypes = merge( + viewConfig.directEventTypes, + UIManager.genericDirectEventTypes, + ); } }