Skip to content

Commit

Permalink
Merge branch 'main' into @wolewicki/bump-example-to-074
Browse files Browse the repository at this point in the history
  • Loading branch information
WoLewicki committed Apr 23, 2024
2 parents 91d8be7 + 3ea8fc4 commit 655a640
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 53 deletions.
9 changes: 5 additions & 4 deletions windows/RNSVG/D2DHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ struct D2DHelpers {
}
}

static D2D1::ColorF AsD2DColor(ui::Color const &color) {
static D2D1::ColorF AsD2DColor(Windows::UI::Color const &color) {
return {
color.R / 255.0f,
color.G / 255.0f,
color.B / 255.0f,
color.A / 255.0f};
}

static ui::Color FromD2DColor(D2D1::ColorF const color) {
return ui::ColorHelper::FromArgb(
static Windows::UI::Color FromD2DColor(D2D1::ColorF const color) {
return Windows::UI::Color{
static_cast<uint8_t>(color.a),
static_cast<uint8_t>(color.r),
static_cast<uint8_t>(color.g),
static_cast<uint8_t>(color.b));
static_cast<uint8_t>(color.b),
};
}

static D2D1_RECT_F AsD2DRect(Rect const &rect) {
Expand Down
2 changes: 1 addition & 1 deletion windows/RNSVG/GroupViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace Microsoft::ReactNative;

using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace xaml;

namespace winrt::RNSVG::implementation {
GroupViewManager::GroupViewManager() {
Expand Down
12 changes: 6 additions & 6 deletions windows/RNSVG/GroupViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ struct GroupViewManager : GroupViewManagerT<GroupViewManager, RNSVG::implementat

// IViewManagerWithChildren
void
AddView(Windows::UI::Xaml::FrameworkElement const &parent, Windows::UI::Xaml::UIElement const &child, int64_t index);
void RemoveAllChildren(Windows::UI::Xaml::FrameworkElement const &parent);
void RemoveChildAt(Windows::UI::Xaml::FrameworkElement const &parent, int64_t index);
AddView(xaml::FrameworkElement const &parent, xaml::UIElement const &child, int64_t index);
void RemoveAllChildren(xaml::FrameworkElement const &parent);
void RemoveChildAt(xaml::FrameworkElement const &parent, int64_t index);
void ReplaceChild(
Windows::UI::Xaml::FrameworkElement const &parent,
Windows::UI::Xaml::UIElement const &oldChild,
Windows::UI::Xaml::UIElement const &newChild);
xaml::FrameworkElement const &parent,
xaml::UIElement const &oldChild,
xaml::UIElement const &newChild);
};
} // namespace winrt::RNSVG::implementation

Expand Down
2 changes: 1 addition & 1 deletion windows/RNSVG/RenderableView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ RNSVG::IRenderable RenderableView::HitTest(Point const &point) {
return nullptr;
}

void RenderableView::SetColor(const JSValueObject &propValue, ui::Color const &fallbackColor, std::string propName) {
void RenderableView::SetColor(const JSValueObject &propValue, Windows::UI::Color const &fallbackColor, std::string propName) {
switch (propValue["type"].AsInt64()) {
// https://github.com/software-mansion/react-native-svg/blob/main/src/lib/extract/extractBrush.ts#L29
case 1: {
Expand Down
10 changes: 5 additions & 5 deletions windows/RNSVG/RenderableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct RenderableView : RenderableViewT<RenderableView> {

RNSVG::SvgView SvgRoot();

Windows::UI::Xaml::FrameworkElement SvgParent() { return m_parent; }
void SvgParent(Windows::UI::Xaml::FrameworkElement const &value) { m_parent = value; }
xaml::FrameworkElement SvgParent() { return m_parent; }
void SvgParent(xaml::FrameworkElement const &value) { m_parent = value; }

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

private:
Microsoft::ReactNative::IReactContext m_reactContext{nullptr};
Windows::UI::Xaml::FrameworkElement m_parent{nullptr};
xaml::FrameworkElement m_parent{nullptr};
RNSVG::D2DGeometry m_geometry{nullptr};
bool m_recreateResources{true};
bool m_isResponsible{false};
Expand All @@ -80,8 +80,8 @@ struct RenderableView : RenderableViewT<RenderableView> {
hstring m_id{L""};
hstring m_clipPathId{L""};
Numerics::float3x2 m_transformMatrix{Numerics::make_float3x2_rotation(0)};
Windows::UI::Color m_fill{Windows::UI::Colors::Black()};
Windows::UI::Color m_stroke{Windows::UI::Colors::Transparent()};
Windows::UI::Color m_fill{Colors::Black()};
Windows::UI::Color m_stroke{Colors::Transparent()};
hstring m_fillBrushId{L""};
hstring m_strokeBrushId{L""};
float m_fillOpacity{1.0f};
Expand Down
4 changes: 2 additions & 2 deletions windows/RNSVG/RenderableViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace winrt;
using namespace Microsoft::ReactNative;

namespace winrt::RNSVG::implementation {
Windows::UI::Xaml::FrameworkElement RenderableViewManager::CreateView() {
xaml::FrameworkElement RenderableViewManager::CreateView() {
switch (m_class) {
case RNSVG::SVGClass::RNSVGGroup:
return winrt::RNSVG::GroupView(m_reactContext);
Expand Down Expand Up @@ -75,7 +75,7 @@ IMapView<hstring, ViewManagerPropertyType> RenderableViewManager::NativeProps()
}

void RenderableViewManager::UpdateProperties(
Windows::UI::Xaml::FrameworkElement const &view,
xaml::FrameworkElement const &view,
Microsoft::ReactNative::IJSValueReader const &propertyMapReader) {
if (auto const &renderable{view.try_as<RenderableView>()}) {
renderable->UpdateProperties(propertyMapReader);
Expand Down
4 changes: 2 additions & 2 deletions windows/RNSVG/RenderableViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ struct RenderableViewManager : RenderableViewManagerT<RenderableViewManager> {

// IViewManager
hstring Name() { return m_name; }
Windows::UI::Xaml::FrameworkElement CreateView();
xaml::FrameworkElement CreateView();

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

// IViewManagerWithNativeProperties
void UpdateProperties(
Windows::UI::Xaml::FrameworkElement const &view,
xaml::FrameworkElement const &view,
Microsoft::ReactNative::IJSValueReader const &propertyMapReader);
virtual
Windows::Foundation::Collections::IMapView<hstring, Microsoft::ReactNative::ViewManagerPropertyType> NativeProps();
Expand Down
7 changes: 6 additions & 1 deletion windows/RNSVG/SvgView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
#include "SvgView.g.cpp"
#endif

#include <UI.Xaml.Media.Imaging.h>
#ifdef USE_WINUI3
#include <microsoft.ui.xaml.media.dxinterop.h>
#include <winrt/Microsoft.Graphics.Display.h>
#else
#include <windows.ui.xaml.media.dxinterop.h>
#include <winrt/Windows.UI.Xaml.Media.Imaging.h>
#include <winrt/Windows.Graphics.Display.h>
#endif

#include "D2DDevice.h"
#include "D2DDeviceContext.h"
Expand Down
18 changes: 9 additions & 9 deletions windows/RNSVG/SvgView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct SvgView : SvgViewT<SvgView> {

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

Windows::UI::Xaml::FrameworkElement SvgParent() { return m_parent; }
void SvgParent(Windows::UI::Xaml::FrameworkElement const &value);
xaml::FrameworkElement SvgParent() { return m_parent; }
void SvgParent(xaml::FrameworkElement const &value);

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

void Panel_Loaded(Windows::Foundation::IInspectable const &sender, Windows::UI::Xaml::RoutedEventArgs const &args);
void Panel_Unloaded(Windows::Foundation::IInspectable const &sender, Windows::UI::Xaml::RoutedEventArgs const &args);
void Panel_Loaded(Windows::Foundation::IInspectable const &sender, xaml::RoutedEventArgs const &args);
void Panel_Unloaded(Windows::Foundation::IInspectable const &sender, xaml::RoutedEventArgs const &args);

void Invalidate();

Expand All @@ -58,10 +58,10 @@ struct SvgView : SvgViewT<SvgView> {
bool m_hasRendered{false};
bool m_isResponsible{false};
Microsoft::ReactNative::IReactContext m_reactContext{nullptr};
Windows::UI::Xaml::FrameworkElement m_parent{nullptr};
xaml::FrameworkElement m_parent{nullptr};
RNSVG::D2DDevice m_device;
RNSVG::D2DDeviceContext m_deviceContext;
Windows::UI::Xaml::Controls::Image m_image;
xaml::Controls::Image m_image;
RNSVG::GroupView m_group{nullptr};
hstring m_id{L""};
float m_minX{0.0f};
Expand All @@ -74,14 +74,14 @@ struct SvgView : SvgViewT<SvgView> {
RNSVG::SVGLength m_height{};
std::string m_align{""};
RNSVG::MeetOrSlice m_meetOrSlice{RNSVG::MeetOrSlice::Meet};
Windows::UI::Color m_currentColor{Windows::UI::Colors::Black()};
Windows::UI::Color m_currentColor{Colors::Black()};

Windows::Foundation::Collections::IMap<hstring, RNSVG::IRenderable> m_templates{
winrt::single_threaded_map<hstring, RNSVG::IRenderable>()};
Windows::Foundation::Collections::IMap<hstring, RNSVG::BrushView> m_brushes{
winrt::single_threaded_map<hstring, RNSVG::BrushView>()};
Windows::UI::Xaml::FrameworkElement::Loaded_revoker m_panelLoadedRevoker{};
Windows::UI::Xaml::FrameworkElement::Unloaded_revoker m_panelUnloadedRevoker{};
xaml::FrameworkElement::Loaded_revoker m_panelLoadedRevoker{};
xaml::FrameworkElement::Unloaded_revoker m_panelUnloadedRevoker{};
};
} // namespace winrt::RNSVG::implementation

Expand Down
12 changes: 6 additions & 6 deletions windows/RNSVG/SvgViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include "SvgViewManager.g.cpp"
#endif

#include <winrt/Windows.UI.Input.h>
#include <winrt/Windows.UI.Xaml.Input.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <winrt/Windows.UI.Xaml.Shapes.h>
#include <UI.Input.h>
#include <UI.Xaml.Input.h>
#include <UI.Xaml.Media.h>
#include <UI.Xaml.Shapes.h>

#include "RenderableView.h"
#include "SvgView.h"
Expand All @@ -16,8 +16,8 @@ namespace winrt {
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Microsoft::ReactNative;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace xaml;
using namespace xaml::Controls;
} // namespace winrt

namespace winrt::RNSVG::implementation {
Expand Down
16 changes: 8 additions & 8 deletions windows/RNSVG/SvgViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct SvgViewManager : SvgViewManagerT<SvgViewManager> {

// IViewManager
hstring Name();
Windows::UI::Xaml::FrameworkElement CreateView();
xaml::FrameworkElement CreateView();

// IViewManagerWithReactContext
Microsoft::ReactNative::IReactContext ReactContext();
Expand All @@ -17,18 +17,18 @@ struct SvgViewManager : SvgViewManagerT<SvgViewManager> {
// IViewManagerWithNativeProperties
Windows::Foundation::Collections::IMapView<hstring, Microsoft::ReactNative::ViewManagerPropertyType> NativeProps();
void UpdateProperties(
Windows::UI::Xaml::FrameworkElement const &view,
xaml::FrameworkElement const &view,
Microsoft::ReactNative::IJSValueReader const &propertyMapReader);

// IViewManagerWithChildren
void
AddView(Windows::UI::Xaml::FrameworkElement const &parent, Windows::UI::Xaml::UIElement const &child, int64_t index);
void RemoveAllChildren(Windows::UI::Xaml::FrameworkElement const &parent);
void RemoveChildAt(Windows::UI::Xaml::FrameworkElement const &parent, int64_t index);
AddView(xaml::FrameworkElement const &parent, xaml::UIElement const &child, int64_t index);
void RemoveAllChildren(xaml::FrameworkElement const &parent);
void RemoveChildAt(xaml::FrameworkElement const &parent, int64_t index);
void ReplaceChild(
Windows::UI::Xaml::FrameworkElement const &parent,
Windows::UI::Xaml::UIElement const &oldChild,
Windows::UI::Xaml::UIElement const &newChild);
xaml::FrameworkElement const &parent,
xaml::UIElement const &oldChild,
xaml::UIElement const &newChild);

// IViewManagerWithPointerEvents
void OnPointerEvent(
Expand Down
6 changes: 3 additions & 3 deletions windows/RNSVG/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "pch.h"

#include <winrt/Windows.Foundation.Numerics.h>
#include <winrt/Windows.UI.Text.h>
#include <UI.Text.h>
#include "JSValueReader.h"
#include "D2DHelpers.h"
#include "D2DBrush.h"
Expand Down Expand Up @@ -194,7 +194,7 @@ struct Utils {
}
}

static ui::Color JSValueAsColor(JSValue const &value, ui::Color const &defaultValue = Colors::Transparent()) {
static Windows::UI::Color JSValueAsColor(JSValue const &value, Windows::UI::Color const &defaultValue = Colors::Transparent()) {
if (value.IsNull()) {
return defaultValue;
} else if (auto const &brush{value.To<xaml::Media::Brush>()}) {
Expand Down Expand Up @@ -266,7 +266,7 @@ struct Utils {

static com_ptr<ID2D1Brush> GetCanvasBrush(
hstring const &brushId,
ui::Color const &color,
Windows::UI::Color const &color,
RNSVG::SvgView const &root,
com_ptr<ID2D1Geometry> const &geometry) {
com_ptr<ID2D1Brush> brush;
Expand Down
7 changes: 4 additions & 3 deletions windows/RNSVG/Views.idl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "Types.idl";
#include <NamespaceRedirect.h>

namespace RNSVG
{
interface IRenderable
{
Windows.UI.Xaml.FrameworkElement SvgParent;
XAML_NAMESPACE.FrameworkElement SvgParent;
D2DGeometry Geometry;
Boolean IsResponsible;

Expand All @@ -19,7 +20,7 @@ namespace RNSVG
};

[default_interface]
runtimeclass SvgView : Windows.UI.Xaml.Controls.Panel, IRenderable
runtimeclass SvgView : XAML_NAMESPACE.Controls.Panel, IRenderable
{
SvgView(Microsoft.ReactNative.IReactContext context);

Expand All @@ -34,7 +35,7 @@ namespace RNSVG
};

[default_interface]
unsealed runtimeclass RenderableView : Windows.UI.Xaml.FrameworkElement, IRenderable
unsealed runtimeclass RenderableView : XAML_NAMESPACE.FrameworkElement, IRenderable
{
RenderableView(Microsoft.ReactNative.IReactContext context);
SvgView SvgRoot{ get; };
Expand Down
4 changes: 2 additions & 2 deletions windows/RNSVG/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <windows.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <winrt/Windows.UI.Xaml.h>
#include <CppWinRTIncludes.h>
#include <UI.Xaml.Media.h>

#include <winrt/Microsoft.ReactNative.h>

0 comments on commit 655a640

Please sign in to comment.