-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fabric] Support blob: images, and provide better image.onError callbacks #13285
Changes from 4 commits
a436510
64a5ffb
fc43dd3
7ebd491
f530a37
263a5ce
0783bbc
3b933c7
e20d475
b8e200c
c4da04c
dd0c6f9
24038c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "[Fabric] Support blob: images, and provide better image.onError callbacks", | ||
"packageName": "react-native-windows", | ||
"email": "30809111+acoates-ms@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,43 +52,41 @@ void RegisterCustomComponent(winrt::Microsoft::ReactNative::IReactPackageBuilder | |
* | ||
* This allows applications to provide custom image rendering pipelines. | ||
*/ | ||
struct EllipseImageHandler : winrt::implements< | ||
EllipseImageHandler, | ||
winrt::Microsoft::ReactNative::Composition::Experimental::IUriBrushProvider, | ||
winrt::Microsoft::ReactNative::Composition::IUriImageProvider> { | ||
struct EllipseImageHandler | ||
: winrt::implements<EllipseImageHandler, winrt::Microsoft::ReactNative::Composition::IUriImageProvider> { | ||
bool CanLoadImageUri(winrt::Microsoft::ReactNative::IReactContext context, winrt::Windows::Foundation::Uri uri) { | ||
return uri.SchemeName() == L"ellipse"; | ||
} | ||
|
||
winrt::Windows::Foundation::IAsyncOperation<winrt::Microsoft::ReactNative::Composition::Experimental::UriBrushFactory> | ||
GetSourceAsync( | ||
winrt::Windows::Foundation::IAsyncOperation<winrt::Microsoft::ReactNative::Composition::ImageResponse> | ||
GetImageResponseAsync( | ||
const winrt::Microsoft::ReactNative::IReactContext &context, | ||
const winrt::Microsoft::ReactNative::Composition::ImageSource &imageSource) { | ||
co_return [uri = imageSource.Uri(), size = imageSource.Size(), scale = imageSource.Scale(), context]( | ||
const winrt::Microsoft::ReactNative::IReactContext &reactContext, | ||
const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext | ||
&compositionContext) -> winrt::Microsoft::ReactNative::Composition::Experimental::IBrush { | ||
auto compositor = | ||
winrt::Microsoft::ReactNative::Composition::Experimental::MicrosoftCompositionContextHelper::InnerCompositor( | ||
compositionContext); | ||
auto drawingBrush = compositionContext.CreateDrawingSurfaceBrush( | ||
size, | ||
winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized, | ||
winrt::Windows::Graphics::DirectX::DirectXAlphaMode::Premultiplied); | ||
POINT pt; | ||
Microsoft::ReactNative::Composition::AutoDrawDrawingSurface autoDraw(drawingBrush, scale, &pt); | ||
auto renderTarget = autoDraw.GetRenderTarget(); | ||
|
||
winrt::com_ptr<ID2D1SolidColorBrush> brush; | ||
renderTarget->CreateSolidColorBrush({1.0f, 0.0f, 0.0f, 1.0f}, brush.put()); | ||
renderTarget->DrawEllipse( | ||
{{(pt.x + size.Width / 2) / scale, (pt.y + size.Height / 2) / scale}, | ||
(size.Width / 2) / scale, | ||
(size.Height / 2) / scale}, | ||
brush.get()); | ||
|
||
return drawingBrush; | ||
}; | ||
co_return winrt::Microsoft::ReactNative::Composition::Experimental::UriBrushFactoryImageResponse( | ||
[uri = imageSource.Uri(), size = imageSource.Size(), scale = imageSource.Scale(), context]( | ||
const winrt::Microsoft::ReactNative::IReactContext &reactContext, | ||
const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compositionContext) | ||
-> winrt::Microsoft::ReactNative::Composition::Experimental::IBrush { | ||
auto compositor = winrt::Microsoft::ReactNative::Composition::Experimental:: | ||
MicrosoftCompositionContextHelper::InnerCompositor(compositionContext); | ||
auto drawingBrush = compositionContext.CreateDrawingSurfaceBrush( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: {} - brace initialization to avoid any type conversion happening and ensuring uniform initialization? https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es23-prefer-the--initializer-syntax |
||
size, | ||
winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized, | ||
winrt::Windows::Graphics::DirectX::DirectXAlphaMode::Premultiplied); | ||
POINT pt; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. POINT pt{}? |
||
Microsoft::ReactNative::Composition::AutoDrawDrawingSurface autoDraw(drawingBrush, scale, &pt); | ||
auto renderTarget = autoDraw.GetRenderTarget(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: uniform initialization? |
||
|
||
winrt::com_ptr<ID2D1SolidColorBrush> brush; | ||
renderTarget->CreateSolidColorBrush({1.0f, 0.0f, 0.0f, 1.0f}, brush.put()); | ||
renderTarget->DrawEllipse( | ||
{{(pt.x + size.Width / 2) / scale, (pt.y + size.Height / 2) / scale}, | ||
(size.Width / 2) / scale, | ||
(size.Height / 2) / scale}, | ||
brush.get()); | ||
|
||
return drawingBrush; | ||
}); | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uniform initialization?