From 1cd1d5fe48d2f304c5b1b4597c7a9930c76183ff Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Mon, 28 Oct 2019 17:42:06 -0700 Subject: [PATCH 1/2] Fix crash in RS5 due to missing facade property --- .../ReactUWP/Modules/Animated/PropsAnimatedNode.cpp | 6 ++++++ vnext/ReactUWP/Views/ExpressionAnimationStore.cpp | 12 +++++++++++- vnext/ReactUWP/Views/ReactControl.cpp | 1 + vnext/ReactUWP/Views/ReactControl.h | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/vnext/ReactUWP/Modules/Animated/PropsAnimatedNode.cpp b/vnext/ReactUWP/Modules/Animated/PropsAnimatedNode.cpp index 07386233a2a..dfca8242c14 100644 --- a/vnext/ReactUWP/Modules/Animated/PropsAnimatedNode.cpp +++ b/vnext/ReactUWP/Modules/Animated/PropsAnimatedNode.cpp @@ -3,6 +3,7 @@ #include "pch.h" +#include #include #include #include "NativeAnimatedNodeManager.h" @@ -121,6 +122,11 @@ void PropsAnimatedNode::StartAnimations() { if (!m_centerPointAnimation) { m_centerPointAnimation = winrt::Window::Current().Compositor().CreateExpressionAnimation(); m_centerPointAnimation.Target(L"CenterPoint"); + + if (g_HasActualSizeProperty == TriBit::Undefined) { + // ActualSize works on 19H1+ only + g_HasActualSizeProperty = (uiElement.try_as()) ? TriBit::Set : TriBit::NotSet; + } m_centerPointAnimation.SetReferenceParameter( L"centerPointPropertySet", GetShadowNodeBase()->EnsureTransformPS()); m_centerPointAnimation.Expression(L"centerPointPropertySet.center"); diff --git a/vnext/ReactUWP/Views/ExpressionAnimationStore.cpp b/vnext/ReactUWP/Views/ExpressionAnimationStore.cpp index a1e5209176f..b3aa71575db 100644 --- a/vnext/ReactUWP/Views/ExpressionAnimationStore.cpp +++ b/vnext/ReactUWP/Views/ExpressionAnimationStore.cpp @@ -4,6 +4,7 @@ #include "pch.h" #include "ExpressionAnimationStore.h" +#include "ReactControl.h" namespace winrt { using namespace Windows::UI::Xaml; @@ -37,8 +38,17 @@ winrt::ExpressionAnimation ExpressionAnimationStore::GetElementCenterPointExpres return m_elementCenterPointExpression; */ + // In React Native, animations use the element's center as the center or rotation/scale + // However XAML uses CenterPoint which is usually not set and therefore remains at 0,0,0 + // This means Rotate animations would rotate around the top left corner instead of around the center of the element + // In order to fix that we need a transform (see GetTransformCenteringExpression) + // The way we obtain the center of an element is by using the ActualSize façade. However this was only added in 19h1 + // An expression animation that refers to a non-existent property (e.g. in RS5) will crash, so use the CenterPoint as + // a fallback. This might be wrong but at least we won't crash. return winrt::Window::Current().Compositor().CreateExpressionAnimation( - L"vector3(0.5 * uielement.ActualSize.x, 0.5 * uielement.ActualSize.y, 0)"); + g_HasActualSizeProperty == TriBit::Set + ? L"vector3(0.5 * uielement.ActualSize.x, 0.5 * uielement.ActualSize.y, 0)" + : L"vector3(uielement.CenterPoint.X, uielement.CenterPoint.Y, uielement.CenterPoint.Z)"); } // Expression for applying a TransformMatrix about the centerpoint of a diff --git a/vnext/ReactUWP/Views/ReactControl.cpp b/vnext/ReactUWP/Views/ReactControl.cpp index 74ef6ce672d..dba585530d4 100644 --- a/vnext/ReactUWP/Views/ReactControl.cpp +++ b/vnext/ReactUWP/Views/ReactControl.cpp @@ -473,5 +473,6 @@ void ReactControl::ToggleInspector() { } } +TriBit g_HasActualSizeProperty{TriBit::Undefined}; } // namespace uwp } // namespace react diff --git a/vnext/ReactUWP/Views/ReactControl.h b/vnext/ReactUWP/Views/ReactControl.h index e6bd45f17e9..bd050e1d333 100644 --- a/vnext/ReactUWP/Views/ReactControl.h +++ b/vnext/ReactUWP/Views/ReactControl.h @@ -25,6 +25,9 @@ using namespace Windows::UI::Xaml::Media; namespace react { namespace uwp { +enum class TriBit { Undefined = -1, NotSet = 0, Set = 1 }; +extern TriBit g_HasActualSizeProperty; + class ReactControl : public std::enable_shared_from_this, public IXamlReactControl { public: ReactControl(IXamlRootView *parent, XamlView rootView); From 5ea40a4bd68b3304cdc45799feb19ba1db7d5942 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Tue, 29 Oct 2019 13:55:40 -0700 Subject: [PATCH 2/2] Change files --- ...ct-native-windows-2019-10-29-13-55-40-noRS5crash.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 change/react-native-windows-2019-10-29-13-55-40-noRS5crash.json diff --git a/change/react-native-windows-2019-10-29-13-55-40-noRS5crash.json b/change/react-native-windows-2019-10-29-13-55-40-noRS5crash.json new file mode 100644 index 00000000000..6e60e9b9027 --- /dev/null +++ b/change/react-native-windows-2019-10-29-13-55-40-noRS5crash.json @@ -0,0 +1,9 @@ +{ + "type": "prerelease", + "comment": "Fix crash in RS5 due to missing facade property", + "packageName": "react-native-windows", + "email": "asklar@winse.microsoft.com", + "commit": "1cd1d5fe48d2f304c5b1b4597c7a9930c76183ff", + "date": "2019-10-29T20:55:40.104Z", + "file": "F:\\rnw\\change\\react-native-windows-2019-10-29-13-55-40-noRS5crash.json" +} \ No newline at end of file