/** * Used to create React components that directly wrap native component * 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 * 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 * with `nativePropsToIgnore`; * * Common types are lined up with the appropriate prop differs with * `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`. */ function requireNativeComponent( viewName: string, wrapperComponent: ?Function ): Function { var viewConfig = RCTUIManager[viewName]; if (!viewConfig || !viewConfig.NativeProps) { warning(false, 'Native component for "%s" does not exist', viewName); return UnimplementedView; } var nativeProps = { ...RCTUIManager.RCTView.NativeProps, ...viewConfig.NativeProps, }; viewConfig.uiViewClassName = viewName; viewConfig.validAttributes = {}; for (var key in nativeProps) { // TODO: deep diff by default in diffRawProperties instead of setting it here var differ = TypeToDifferMap[nativeProps[key]] || deepDiffer; viewConfig.validAttributes[key] = {diff: differ}; } if (__DEV__) { wrapperComponent && verifyPropTypes(wrapperComponent, viewConfig); } return createReactNativeComponentClass(viewConfig); }
function requireNativeComponent( viewName: string, componentInterface?: ?ComponentInterface, extraConfig?: ?{nativeOnly?: Object}, ): Function { const viewConfig = UIManager[viewName]; if (!viewConfig || !viewConfig.NativeProps) { warning(false, 'Native component for "%s" does not exist', viewName); return UnimplementedView; } viewConfig.uiViewClassName = viewName; viewConfig.validAttributes = {}; viewConfig.propTypes = componentInterface && componentInterface.propTypes; // The ViewConfig doesn't contain any props inherited from the view manager's // superclass, so we manually merge in the RCTView ones. Other inheritance // patterns are currenty not supported. const nativeProps = { ...UIManager.RCTView.NativeProps, ...viewConfig.NativeProps, }; for (const key in nativeProps) { let useAttribute = false; const attribute = {}; const differ = TypeToDifferMap[nativeProps[key]]; if (differ) { attribute.diff = differ; useAttribute = true; } const processor = TypeToProcessorMap[nativeProps[key]]; if (processor) { attribute.process = processor; useAttribute = true; } viewConfig.validAttributes[key] = useAttribute ? attribute : true; } // Unfortunately, the current set up puts the style properties on the top // level props object. We also need to add the nested form for API // compatibility. This allows these props on both the top level and the // nested style level. TODO: Move these to nested declarations on the // native side. viewConfig.validAttributes.style = ReactNativeStyleAttributes; if (__DEV__) { componentInterface && verifyPropTypes( componentInterface, viewConfig, extraConfig && extraConfig.nativeOnly ); } return createReactNativeComponentClass(viewConfig); }
function requireNativeComponent( viewName: string, componentInterface?: ?ComponentInterface, extraConfig?: ?{nativeOnly?: Object}, ): Function { var viewConfig = RCTUIManager[viewName]; if (!viewConfig || !viewConfig.NativeProps) { warning(false, 'Native component for "%s" does not exist', viewName); return UnimplementedView; } var nativeProps = { ...RCTUIManager.RCTView.NativeProps, ...viewConfig.NativeProps, }; viewConfig.uiViewClassName = viewName; viewConfig.validAttributes = {}; viewConfig.propTypes = componentInterface && componentInterface.propTypes; for (var key in nativeProps) { var useAttribute = false; var attribute = {}; var differ = TypeToDifferMap[nativeProps[key]]; if (differ) { attribute.diff = differ; useAttribute = true; } var processor = TypeToProcessorMap[nativeProps[key]]; if (processor) { attribute.process = processor; useAttribute = true; } viewConfig.validAttributes[key] = useAttribute ? attribute : true; } // Unfortunately, the current set up puts the style properties on the top // level props object. We also need to add the nested form for API // compatibility. This allows these props on both the top level and the // nested style level. TODO: Move these to nested declarations on the // native side. viewConfig.validAttributes.style = ReactNativeStyleAttributes; if (__DEV__) { componentInterface && verifyPropTypes( componentInterface, viewConfig, extraConfig && extraConfig.nativeOnly ); } return createReactNativeComponentClass(viewConfig); }
/** * Used to create React components that directly wrap native component * 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 * 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 * with `nativePropsToIgnore`; * * Common types are lined up with the appropriate prop differs with * `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`. */ function requireNativeComponent( viewName: string, wrapperComponent: ?Function ): Function { var viewConfig = RCTUIManager.viewConfigs && RCTUIManager.viewConfigs[viewName]; if (!viewConfig) { return UnimplementedView; } var nativeProps = { ...RCTUIManager.viewConfigs.RCTView.nativeProps, ...viewConfig.nativeProps, }; viewConfig.validAttributes = {}; for (var key in nativeProps) { // TODO: deep diff by default in diffRawProperties instead of setting it here var differ = TypeToDifferMap[nativeProps[key].type] || deepDiffer; viewConfig.validAttributes[key] = {diff: differ}; } if (__DEV__) { wrapperComponent && verifyPropTypes(wrapperComponent, viewConfig); } return createReactIOSNativeComponentClass(viewConfig); }
/** * Used to create React components that directly wrap native component * 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 * 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 * with `nativePropsToIgnore`; * * Common types are lined up with the appropriate prop differs with * `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`. */ function requireNativeComponent( viewName: string, wrapperComponent: ?Function ): Function { var viewConfig = RCTUIManager[viewName]; if (!viewConfig || !viewConfig.NativeProps) { warning(false, 'Native component for "%s" does not exist', viewName); return UnimplementedView; } var nativeProps = { ...RCTUIManager.RCTView.NativeProps, ...viewConfig.NativeProps, }; viewConfig.uiViewClassName = viewName; viewConfig.validAttributes = {}; for (var key in nativeProps) { var differ = TypeToDifferMap[nativeProps[key]]; viewConfig.validAttributes[key] = differ ? {diff: differ} : true; } if (__DEV__) { wrapperComponent && verifyPropTypes(wrapperComponent, viewConfig); } return createReactNativeComponentClass(viewConfig); }
// Don't load the ViewConfig from UIManager until it's needed for rendering. // Lazy-loading this can help avoid Prepack deopts. function getViewConfig() { const viewConfig = UIManager[viewName]; invariant( viewConfig != null && !viewConfig.NativeProps != null, 'Native component for "%s" does not exist', viewName ); viewConfig.uiViewClassName = viewName; viewConfig.validAttributes = {}; // ReactNative `View.propTypes` have been deprecated in favor of // `ViewPropTypes`. In their place a temporary getter has been added with a // deprecated warning message. Avoid triggering that warning here by using // temporary workaround, __propTypesSecretDontUseThesePlease. // TODO (bvaughn) Revert this particular change any time after April 1 if (componentInterface) { viewConfig.propTypes = typeof componentInterface.__propTypesSecretDontUseThesePlease === 'object' ? componentInterface.__propTypesSecretDontUseThesePlease : componentInterface.propTypes; } else { viewConfig.propTypes = null; } let baseModuleName = viewConfig.baseModuleName; let nativeProps = { ...viewConfig.NativeProps }; while (baseModuleName) { const baseModule = UIManager[baseModuleName]; if (!baseModule) { warning(false, 'Base module "%s" does not exist', baseModuleName); baseModuleName = null; } else { nativeProps = { ...nativeProps, ...baseModule.NativeProps }; baseModuleName = baseModule.baseModuleName; } } for (const key in nativeProps) { let useAttribute = false; const attribute = {}; const differ = TypeToDifferMap[nativeProps[key]]; if (differ) { attribute.diff = differ; useAttribute = true; } const processor = TypeToProcessorMap[nativeProps[key]]; if (processor) { attribute.process = processor; useAttribute = true; } viewConfig.validAttributes[key] = useAttribute ? attribute : true; } // Unfortunately, the current set up puts the style properties on the top // level props object. We also need to add the nested form for API // compatibility. This allows these props on both the top level and the // nested style level. TODO: Move these to nested declarations on the // native side. viewConfig.validAttributes.style = ReactNativeStyleAttributes; if (__DEV__) { componentInterface && verifyPropTypes( componentInterface, viewConfig, extraConfig && extraConfig.nativeOnly ); } // 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. ReactNativeBridgeEventPlugin.processEventTypes(viewConfig); return viewConfig; }
nativeProps.src = source.uri; } if (this.props.defaultSource) { nativeProps.defaultImageSrc = this.props.defaultSource.uri; } return <RawImage {...nativeProps} />; } }); var styles = StyleSheet.create({ base: { overflow: 'hidden', }, }); var RCTNetworkImage = requireNativeComponent('RCTNetworkImageView', null); var RCTStaticImage = requireNativeComponent('RCTStaticImage', null); var nativeOnlyProps = { src: true, defaultImageSrc: true, imageTag: true, contentMode: true, }; if (__DEV__) { verifyPropTypes(Image, RCTStaticImage.viewConfig, nativeOnlyProps); verifyPropTypes(Image, RCTNetworkImage.viewConfig, nativeOnlyProps); } module.exports = Image;
} }); var styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', }, sizeSmall: { height: 20, }, sizeLarge: { height: 36, } }); var RCTActivityIndicatorView = requireNativeComponent( 'RCTActivityIndicatorView', null ); if (__DEV__) { var nativeOnlyProps = {activityIndicatorViewStyle: true}; verifyPropTypes( ActivityIndicatorIOS, RCTActivityIndicatorView.viewConfig, nativeOnlyProps ); } module.exports = ActivityIndicatorIOS;
backgroundColor: '#EFEFEF', }, }); var RCTExNetworkImage = requireNativeComponent('RCTExNetworkImage', null); var RCTExStaticImage = requireNativeComponent('RCTExStaticImage', null); var nativeOnlyProps = { src: true, defaultImageSrc: true, imageTag: true, contentMode: true, imageInfo: true, }; if (__DEV__) { verifyPropTypes(ExImage, RCTExStaticImage.viewConfig, nativeOnlyProps); verifyPropTypes(ExImage, RCTExNetworkImage.viewConfig, nativeOnlyProps); } ExImage.calculateCacheSize = function(callback) { NativeModules.ExNetworkImageManager.calculateCacheSize(callback); } ExImage.clearCache = function(callback) { NativeModules.ExNetworkImageManager.clearCache(callback); } ExImage.clearThumbnailCache = function(callback) { NativeModules.RCTExStaticImageManager.clearThumbnailCache(callback); }
function requireNativeComponent( viewName: string, componentInterface?: ?ComponentInterface, extraConfig?: ?{nativeOnly?: Object}, ): ReactClass<any> | string { const viewConfig = UIManager[viewName]; if (!viewConfig || !viewConfig.NativeProps) { warning(false, 'Native component for "%s" does not exist', viewName); return UnimplementedView; } viewConfig.uiViewClassName = viewName; viewConfig.validAttributes = {}; // ReactNative `View.propTypes` have been deprecated in favor of // `ViewPropTypes`. In their place a temporary getter has been added with a // deprecated warning message. Avoid triggering that warning here by using // temporary workaround, __propTypesSecretDontUseThesePlease. // TODO (bvaughn) Revert this particular change any time after April 1 if (componentInterface) { viewConfig.propTypes = typeof componentInterface.__propTypesSecretDontUseThesePlease === 'object' ? componentInterface.__propTypesSecretDontUseThesePlease : componentInterface.propTypes; } else { viewConfig.propTypes = null; } // The ViewConfig doesn't contain any props inherited from the view manager's // superclass, so we manually merge in the RCTView ones. Other inheritance // patterns are currenty not supported. const nativeProps = { ...UIManager.RCTView.NativeProps, ...viewConfig.NativeProps, }; for (const key in nativeProps) { let useAttribute = false; const attribute = {}; const differ = TypeToDifferMap[nativeProps[key]]; if (differ) { attribute.diff = differ; useAttribute = true; } const processor = TypeToProcessorMap[nativeProps[key]]; if (processor) { attribute.process = processor; useAttribute = true; } viewConfig.validAttributes[key] = useAttribute ? attribute : true; } // Unfortunately, the current set up puts the style properties on the top // level props object. We also need to add the nested form for API // compatibility. This allows these props on both the top level and the // nested style level. TODO: Move these to nested declarations on the // native side. viewConfig.validAttributes.style = ReactNativeStyleAttributes; if (__DEV__) { componentInterface && verifyPropTypes( componentInterface, viewConfig, extraConfig && extraConfig.nativeOnly ); } return createReactNativeComponentClass(viewConfig); }