mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Migrate ImageView to NativeComponentRegistry
Summary: Migrates `ImageView` to use `NativeComponentRegistry`, which enables configuring it to avoid reflection by using a static `ViewConfig`. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D25104446 fbshipit-source-id: dd01bf01ead94ca6632b2653b45becf408953bcf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9dfefa8da0
commit
a865bd89d7
@@ -4,26 +4,24 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const requireNativeComponent = require('../ReactNative/requireNativeComponent');
|
||||
|
||||
import type {DangerouslyImpreciseStyle} from '../StyleSheet/StyleSheet';
|
||||
import type {ResolvedAssetSource} from './AssetSourceResolver';
|
||||
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
|
||||
import type {ImageProps} from './ImageProps';
|
||||
import type {ViewProps} from '../Components/View/ViewPropTypes';
|
||||
import type {ImageStyleProp} from '../StyleSheet/StyleSheet';
|
||||
import type {ColorValue} from '../StyleSheet/StyleSheet';
|
||||
import * as NativeComponentRegistry from '../NativeComponent/NativeComponentRegistry';
|
||||
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
|
||||
import type {
|
||||
ColorValue,
|
||||
DangerouslyImpreciseStyle,
|
||||
ImageStyleProp,
|
||||
} from '../StyleSheet/StyleSheet';
|
||||
|
||||
import ImageViewViewConfig from './ImageViewViewConfig';
|
||||
const ReactNativeViewConfigRegistry = require('../Renderer/shims/ReactNativeViewConfigRegistry');
|
||||
|
||||
type NativeProps = $ReadOnly<{|
|
||||
type Props = $ReadOnly<{
|
||||
...ImageProps,
|
||||
...ViewProps,
|
||||
|
||||
@@ -38,19 +36,65 @@ type NativeProps = $ReadOnly<{|
|
||||
headers?: ?string,
|
||||
defaultSrc?: ?string,
|
||||
loadingIndicatorSrc?: ?string,
|
||||
|}>;
|
||||
}>;
|
||||
|
||||
let ImageViewNativeComponent;
|
||||
if (global.RN$Bridgeless) {
|
||||
ReactNativeViewConfigRegistry.register('RCTImageView', () => {
|
||||
return ImageViewViewConfig;
|
||||
});
|
||||
ImageViewNativeComponent = 'RCTImageView';
|
||||
} else {
|
||||
ImageViewNativeComponent = requireNativeComponent<NativeProps>(
|
||||
'RCTImageView',
|
||||
);
|
||||
}
|
||||
const ImageViewNativeComponent: HostComponent<Props> = NativeComponentRegistry.get<Props>(
|
||||
'RCTImageView',
|
||||
() => ({
|
||||
uiViewClassName: 'RCTImageView',
|
||||
bubblingEventTypes: {},
|
||||
directEventTypes: {
|
||||
topLoadStart: {
|
||||
registrationName: 'onLoadStart',
|
||||
},
|
||||
topProgress: {
|
||||
registrationName: 'onProgress',
|
||||
},
|
||||
topError: {
|
||||
registrationName: 'onError',
|
||||
},
|
||||
topPartialLoad: {
|
||||
registrationName: 'onPartialLoad',
|
||||
},
|
||||
topLoad: {
|
||||
registrationName: 'onLoad',
|
||||
},
|
||||
topLoadEnd: {
|
||||
registrationName: 'onLoadEnd',
|
||||
},
|
||||
},
|
||||
validAttributes: {
|
||||
blurRadius: true,
|
||||
capInsets: {
|
||||
diff: require('../Utilities/differ/insetsDiffer'),
|
||||
},
|
||||
defaultSource: {
|
||||
process: require('./resolveAssetSource'),
|
||||
},
|
||||
defaultSrc: true,
|
||||
fadeDuration: true,
|
||||
headers: true,
|
||||
loadingIndicatorSrc: true,
|
||||
onError: true,
|
||||
onLoad: true,
|
||||
onLoadEnd: true,
|
||||
onLoadStart: true,
|
||||
onPartialLoad: true,
|
||||
onProgress: true,
|
||||
overlayColor: {
|
||||
process: require('../StyleSheet/processColor'),
|
||||
},
|
||||
progressiveRenderingEnabled: true,
|
||||
resizeMethod: true,
|
||||
resizeMode: true,
|
||||
shouldNotifyLoadEvents: true,
|
||||
source: true,
|
||||
src: true,
|
||||
tintColor: {
|
||||
process: require('../StyleSheet/processColor'),
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
export default ((ImageViewNativeComponent: any): HostComponent<NativeProps>);
|
||||
export default ImageViewNativeComponent;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import ReactNativeViewViewConfig from '../Components/View/ReactNativeViewViewConfig';
|
||||
import {type ViewConfig} from '../Renderer/shims/ReactNativeTypes';
|
||||
|
||||
const ImageViewViewConfig = {
|
||||
uiViewClassName: 'RCTImageView',
|
||||
bubblingEventTypes: {},
|
||||
directEventTypes: {
|
||||
topLoadStart: {
|
||||
registrationName: 'onLoadStart',
|
||||
},
|
||||
topProgress: {
|
||||
registrationName: 'onProgress',
|
||||
},
|
||||
topError: {
|
||||
registrationName: 'onError',
|
||||
},
|
||||
topPartialLoad: {
|
||||
registrationName: 'onPartialLoad',
|
||||
},
|
||||
topLoad: {
|
||||
registrationName: 'onLoad',
|
||||
},
|
||||
topLoadEnd: {
|
||||
registrationName: 'onLoadEnd',
|
||||
},
|
||||
},
|
||||
validAttributes: {
|
||||
...ReactNativeViewViewConfig.validAttributes,
|
||||
blurRadius: true,
|
||||
// flowlint-next-line unclear-type:off
|
||||
capInsets: {diff: (require('../Utilities/differ/insetsDiffer'): any)},
|
||||
defaultSource: {
|
||||
process: require('./resolveAssetSource'),
|
||||
},
|
||||
defaultSrc: true,
|
||||
fadeDuration: true,
|
||||
headers: true,
|
||||
loadingIndicatorSrc: true,
|
||||
onError: true,
|
||||
onLoad: true,
|
||||
onLoadEnd: true,
|
||||
onLoadStart: true,
|
||||
onPartialLoad: true,
|
||||
onProgress: true,
|
||||
overlayColor: {process: require('../StyleSheet/processColor')},
|
||||
progressiveRenderingEnabled: true,
|
||||
resizeMethod: true,
|
||||
resizeMode: true,
|
||||
shouldNotifyLoadEvents: true,
|
||||
source: true,
|
||||
src: true,
|
||||
tintColor: {process: require('../StyleSheet/processColor')},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = (ImageViewViewConfig: ViewConfig);
|
||||
Reference in New Issue
Block a user