mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
[ReactNative] cleanup native components
This commit is contained in:
@@ -27,19 +27,22 @@ var warning = require('warning');
|
||||
* implementations. Config information is extracted from data exported from the
|
||||
* RCTUIManager module. You should also wrap the native component in a
|
||||
* hand-written component with full propTypes definitions and other
|
||||
* documentation - pass the hand-written component in as `wrapperComponent` to
|
||||
* documentation - pass the hand-written component in as `componentInterface` to
|
||||
* verify all the native props are documented via `propTypes`.
|
||||
*
|
||||
* If some native props shouldn't be exposed in the wrapper interface, you can
|
||||
* pass null for `wrapperComponent` and call `verifyPropTypes` directly
|
||||
* pass null for `componentInterface` and call `verifyPropTypes` directly
|
||||
* with `nativePropsToIgnore`;
|
||||
*
|
||||
* Common types are lined up with the appropriate prop differs with
|
||||
* `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`.
|
||||
*/
|
||||
import type { ComponentInterface } from 'verifyPropTypes';
|
||||
|
||||
function requireNativeComponent(
|
||||
viewName: string,
|
||||
wrapperComponent: ?Function
|
||||
componentInterface?: ?ComponentInterface,
|
||||
extraConfig?: ?{nativeOnly?: Object},
|
||||
): Function {
|
||||
var viewConfig = RCTUIManager[viewName];
|
||||
if (!viewConfig || !viewConfig.NativeProps) {
|
||||
@@ -52,12 +55,17 @@ function requireNativeComponent(
|
||||
};
|
||||
viewConfig.uiViewClassName = viewName;
|
||||
viewConfig.validAttributes = {};
|
||||
viewConfig.propTypes = componentInterface && componentInterface.propTypes;
|
||||
for (var key in nativeProps) {
|
||||
var differ = TypeToDifferMap[nativeProps[key]];
|
||||
viewConfig.validAttributes[key] = differ ? {diff: differ} : true;
|
||||
}
|
||||
if (__DEV__) {
|
||||
wrapperComponent && verifyPropTypes(wrapperComponent, viewConfig);
|
||||
componentInterface && verifyPropTypes(
|
||||
componentInterface,
|
||||
viewConfig,
|
||||
extraConfig && extraConfig.nativeOnly
|
||||
);
|
||||
}
|
||||
return createReactNativeComponentClass(viewConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user