mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 09:27:29 +08:00
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
This commit is contained in:
committed by
Facebook Github Bot
parent
fa7c322af4
commit
f6bcd73ed7
@@ -53,22 +53,21 @@ function requireNativeComponent(
|
||||
extraConfig?: ?{nativeOnly?: Object},
|
||||
): React$ComponentType<any> | 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,22 +51,21 @@ function requireNativeComponent(
|
||||
extraConfig?: ?{nativeOnly?: Object},
|
||||
): React$ComponentType<any> | 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user