Skip to content

Commit

Permalink
Fix loading images from file:// URIs (#12757)
Browse files Browse the repository at this point in the history
## Description

Fixes the loading of images via `file://` URIs, which is what is used for asset files in (unpackaged) Fabric apps.

### Type of Change

- Bug fix (non-breaking change which fixes an issue)

### Why
To fix image loading.

Resolves #12755

### What
The API we use to load the image can support `file://` URI's directly, we were doing a bunch of (now no longer necessary?) path processing that ultimately wasn't working. This change removes that processing.

## Screenshots
Before: 

![image](https://github.com/microsoft/react-native-windows/assets/10852185/dd634958-e2a0-4edf-9a60-5c5c74c1d2e6)


After:
![image](https://github.com/microsoft/react-native-windows/assets/10852185/5a51785b-0829-4d3a-8210-5fa5257f9ad0)


## Testing
Verified images started loading.

## Changelog
Should this change be included in the release notes: _yes_

Fixed loading images from `file://` URIs (as used for assets in on-disk bundles)
  • Loading branch information
jonthysell committed Feb 22, 2024
1 parent e694482 commit b99a46f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix loading images from `file://` URIs",
"packageName": "react-native-windows",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
4 changes: 1 addition & 3 deletions vnext/Microsoft.ReactNative/Utils/ImageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ winrt::IAsyncOperation<winrt::IRandomAccessStream> GetImageStreamAsync(ReactImag
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFile> getFileSync{nullptr};

if (isFile) {
auto path = winrt::to_string(uri.Path());
std::replace(path.begin(), path.end(), '/', '\\');
getFileSync = winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(winrt::to_hstring(path));
getFileSync = winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(uri.AbsoluteCanonicalUri());
} else {
getFileSync = winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri);
}
Expand Down

0 comments on commit b99a46f

Please sign in to comment.