Skip to content

Commit 540120a

Browse files
alanleedevmeta-codesync[bot]
authored andcommitted
Revert D96727336 (#56142)
Summary: Pull Request resolved: #56142 reverting Changelog: [Internal] --- Reviewed By: fkgozali Differential Revision: D97213707 fbshipit-source-id: 1fc070d0399535bddf8ec3b5aeb060a97d6aa16f
1 parent 0f92aa6 commit 540120a

4 files changed

Lines changed: 71 additions & 24 deletions

File tree

packages/react-native/Libraries/Image/Image.android.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import type {HostInstance} from '../../src/private/types/HostInstance';
1212
import type {ImageStyleProp} from '../StyleSheet/StyleSheet';
1313
import type {RootTag} from '../Types/RootTagTypes';
1414
import type {ImageProps} from './ImageProps';
15+
import type {ImageSourceHeaders} from './ImageSourceUtils';
1516
import type {AbstractImageAndroid, ImageAndroid} from './ImageTypes.flow';
1617

18+
import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
1719
import flattenStyle from '../StyleSheet/flattenStyle';
1820
import StyleSheet from '../StyleSheet/StyleSheet';
1921
import ImageAnalyticsTagContext from './ImageAnalyticsTagContext';
@@ -194,37 +196,55 @@ let BaseImage: AbstractImageAndroid = ({
194196
);
195197
}
196198

197-
const nativeProps = restProps as {
198-
...React.PropsOf<ImageViewNativeComponent>,
199-
};
200-
199+
let style_: ImageStyleProp;
200+
let sources_;
201+
let headers_: ?ImageSourceHeaders;
201202
if (Array.isArray(source_)) {
202203
const {
203204
headers: sourceHeaders,
204205
width: sourceWidth,
205206
height: sourceHeight,
206207
} = source_[0];
207-
if (sourceHeaders != null) {
208-
nativeProps.headers = sourceHeaders;
209-
}
208+
headers_ = sourceHeaders;
210209
// Default to the first source's width and height if only one is provided
211-
nativeProps.style = [
212-
source_.length === 1 && {width: sourceWidth, height: sourceHeight},
213-
styles.base,
214-
style,
215-
];
216-
nativeProps.source = source_;
210+
if (ReactNativeFeatureFlags.fixImageSrcDimensionPropagation()) {
211+
style_ = [
212+
source_.length === 1 && {width: sourceWidth, height: sourceHeight},
213+
styles.base,
214+
style,
215+
];
216+
} else {
217+
style_ = [styles.base, style];
218+
}
219+
sources_ = source_;
217220
} else {
218221
const {uri, width: sourceWidth, height: sourceHeight} = source_;
219222
if (uri === '') {
220223
console.warn('source.uri should not be an empty string');
221224
}
222-
nativeProps.style = [
225+
style_ = [
223226
{width: sourceWidth ?? width, height: sourceHeight ?? height},
224227
styles.base,
225228
style,
226229
];
227-
nativeProps.source = [source_];
230+
sources_ = [source_];
231+
}
232+
233+
const nativeProps = restProps as {
234+
...React.PropsOf<ImageViewNativeComponent>,
235+
};
236+
237+
// Both iOS and C++ sides expect to have "source" prop, whereas on Android it's "src"
238+
// (for historical reasons). So in the latter case we populate both "src" and "source",
239+
// in order to have a better alignment between platforms in the future.
240+
// TODO: `src` should be eventually removed from the API on Android.
241+
nativeProps.src = sources_;
242+
nativeProps.source = sources_;
243+
244+
nativeProps.style = style_;
245+
246+
if (headers_ != null) {
247+
nativeProps.headers = headers_;
228248
}
229249

230250
if (onLoadStart != null) {

packages/react-native/Libraries/Image/__tests__/Image-itest.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @flow strict-local
8+
* @fantom_flags fixImageSrcDimensionPropagation:*
89
* @format
910
*/
1011

1112
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1213

1314
import type {AccessibilityProps, HostInstance} from 'react-native';
1415

16+
import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags';
1517
import * as Fantom from '@react-native/fantom';
1618
import * as React from 'react';
1719
import {createRef} from 'react';
@@ -475,14 +477,23 @@ describe('<Image>', () => {
475477
.getRenderedOutput({props: ['source', 'width', 'height']})
476478
.toJSX(),
477479
).toEqual(
478-
<rn-image
479-
source-scale="1"
480-
source-type="remote"
481-
source-size="{40, 40}"
482-
source-uri="https://reactnative.dev/img/tiny_logo.png"
483-
width="40"
484-
height="40"
485-
/>,
480+
ReactNativeFeatureFlags.fixImageSrcDimensionPropagation() ? (
481+
<rn-image
482+
source-scale="1"
483+
source-type="remote"
484+
source-size="{40, 40}"
485+
source-uri="https://reactnative.dev/img/tiny_logo.png"
486+
width="40"
487+
height="40"
488+
/>
489+
) : (
490+
<rn-image
491+
source-scale="1"
492+
source-type="remote"
493+
source-size="{40, 40}"
494+
source-uri="https://reactnative.dev/img/tiny_logo.png"
495+
/>
496+
),
486497
);
487498
});
488499
});

packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,16 @@ const definitions: FeatureFlagDefinitions = {
10761076
},
10771077
ossReleaseStage: 'none',
10781078
},
1079+
fixImageSrcDimensionPropagation: {
1080+
defaultValue: true,
1081+
metadata: {
1082+
description:
1083+
'Fix image dimensions not being passed through when src is used',
1084+
expectedReleaseValue: true,
1085+
purpose: 'release',
1086+
},
1087+
ossReleaseStage: 'none',
1088+
},
10791089
fixVirtualizeListCollapseWindowSize: {
10801090
defaultValue: false,
10811091
metadata: {

packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d929e85924c23746edd258449cdb2d42>>
7+
* @generated SignedSource<<8c2aa180526563dbaaeb91f1428e0c77>>
88
* @flow strict
99
* @noformat
1010
*/
@@ -34,6 +34,7 @@ export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{
3434
deferFlatListFocusChangeRenderUpdate: Getter<boolean>,
3535
disableMaintainVisibleContentPosition: Getter<boolean>,
3636
externalElementInspectionEnabled: Getter<boolean>,
37+
fixImageSrcDimensionPropagation: Getter<boolean>,
3738
fixVirtualizeListCollapseWindowSize: Getter<boolean>,
3839
isLayoutAnimationEnabled: Getter<boolean>,
3940
shouldUseAnimatedObjectForTransform: Getter<boolean>,
@@ -169,6 +170,11 @@ export const disableMaintainVisibleContentPosition: Getter<boolean> = createJava
169170
*/
170171
export const externalElementInspectionEnabled: Getter<boolean> = createJavaScriptFlagGetter('externalElementInspectionEnabled', true);
171172

173+
/**
174+
* Fix image dimensions not being passed through when src is used
175+
*/
176+
export const fixImageSrcDimensionPropagation: Getter<boolean> = createJavaScriptFlagGetter('fixImageSrcDimensionPropagation', true);
177+
172178
/**
173179
* Fixing an edge case where the current window size is not properly calculated with fast scrolling. Window size collapsed to 1 element even if windowSize more than the current amount of elements
174180
*/

0 commit comments

Comments
 (0)