-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.74] [Fabric] Add ability to provide custom image uri handlers (#13186
) * [Fabric] Add ability to provide custom image uri handlers (#13180) * Add ability to provide custom image uri handlers * Change files * format * fix * fix * fix change file
- Loading branch information
1 parent
64ae33c
commit b422f06
Showing
15 changed files
with
464 additions
and
53 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/react-native-windows-e43ac1c2-0b09-49f0-9509-e8af020af965.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Add ability to provide custom image uri handlers", | ||
"packageName": "react-native-windows", | ||
"email": "30809111+acoates-ms@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
vnext/Microsoft.ReactNative/Fabric/Composition/ImageResponseImage.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <wincodec.h> | ||
#include <winrt/Microsoft.ReactNative.Composition.Experimental.h> | ||
|
||
namespace winrt::Microsoft::ReactNative::Composition::implementation { | ||
|
||
struct ImageResponseImage { | ||
winrt::com_ptr<IWICBitmap> m_wicbmp; | ||
winrt::Microsoft::ReactNative::Composition::Experimental::UriBrushFactory m_brushFactory{nullptr}; | ||
}; | ||
|
||
} // namespace winrt::Microsoft::ReactNative::Composition::implementation |
82 changes: 82 additions & 0 deletions
82
vnext/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "pch.h" | ||
#include "UriImageManager.h" | ||
|
||
#include "Composition.ImageSource.g.h" | ||
#include "Composition.UriImageManager.g.cpp" | ||
#include <ReactPropertyBag.h> | ||
|
||
namespace winrt::Microsoft::ReactNative::Composition::implementation { | ||
|
||
struct ImageSource : ImageSourceT<ImageSource> { | ||
ImageSource(const facebook::react::ImageSource &source) | ||
: m_size({source.size.width, source.size.height}), | ||
m_scale(source.scale), | ||
m_uri(::Microsoft::ReactNative::UriTryCreate(winrt::to_hstring(source.uri))) {} | ||
|
||
winrt::Windows::Foundation::Uri Uri() noexcept { | ||
return m_uri; | ||
} | ||
|
||
winrt::Windows::Foundation::Size Size() noexcept { | ||
return m_size; | ||
} | ||
|
||
float Scale() noexcept { | ||
return m_scale; | ||
} | ||
|
||
private: | ||
const winrt::Windows::Foundation::Uri m_uri; | ||
const winrt::Windows::Foundation::Size m_size; | ||
const float m_scale; | ||
}; | ||
|
||
winrt::Microsoft::ReactNative::Composition::ImageSource MakeImageSource( | ||
const facebook::react::ImageSource &source) noexcept { | ||
return winrt::make<ImageSource>(source); | ||
} | ||
|
||
static const ReactPropertyId<ReactNonAbiValue<winrt::com_ptr<UriImageManager>>> &UriImageManagerPropertyId() noexcept { | ||
static const ReactPropertyId<ReactNonAbiValue<winrt::com_ptr<UriImageManager>>> prop{ | ||
L"ReactNative", L"UriImageManager"}; | ||
return prop; | ||
} | ||
|
||
winrt::com_ptr<UriImageManager> UriImageManager::GetOrCreate( | ||
const winrt::Microsoft::ReactNative::ReactPropertyBag &properties) noexcept { | ||
auto uriImageManager = | ||
winrt::Microsoft::ReactNative::ReactPropertyBag(properties).GetOrCreate(UriImageManagerPropertyId(), []() { | ||
return winrt::make_self<UriImageManager>(); | ||
}); | ||
return uriImageManager.Value(); | ||
} | ||
|
||
void UriImageManager::AddUriImageProvider( | ||
const winrt::Microsoft::ReactNative::IReactPropertyBag &properties, | ||
const IUriImageProvider &provider) { | ||
if (!provider) | ||
winrt::throw_hresult(E_INVALIDARG); | ||
GetOrCreate(winrt::Microsoft::ReactNative::ReactPropertyBag(properties))->m_providers.push_back(provider); | ||
} | ||
|
||
IUriImageProvider UriImageManager::TryGetUriImageProvider( | ||
const IReactContext &context, | ||
winrt::Microsoft::ReactNative::Composition::ImageSource &source) noexcept { | ||
auto uri = source.Uri(); | ||
if (!uri) { | ||
return nullptr; | ||
} | ||
|
||
for (auto &provider : m_providers) { | ||
if (provider.CanLoadImageUri(context, source.Uri())) { | ||
return provider; | ||
} | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
} // namespace winrt::Microsoft::ReactNative::Composition::implementation |
39 changes: 39 additions & 0 deletions
39
vnext/Microsoft.ReactNative/Fabric/Composition/UriImageManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include "Composition.UriImageManager.g.h" | ||
|
||
#include <ReactPropertyBag.h> | ||
#include <Utils/ImageUtils.h> | ||
#include <react/renderer/imagemanager/primitives.h> | ||
#include <winrt/Microsoft.ReactNative.Composition.h> | ||
|
||
namespace winrt::Microsoft::ReactNative::Composition::implementation { | ||
|
||
struct UriImageManager : UriImageManagerT<UriImageManager> { | ||
UriImageManager() = default; | ||
|
||
static void AddUriImageProvider( | ||
const winrt::Microsoft::ReactNative::IReactPropertyBag &properties, | ||
const IUriImageProvider &provider); | ||
|
||
static winrt::com_ptr<UriImageManager> GetOrCreate( | ||
const winrt::Microsoft::ReactNative::ReactPropertyBag &properties) noexcept; | ||
|
||
IUriImageProvider TryGetUriImageProvider( | ||
const IReactContext &context, | ||
winrt::Microsoft::ReactNative::Composition::ImageSource &source) noexcept; | ||
|
||
private: | ||
std::vector<IUriImageProvider> m_providers; | ||
}; | ||
|
||
winrt::Microsoft::ReactNative::Composition::ImageSource MakeImageSource( | ||
const facebook::react::ImageSource &source) noexcept; | ||
|
||
} // namespace winrt::Microsoft::ReactNative::Composition::implementation | ||
|
||
namespace winrt::Microsoft::ReactNative::Composition::factory_implementation { | ||
struct UriImageManager : UriImageManagerT<UriImageManager, implementation::UriImageManager> {}; | ||
} // namespace winrt::Microsoft::ReactNative::Composition::factory_implementation |
Oops, something went wrong.