Skip to content

Commit 9f6f6fd

Browse files
authored
Adds support to compile react-native-svg against WinAppSDK (#2255)
# Summary Adds namespace redirects required to compile react-native-svg sources against WinAppSDK for react-native-windows. ## Test Plan There aren't a lot of examples for building react-native-windows apps in open source targeting WinAppSDK, but we have some proprietary builds, and this source code is working there (it is also still compatible with UWP).
1 parent 4b51a41 commit 9f6f6fd

14 files changed

+60
-53
lines changed

windows/RNSVG/D2DHelpers.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,21 @@ struct D2DHelpers {
7878
}
7979
}
8080

81-
static D2D1::ColorF AsD2DColor(ui::Color const &color) {
81+
static D2D1::ColorF AsD2DColor(Windows::UI::Color const &color) {
8282
return {
8383
color.R / 255.0f,
8484
color.G / 255.0f,
8585
color.B / 255.0f,
8686
color.A / 255.0f};
8787
}
8888

89-
static ui::Color FromD2DColor(D2D1::ColorF const color) {
90-
return ui::ColorHelper::FromArgb(
89+
static Windows::UI::Color FromD2DColor(D2D1::ColorF const color) {
90+
return Windows::UI::Color{
9191
static_cast<uint8_t>(color.a),
9292
static_cast<uint8_t>(color.r),
9393
static_cast<uint8_t>(color.g),
94-
static_cast<uint8_t>(color.b));
94+
static_cast<uint8_t>(color.b),
95+
};
9596
}
9697

9798
static D2D1_RECT_F AsD2DRect(Rect const &rect) {

windows/RNSVG/GroupViewManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace Microsoft::ReactNative;
1313

1414
using namespace Windows::Foundation;
1515
using namespace Windows::Foundation::Collections;
16-
using namespace Windows::UI::Xaml;
16+
using namespace xaml;
1717

1818
namespace winrt::RNSVG::implementation {
1919
GroupViewManager::GroupViewManager() {

windows/RNSVG/GroupViewManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ struct GroupViewManager : GroupViewManagerT<GroupViewManager, RNSVG::implementat
1313

1414
// IViewManagerWithChildren
1515
void
16-
AddView(Windows::UI::Xaml::FrameworkElement const &parent, Windows::UI::Xaml::UIElement const &child, int64_t index);
17-
void RemoveAllChildren(Windows::UI::Xaml::FrameworkElement const &parent);
18-
void RemoveChildAt(Windows::UI::Xaml::FrameworkElement const &parent, int64_t index);
16+
AddView(xaml::FrameworkElement const &parent, xaml::UIElement const &child, int64_t index);
17+
void RemoveAllChildren(xaml::FrameworkElement const &parent);
18+
void RemoveChildAt(xaml::FrameworkElement const &parent, int64_t index);
1919
void ReplaceChild(
20-
Windows::UI::Xaml::FrameworkElement const &parent,
21-
Windows::UI::Xaml::UIElement const &oldChild,
22-
Windows::UI::Xaml::UIElement const &newChild);
20+
xaml::FrameworkElement const &parent,
21+
xaml::UIElement const &oldChild,
22+
xaml::UIElement const &newChild);
2323
};
2424
} // namespace winrt::RNSVG::implementation
2525

windows/RNSVG/RenderableView.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ RNSVG::IRenderable RenderableView::HitTest(Point const &point) {
385385
return nullptr;
386386
}
387387

388-
void RenderableView::SetColor(const JSValueObject &propValue, ui::Color const &fallbackColor, std::string propName) {
388+
void RenderableView::SetColor(const JSValueObject &propValue, Windows::UI::Color const &fallbackColor, std::string propName) {
389389
switch (propValue["type"].AsInt64()) {
390390
// https://github.com/software-mansion/react-native-svg/blob/main/src/lib/extract/extractBrush.ts#L29
391391
case 1: {

windows/RNSVG/RenderableView.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ struct RenderableView : RenderableViewT<RenderableView> {
1313

1414
RNSVG::SvgView SvgRoot();
1515

16-
Windows::UI::Xaml::FrameworkElement SvgParent() { return m_parent; }
17-
void SvgParent(Windows::UI::Xaml::FrameworkElement const &value) { m_parent = value; }
16+
xaml::FrameworkElement SvgParent() { return m_parent; }
17+
void SvgParent(xaml::FrameworkElement const &value) { m_parent = value; }
1818

1919
RNSVG::D2DGeometry Geometry() { return m_geometry; }
2020
void Geometry(RNSVG::D2DGeometry const &value) { m_geometry = value; }
@@ -71,7 +71,7 @@ struct RenderableView : RenderableViewT<RenderableView> {
7171

7272
private:
7373
Microsoft::ReactNative::IReactContext m_reactContext{nullptr};
74-
Windows::UI::Xaml::FrameworkElement m_parent{nullptr};
74+
xaml::FrameworkElement m_parent{nullptr};
7575
RNSVG::D2DGeometry m_geometry{nullptr};
7676
bool m_recreateResources{true};
7777
bool m_isResponsible{false};
@@ -80,8 +80,8 @@ struct RenderableView : RenderableViewT<RenderableView> {
8080
hstring m_id{L""};
8181
hstring m_clipPathId{L""};
8282
Numerics::float3x2 m_transformMatrix{Numerics::make_float3x2_rotation(0)};
83-
Windows::UI::Color m_fill{Windows::UI::Colors::Black()};
84-
Windows::UI::Color m_stroke{Windows::UI::Colors::Transparent()};
83+
Windows::UI::Color m_fill{Colors::Black()};
84+
Windows::UI::Color m_stroke{Colors::Transparent()};
8585
hstring m_fillBrushId{L""};
8686
hstring m_strokeBrushId{L""};
8787
float m_fillOpacity{1.0f};

windows/RNSVG/RenderableViewManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace winrt;
88
using namespace Microsoft::ReactNative;
99

1010
namespace winrt::RNSVG::implementation {
11-
Windows::UI::Xaml::FrameworkElement RenderableViewManager::CreateView() {
11+
xaml::FrameworkElement RenderableViewManager::CreateView() {
1212
switch (m_class) {
1313
case RNSVG::SVGClass::RNSVGGroup:
1414
return winrt::RNSVG::GroupView(m_reactContext);
@@ -75,7 +75,7 @@ IMapView<hstring, ViewManagerPropertyType> RenderableViewManager::NativeProps()
7575
}
7676

7777
void RenderableViewManager::UpdateProperties(
78-
Windows::UI::Xaml::FrameworkElement const &view,
78+
xaml::FrameworkElement const &view,
7979
Microsoft::ReactNative::IJSValueReader const &propertyMapReader) {
8080
if (auto const &renderable{view.try_as<RenderableView>()}) {
8181
renderable->UpdateProperties(propertyMapReader);

windows/RNSVG/RenderableViewManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ struct RenderableViewManager : RenderableViewManagerT<RenderableViewManager> {
1010

1111
// IViewManager
1212
hstring Name() { return m_name; }
13-
Windows::UI::Xaml::FrameworkElement CreateView();
13+
xaml::FrameworkElement CreateView();
1414

1515
// IViewManagerWithReactContext
1616
Microsoft::ReactNative::IReactContext ReactContext() { return m_reactContext; }
1717
void ReactContext(Microsoft::ReactNative::IReactContext const &value) { m_reactContext = value; }
1818

1919
// IViewManagerWithNativeProperties
2020
void UpdateProperties(
21-
Windows::UI::Xaml::FrameworkElement const &view,
21+
xaml::FrameworkElement const &view,
2222
Microsoft::ReactNative::IJSValueReader const &propertyMapReader);
2323
virtual
2424
Windows::Foundation::Collections::IMapView<hstring, Microsoft::ReactNative::ViewManagerPropertyType> NativeProps();

windows/RNSVG/SvgView.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
#include "SvgView.g.cpp"
66
#endif
77

8+
#include <UI.Xaml.Media.Imaging.h>
9+
#ifdef USE_WINUI3
10+
#include <microsoft.ui.xaml.media.dxinterop.h>
11+
#include <winrt/Microsoft.Graphics.Display.h>
12+
#else
813
#include <windows.ui.xaml.media.dxinterop.h>
9-
#include <winrt/Windows.UI.Xaml.Media.Imaging.h>
1014
#include <winrt/Windows.Graphics.Display.h>
15+
#endif
1116

1217
#include "D2DDevice.h"
1318
#include "D2DDeviceContext.h"

windows/RNSVG/SvgView.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct SvgView : SvgViewT<SvgView> {
99

1010
SvgView(Microsoft::ReactNative::IReactContext const &context);
1111

12-
Windows::UI::Xaml::FrameworkElement SvgParent() { return m_parent; }
13-
void SvgParent(Windows::UI::Xaml::FrameworkElement const &value);
12+
xaml::FrameworkElement SvgParent() { return m_parent; }
13+
void SvgParent(xaml::FrameworkElement const &value);
1414

1515
RNSVG::GroupView Group() { return m_group; }
1616
void Group(RNSVG::GroupView const &value) { m_group = value; }
@@ -48,8 +48,8 @@ struct SvgView : SvgViewT<SvgView> {
4848
Windows::Foundation::Size MeasureOverride(Windows::Foundation::Size const &availableSize);
4949
Windows::Foundation::Size ArrangeOverride(Windows::Foundation::Size const &finalSize);
5050

51-
void Panel_Loaded(Windows::Foundation::IInspectable const &sender, Windows::UI::Xaml::RoutedEventArgs const &args);
52-
void Panel_Unloaded(Windows::Foundation::IInspectable const &sender, Windows::UI::Xaml::RoutedEventArgs const &args);
51+
void Panel_Loaded(Windows::Foundation::IInspectable const &sender, xaml::RoutedEventArgs const &args);
52+
void Panel_Unloaded(Windows::Foundation::IInspectable const &sender, xaml::RoutedEventArgs const &args);
5353

5454
void Invalidate();
5555

@@ -58,10 +58,10 @@ struct SvgView : SvgViewT<SvgView> {
5858
bool m_hasRendered{false};
5959
bool m_isResponsible{false};
6060
Microsoft::ReactNative::IReactContext m_reactContext{nullptr};
61-
Windows::UI::Xaml::FrameworkElement m_parent{nullptr};
61+
xaml::FrameworkElement m_parent{nullptr};
6262
RNSVG::D2DDevice m_device;
6363
RNSVG::D2DDeviceContext m_deviceContext;
64-
Windows::UI::Xaml::Controls::Image m_image;
64+
xaml::Controls::Image m_image;
6565
RNSVG::GroupView m_group{nullptr};
6666
hstring m_id{L""};
6767
float m_minX{0.0f};
@@ -74,14 +74,14 @@ struct SvgView : SvgViewT<SvgView> {
7474
RNSVG::SVGLength m_height{};
7575
std::string m_align{""};
7676
RNSVG::MeetOrSlice m_meetOrSlice{RNSVG::MeetOrSlice::Meet};
77-
Windows::UI::Color m_currentColor{Windows::UI::Colors::Black()};
77+
Windows::UI::Color m_currentColor{Colors::Black()};
7878

7979
Windows::Foundation::Collections::IMap<hstring, RNSVG::IRenderable> m_templates{
8080
winrt::single_threaded_map<hstring, RNSVG::IRenderable>()};
8181
Windows::Foundation::Collections::IMap<hstring, RNSVG::BrushView> m_brushes{
8282
winrt::single_threaded_map<hstring, RNSVG::BrushView>()};
83-
Windows::UI::Xaml::FrameworkElement::Loaded_revoker m_panelLoadedRevoker{};
84-
Windows::UI::Xaml::FrameworkElement::Unloaded_revoker m_panelUnloadedRevoker{};
83+
xaml::FrameworkElement::Loaded_revoker m_panelLoadedRevoker{};
84+
xaml::FrameworkElement::Unloaded_revoker m_panelUnloadedRevoker{};
8585
};
8686
} // namespace winrt::RNSVG::implementation
8787

windows/RNSVG/SvgViewManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include "SvgViewManager.g.cpp"
55
#endif
66

7-
#include <winrt/Windows.UI.Input.h>
8-
#include <winrt/Windows.UI.Xaml.Input.h>
9-
#include <winrt/Windows.UI.Xaml.Media.h>
10-
#include <winrt/Windows.UI.Xaml.Shapes.h>
7+
#include <UI.Input.h>
8+
#include <UI.Xaml.Input.h>
9+
#include <UI.Xaml.Media.h>
10+
#include <UI.Xaml.Shapes.h>
1111

1212
#include "RenderableView.h"
1313
#include "SvgView.h"
@@ -16,8 +16,8 @@ namespace winrt {
1616
using namespace Windows::Foundation;
1717
using namespace Windows::Foundation::Collections;
1818
using namespace Microsoft::ReactNative;
19-
using namespace Windows::UI::Xaml;
20-
using namespace Windows::UI::Xaml::Controls;
19+
using namespace xaml;
20+
using namespace xaml::Controls;
2121
} // namespace winrt
2222

2323
namespace winrt::RNSVG::implementation {

0 commit comments

Comments
 (0)