Skip to content

Commit 9685da5

Browse files
authored
[Fabric] Implement Image body in Image Source RequestImage API (#14568)
* Implement body in Image Source * Change files * Add test in playground
1 parent f5f01eb commit 9685da5

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Implement body in Image Source",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/playground/Samples/image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export default class Bootstrap extends React.Component<
260260
: {tintColor: this.state.tintColor},
261261
]}
262262
defaultSource={{uri: this.state.defaultImageUri}}
263-
source={{uri: this.state.imageUri}}
263+
source={{uri: this.state.imageUri, body: 'test'}}
264264
loadingIndicatorSource={{uri: loadingImageUri}}
265265
resizeMode={this.state.selectedResizeMode}
266266
blurRadius={this.state.blurRadius}

vnext/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ WindowsImageManager::GetImageRandomAccessStreamAsync(
125125
}
126126
}
127127

128+
if (!source.body.empty()) {
129+
auto bodyContent = winrt::Windows::Web::Http::HttpStringContent(
130+
winrt::to_hstring(source.body), winrt::Windows::Storage::Streams::UnicodeEncoding::Utf8, L"application/json");
131+
request.Content(bodyContent);
132+
}
133+
128134
winrt::Windows::Web::Http::HttpResponseMessage response(co_await m_httpClient.SendRequestAsync(request));
129135

130136
if (!response.IsSuccessStatusCode()) {
@@ -182,6 +188,7 @@ facebook::react::ImageRequest WindowsImageManager::requestImage(
182188
source.height = imageSource.size.height;
183189
source.width = imageSource.size.width;
184190
source.sourceType = ImageSourceType::Download;
191+
source.body = imageSource.body;
185192

186193
auto progressCallback = [weakObserverCoordinator](int64_t loaded, int64_t total) {
187194
if (auto observerCoordinator = weakObserverCoordinator.lock()) {

vnext/Microsoft.ReactNative/Utils/ImageUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct ReactImageSource {
1515
std::string uri;
1616
std::string method;
1717
std::vector<std::pair<std::string, std::string>> headers;
18+
std::string body;
1819
double width = 0;
1920
double height = 0;
2021
double scale = 1.0;

0 commit comments

Comments
 (0)