Skip to content

Commit e22a27f

Browse files
Emily Janzerfacebook-github-bot
authored andcommitted
Use JS view configs for Image
Summary: There was already a ImageViewNativeComponent used on Android, so I changed `Image.ios.js` to use it as well, and then switched that component to use `codegenNativeComponent` instead of `requireNativeComponent` so that it gets the view config from JS instead of the UIManager. I'm gating this change behind `RN$Bridgeless` so this only affects bridgeless mode. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D18575533 fbshipit-source-id: aa71beb6be65dbb48ad2e1ca748f2cccd72a0e73
1 parent e6d566f commit e22a27f

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

Libraries/Image/Image.ios.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,19 @@
1111
'use strict';
1212

1313
const DeprecatedImagePropType = require('../DeprecatedPropTypes/DeprecatedImagePropType');
14-
const NativeModules = require('../BatchedBridge/NativeModules');
1514
const React = require('react');
1615
const ReactNative = require('../Renderer/shims/ReactNative'); // eslint-disable-line no-unused-vars
1716
const StyleSheet = require('../StyleSheet/StyleSheet');
1817

1918
const flattenStyle = require('../StyleSheet/flattenStyle');
20-
const requireNativeComponent = require('../ReactNative/requireNativeComponent');
2119
const resolveAssetSource = require('./resolveAssetSource');
2220

2321
import type {ImageProps as ImagePropsType} from './ImageProps';
24-
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
2522

2623
import type {ImageStyleProp} from '../StyleSheet/StyleSheet';
2724
import NativeImageLoaderIOS from './NativeImageLoaderIOS';
2825

29-
const ImageViewManager = NativeModules.ImageViewManager;
30-
const RCTImageView: HostComponent<mixed> = requireNativeComponent(
31-
'RCTImageView',
32-
);
26+
const RCTImageView = require('./ImageViewNativeComponent');
3327

3428
function getSize(
3529
uri: string,

Libraries/Image/ImageViewNativeComponent.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,43 @@
1212

1313
const requireNativeComponent = require('../ReactNative/requireNativeComponent');
1414

15+
import codegenNativeComponent from '../Utilities/codegenNativeComponent';
16+
17+
import type {DangerouslyImpreciseStyle} from '../StyleSheet/StyleSheet';
18+
import type {ResolvedAssetSource} from './AssetSourceResolver';
1519
import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
20+
import type {ImageProps} from './ImageProps';
21+
import type {ViewProps} from '../Components/View/ViewPropTypes';
22+
import type {ImageStyleProp} from '../StyleSheet/StyleSheet';
23+
import type {ColorValue} from '../StyleSheet/StyleSheetTypes';
24+
25+
type NativeProps = $ReadOnly<{|
26+
...ImageProps,
27+
...ViewProps,
28+
29+
style?: ImageStyleProp | DangerouslyImpreciseStyle,
30+
31+
// iOS native props
32+
tintColor?: ColorValue,
33+
34+
// Android native props
35+
shouldNotifyLoadEvents?: boolean,
36+
src?: ?ResolvedAssetSource | $ReadOnlyArray<{uri: string}>,
37+
headers?: ?string,
38+
defaultSrc?: ?string,
39+
loadingIndicatorSrc?: ?string,
40+
|}>;
41+
42+
let ImageViewNativeComponent;
1643

17-
const ImageViewNativeComponent: HostComponent<mixed> = requireNativeComponent<mixed>(
18-
'RCTImageView',
19-
);
44+
if (global.RN$Bridgeless) {
45+
ImageViewNativeComponent = codegenNativeComponent<NativeProps>(
46+
'RCTImageView',
47+
);
48+
} else {
49+
ImageViewNativeComponent = requireNativeComponent<NativeProps>(
50+
'RCTImageView',
51+
);
52+
}
2053

21-
module.exports = ImageViewNativeComponent;
54+
module.exports = (ImageViewNativeComponent: HostComponent<NativeProps>);

0 commit comments

Comments
 (0)