feat(windows): add fabric support (#2321)

# Summary
This PR adds Fabric support and a FabricExample app for Windows.

Windows support for Fabric is experimental and as such APIs are subject
to change/break.

## Test Plan


https://github.com/software-mansion/react-native-svg/assets/1422161/2a7db119-44a8-4ee1-a837-41ca8320d8fa

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |         |
| Android |         |
| Windows |         |

## Checklist
- [x] I have tested this on a device and a simulator
- [ ] I added documentation in `README.md`
- [ ] I updated the typed files (typescript)
- [ ] I added a test for the API in the `__tests__` folder
This commit is contained in:
Marlene Cota
2024-08-18 23:18:45 -07:00
committed by GitHub
parent e87d22f49e
commit b80f102b09
124 changed files with 14920 additions and 1127 deletions

View File

@@ -14,6 +14,50 @@ using namespace winrt;
using namespace Microsoft::ReactNative;
namespace winrt::RNSVG::implementation {
#ifdef USE_FABRIC
PathProps::PathProps(const winrt::Microsoft::ReactNative::ViewProps &props) : base_type(props) {}
void PathProps::SetProp(
uint32_t hash,
winrt::hstring propName,
winrt::Microsoft::ReactNative::IJSValueReader value) noexcept {
winrt::Microsoft::ReactNative::ReadProp(hash, propName, value, *this);
}
PathView::PathView(const winrt::Microsoft::ReactNative::CreateComponentViewArgs &args) : base_type(args) {}
void PathView::RegisterComponent(const winrt::Microsoft::ReactNative::IReactPackageBuilderFabric &builder) noexcept {
builder.AddViewComponent(
L"RNSVGPath", [](winrt::Microsoft::ReactNative::IReactViewComponentBuilder const &builder) noexcept {
builder.SetCreateProps([](winrt::Microsoft::ReactNative::ViewProps props) noexcept {
return winrt::make<winrt::RNSVG::implementation::PathProps>(props);
});
builder.SetCreateComponentView([](const winrt::Microsoft::ReactNative::CreateComponentViewArgs &args) noexcept {
return winrt::make<winrt::RNSVG::implementation::PathView>(args);
});
});
}
void PathView::UpdateProperties(
const winrt::Microsoft::ReactNative::IComponentProps &props,
const winrt::Microsoft::ReactNative::IComponentProps &oldProps,
bool forceUpdate,
bool invalidate) noexcept {
auto pathProps = props.try_as<PathProps>();
if (pathProps) {
m_props = pathProps;
m_d = m_props->d;
m_commands.clear();
m_segmentData.clear();
ParsePath();
}
base_type::UpdateProperties(props, oldProps, forceUpdate, invalidate);
}
#else
void PathView::UpdateProperties(IJSValueReader const &reader, bool forceUpdate, bool invalidate) {
const JSValueObject &propertyMap{JSValue::ReadObjectFrom(reader)};
@@ -37,16 +81,18 @@ void PathView::UpdateProperties(IJSValueReader const &reader, bool forceUpdate,
__super::UpdateProperties(reader, forceUpdate, invalidate);
}
#endif
void PathView::CreateGeometry() {
void PathView::CreateGeometry(RNSVG::D2DDeviceContext const &context) {
auto const &root{SvgRoot()};
com_ptr<ID2D1SvgDocument> doc;
com_ptr<ID2D1DeviceContext5> deviceContext{get_self<D2DDeviceContext>(root.DeviceContext())->Get().as<ID2D1DeviceContext5>()};
com_ptr<ID2D1DeviceContext5> deviceContext{get_self<D2DDeviceContext>(context)->Get().as<ID2D1DeviceContext5>()};
auto size{root.CanvasSize()};
check_hresult(deviceContext->CreateSvgDocument(
nullptr,
D2D1::SizeF(static_cast<float>(root.ActualWidth()), static_cast<float>(root.ActualHeight())),
D2D1::SizeF(size.Width, size.Height),
doc.put()));
m_segmentData.resize(m_segmentData.size());