From f6bcd73ed7cdc1f76a940e301a42d8b578f890c8 Mon Sep 17 00:00:00 2001 From: Jeff Hampton Date: Tue, 20 Mar 2018 05:15:48 -0700 Subject: [PATCH] feat: Remove platform check in requireNativeComponent to support additional platforms Summary: Using platform checks can make it difficult to incorporate changes for other platforms (e.g. Windows). Using a check for the underlying function accomplishes the same goal without relying on an Android-specific check. This change allows this JS file to be re-used instead of copied and modified. [X] Run Jest tests [X] Test in RNTester on simulators [X] Test in Playground No related PR's found :) [GENERAL] [ENHANCEMENT] [Libraries/ReactNative/requireFabricComponent.js] - Simplified check against UIManager to support additional platforms, removing Android-specific check Closes https://github.com/facebook/react-native/pull/18381 Differential Revision: D7336214 Pulled By: hramos fbshipit-source-id: e936f1fdcf36556c528115ee3f79197883d7b7d4 --- .../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 4b6010a0c..4d9fca04c 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 supported on UIManager platforms (ex: Android), + // as lazy view managers are not implemented for all platforms. + // See [UIManager] for details on constants and implementations. + 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, + ); } } diff --git a/Libraries/ReactNative/requireNativeComponent.js b/Libraries/ReactNative/requireNativeComponent.js index 4a6fd4c13..453be93f7 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 supported on UIManager platforms (ex: Android), + // as lazy view managers are not implemented for all platforms. + // See [UIManager] for details on constants and implementations. + 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, + ); } }