Skip to content

Commit e560782

Browse files
Bartlomiej Bloniarzmeta-codesync[bot]
authored andcommitted
Default Image resizeMode to cover in C++ (#58862)
Summary: Pull Request resolved: #58862 `ImageProps` defaulted `resizeMode` to `stretch`, while the JS `Image` default, the documented default and every Android image view use `cover`. On Android, props equal to their C++ default are not sent when a view is created, so an explicit `resizeMode="stretch"` never reached the view and the image rendered as `cover`. The C++ default is now `cover`. `Image` always sends `resizeMode` on every platform, so the value components receive is unchanged, and iOS initializes its content mode from the default props. Changelog: [General][Fixed] - Fix explicit `resizeMode="stretch"` being ignored on newly created Android `Image`s Reviewed By: javache, christophpurrer Differential Revision: D123029410 fbshipit-source-id: bd9383c68cefc39749ab7f056a4f70a74efd2baa
1 parent 1c7a66b commit e560782

3 files changed

Lines changed: 8 additions & 18 deletions

File tree

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,15 @@ describe('<Image>', () => {
3636
});
3737

3838
expect(root.getRenderedOutput().toJSX()).toEqual(
39-
<rn-image
40-
overflow="hidden"
41-
resizeMode="cover"
42-
source-scale="1"
43-
source-type="remote"
44-
/>,
39+
<rn-image overflow="hidden" source-scale="1" source-type="remote" />,
4540
);
4641

4742
Fantom.runTask(() => {
4843
root.render(<Image src="" />);
4944
});
5045

5146
expect(root.getRenderedOutput().toJSX()).toEqual(
52-
<rn-image
53-
overflow="hidden"
54-
resizeMode="cover"
55-
source-scale="1"
56-
source-type="remote"
57-
/>,
47+
<rn-image overflow="hidden" source-scale="1" source-type="remote" />,
5848
);
5949
});
6050
});
@@ -282,7 +272,7 @@ describe('<Image>', () => {
282272
});
283273

284274
expect(root.getRenderedOutput({props: ['resizeMode']}).toJSX()).toEqual(
285-
<rn-image resizeMode="cover" />,
275+
<rn-image />,
286276
);
287277
});
288278

@@ -294,19 +284,19 @@ describe('<Image>', () => {
294284
});
295285

296286
expect(root.getRenderedOutput({props: ['resizeMode']}).toJSX()).toEqual(
297-
<rn-image resizeMode="cover" />,
287+
<rn-image />,
298288
);
299289
});
300290

301-
it('can be set to "stretch", which is the same as not setting it', () => {
291+
it('can be set to "stretch"', () => {
302292
const root = Fantom.createRoot();
303293

304294
Fantom.runTask(() => {
305295
root.render(<Image resizeMode="stretch" source={LOGO_SOURCE} />);
306296
});
307297

308298
expect(root.getRenderedOutput({props: ['resizeMode']}).toJSX()).toEqual(
309-
<rn-image />,
299+
<rn-image resizeMode="stretch" />,
310300
);
311301
});
312302

‎packages/react-native/ReactCommon/react/renderer/components/image/ImageProps.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ImageProps::ImageProps(
4242
rawProps,
4343
"resizeMode",
4444
sourceProps.resizeMode,
45-
ImageResizeMode::Stretch)),
45+
ImageResizeMode::Cover)),
4646
blurRadius(convertRawProp(
4747
context,
4848
rawProps,

‎packages/react-native/ReactCommon/react/renderer/components/image/ImageProps.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ImageProps final : public ViewProps {
3333
ImageSources sources{};
3434
ImageSource defaultSource{};
3535
ImageSource loadingIndicatorSource{};
36-
ImageResizeMode resizeMode{ImageResizeMode::Stretch};
36+
ImageResizeMode resizeMode{ImageResizeMode::Cover};
3737
Float blurRadius{};
3838
EdgeInsets capInsets{};
3939
std::optional<SharedColor> tintColor{};

0 commit comments

Comments
 (0)