From 4ffbcf5aeb4933f56e9e586483780a481621cc52 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Wed, 29 Apr 2020 02:59:44 -0700 Subject: [PATCH 1/3] Change files --- ...eact-native-windows-2020-04-29-02-59-44-yellowbox.json | 8 ++++++++ vnext/ReactUWP/Polyester/IconViewManager.cpp | 8 +++++--- vnext/ReactUWP/Views/ShadowNodeBase.cpp | 7 ++++++- vnext/include/ReactUWP/Views/ShadowNodeBase.h | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 change/react-native-windows-2020-04-29-02-59-44-yellowbox.json diff --git a/change/react-native-windows-2020-04-29-02-59-44-yellowbox.json b/change/react-native-windows-2020-04-29-02-59-44-yellowbox.json new file mode 100644 index 00000000000..4cf803a33b7 --- /dev/null +++ b/change/react-native-windows-2020-04-29-02-59-44-yellowbox.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Expose YellowBox functionality to native code", + "packageName": "react-native-windows", + "email": "asklar@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-29T09:59:44.174Z" +} diff --git a/vnext/ReactUWP/Polyester/IconViewManager.cpp b/vnext/ReactUWP/Polyester/IconViewManager.cpp index 10a43507480..1be6ee0d005 100644 --- a/vnext/ReactUWP/Polyester/IconViewManager.cpp +++ b/vnext/ReactUWP/Polyester/IconViewManager.cpp @@ -65,9 +65,11 @@ void IconShadowNode::updateProperties(const folly::dynamic &&props) { if (propertyName == "color") { if (IsValidColorValue(propertyValue)) glyphs.Fill(BrushFrom(propertyValue)); -#if FUTURE - else if (propertyValue.isNull()) - ; // Log error, must have a color +#ifdef DEBUG + else if (propertyValue.isNull()) { + // Log error, must have a color + YellowBox("IconShadowNode - color property must be non-null"); + } #endif } else if (propertyName == "fontUri") { if (propertyValue.isString()) { diff --git a/vnext/ReactUWP/Views/ShadowNodeBase.cpp b/vnext/ReactUWP/Views/ShadowNodeBase.cpp index 7a4e28e9981..87e0421c832 100644 --- a/vnext/ReactUWP/Views/ShadowNodeBase.cpp +++ b/vnext/ReactUWP/Views/ShadowNodeBase.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #include "pch.h" - +#include #include #include @@ -154,5 +154,10 @@ void ShadowNodeBase::EnsureHandledKeyboardEventHandler() { } } +void ShadowNodeBase::YellowBox(const std::string& message) { + const auto instance = GetViewManager()->GetReactInstance().lock(); + instance->CallJsFunction("RCTLog", "logToConsole", folly::dynamic::array("warn", message)); +} + } // namespace uwp } // namespace react diff --git a/vnext/include/ReactUWP/Views/ShadowNodeBase.h b/vnext/include/ReactUWP/Views/ShadowNodeBase.h index a81260c8201..c8020bd1289 100644 --- a/vnext/include/ReactUWP/Views/ShadowNodeBase.h +++ b/vnext/include/ReactUWP/Views/ShadowNodeBase.h @@ -68,6 +68,8 @@ struct REACTWINDOWS_EXPORT ShadowNodeBase : public facebook::react::ShadowNode { return false; } + void YellowBox(const std::string &message); + ViewManagerBase *GetViewManager() const; XamlView GetView() const { return m_view; From 0bd2810715eb07c226ab036794a141bf72df2fcf Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Wed, 29 Apr 2020 03:17:08 -0700 Subject: [PATCH 2/3] don't need sstream yet --- vnext/ReactUWP/Views/ShadowNodeBase.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vnext/ReactUWP/Views/ShadowNodeBase.cpp b/vnext/ReactUWP/Views/ShadowNodeBase.cpp index 87e0421c832..1e4b39c2a9b 100644 --- a/vnext/ReactUWP/Views/ShadowNodeBase.cpp +++ b/vnext/ReactUWP/Views/ShadowNodeBase.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #include "pch.h" -#include + #include #include @@ -154,8 +154,8 @@ void ShadowNodeBase::EnsureHandledKeyboardEventHandler() { } } -void ShadowNodeBase::YellowBox(const std::string& message) { - const auto instance = GetViewManager()->GetReactInstance().lock(); +void ShadowNodeBase::YellowBox(const std::string &message) { + const auto instance = GetViewManager()->GetReactInstance().lock(); instance->CallJsFunction("RCTLog", "logToConsole", folly::dynamic::array("warn", message)); } From 2c549893761e7bc02f3f364ed8fac7544ee79796 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Wed, 29 Apr 2020 10:40:49 -0700 Subject: [PATCH 3/3] const noexcept --- vnext/ReactUWP/Views/ShadowNodeBase.cpp | 6 ++++-- vnext/include/ReactUWP/Views/ShadowNodeBase.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/vnext/ReactUWP/Views/ShadowNodeBase.cpp b/vnext/ReactUWP/Views/ShadowNodeBase.cpp index 1e4b39c2a9b..f4d22f70f03 100644 --- a/vnext/ReactUWP/Views/ShadowNodeBase.cpp +++ b/vnext/ReactUWP/Views/ShadowNodeBase.cpp @@ -154,9 +154,11 @@ void ShadowNodeBase::EnsureHandledKeyboardEventHandler() { } } -void ShadowNodeBase::YellowBox(const std::string &message) { +void ShadowNodeBase::YellowBox(const std::string &message) const noexcept { const auto instance = GetViewManager()->GetReactInstance().lock(); - instance->CallJsFunction("RCTLog", "logToConsole", folly::dynamic::array("warn", message)); + if (instance) { + instance->CallJsFunction("RCTLog", "logToConsole", folly::dynamic::array("warn", message)); + } } } // namespace uwp diff --git a/vnext/include/ReactUWP/Views/ShadowNodeBase.h b/vnext/include/ReactUWP/Views/ShadowNodeBase.h index c8020bd1289..1c988f9be80 100644 --- a/vnext/include/ReactUWP/Views/ShadowNodeBase.h +++ b/vnext/include/ReactUWP/Views/ShadowNodeBase.h @@ -68,7 +68,7 @@ struct REACTWINDOWS_EXPORT ShadowNodeBase : public facebook::react::ShadowNode { return false; } - void YellowBox(const std::string &message); + void YellowBox(const std::string &message) const noexcept; ViewManagerBase *GetViewManager() const; XamlView GetView() const {