From 45a2fb84e8cbe53ad7ea190efab3919124ffb90b Mon Sep 17 00:00:00 2001 From: Di Da Date: Mon, 28 Oct 2019 10:35:31 -0700 Subject: [PATCH 1/6] Support Keyboard events --- packages/playground/Samples/textinput.tsx | 32 +++++- vnext/ReactUWP/ReactUWP.vcxproj | 4 + vnext/ReactUWP/Utils/RectUtils.cpp | 117 ++++++++++++++++++++++ vnext/ReactUWP/Views/ReactControl.cpp | 5 + vnext/ReactUWP/Views/ReactControl.h | 2 + vnext/ReactUWP/Views/SIPEventHandler.cpp | 72 +++++++++++++ vnext/ReactUWP/Views/SIPEventHandler.h | 31 ++++++ vnext/include/ReactUWP/Utils/RectUtils.h | 17 ++++ 8 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 vnext/ReactUWP/Utils/RectUtils.cpp create mode 100644 vnext/ReactUWP/Views/SIPEventHandler.cpp create mode 100644 vnext/ReactUWP/Views/SIPEventHandler.h create mode 100644 vnext/include/ReactUWP/Utils/RectUtils.h diff --git a/packages/playground/Samples/textinput.tsx b/packages/playground/Samples/textinput.tsx index 595cd757a39..0a5e8ac4d3f 100644 --- a/packages/playground/Samples/textinput.tsx +++ b/packages/playground/Samples/textinput.tsx @@ -5,9 +5,33 @@ */ import * as React from 'react'; -import {AppRegistry, Button, StyleSheet, TextInput, View} from 'react-native'; +import {AppRegistry, Button, StyleSheet, TextInput, Keyboard, View, KeyboardAvoidingView} from 'react-native'; export default class Bootstrap extends React.Component<{}, any> { + componentDidMount() { + this.keyboardDidShowListener = Keyboard.addListener( + 'keyboardDidShow', + this.keyboardDidShow, + ); + this.keyboardDidHideListener = Keyboard.addListener( + 'keyboardDidHide', + this.keyboardDidHide, + ); + } + + keyboardDidShow = () => { + console.log('keyboardDidShow'); + } + + keyboardDidHide = () => { + console.log('keyboardDidHide'); + } + + componentWillUnmount() { + this.keyboardDidShowListener.remove(); + this.keyboardDidHideListener.remove(); + } + state = { passwordHidden: true, text: '', @@ -82,6 +106,12 @@ export default class Bootstrap extends React.Component<{}, any> { } onPress={this.onPressShowPassword} /> + + + ); } diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index 5bfbd4d2a76..d0f2f1d0f55 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -151,6 +151,7 @@ + @@ -252,6 +253,7 @@ + @@ -276,6 +278,7 @@ + @@ -353,6 +356,7 @@ + diff --git a/vnext/ReactUWP/Utils/RectUtils.cpp b/vnext/ReactUWP/Utils/RectUtils.cpp new file mode 100644 index 00000000000..681208ce96a --- /dev/null +++ b/vnext/ReactUWP/Utils/RectUtils.cpp @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "pch.h" + +#include + +namespace winrt { +using namespace Windows::Foundation; +} // namespace winrt + +namespace react { +namespace uwp { + + // Represents positive infinity. +const float PositiveInfinity = std::numeric_limits::infinity(); + +// Represents negative infinity. +const float NegativeInfinity = -std::numeric_limits::infinity(); + +bool IsPositiveInfinity(float value) { + return value == PositiveInfinity; +} + +bool IsNegativeInfinity(float value) { + return value == NegativeInfinity; +} + +// This is a read-only alias for X. If this is the empty rectangle, +// the value will be positive infinity. +float GetLeft(_In_ winrt::Rect rect) { + return rect.X; +} + +// This is a read-only alias for Y. If this is the empty rectangle, +// the value will be positive infinity. +float GetTop(_In_ winrt::Rect rect) { + return rect.Y; +} + +// This is a read-only alias for X + Width. If this is the empty +// rectangle, the value will be negative infinity. +float GetRight(_In_ winrt::Rect rect) { + return (IsEmptyRect(rect) ? NegativeInfinity : rect.X + rect.Width); +} + +// This is a read-only alias for Y + Height. If this is the empty +// rectangle, the value will be negative infinity. +float GetBottom(_In_ winrt::Rect rect) { + return (IsEmptyRect(rect) ? NegativeInfinity : rect.Y + rect.Height); +} + +REACTWINDOWS_API_(bool) IsEmptyRect(winrt::Rect rect) { + return rect.Width < 0; +} + +REACTWINDOWS_API_(winrt::Rect) CreateEmptyRect() { + winrt::Rect result; + result.X = std::numeric_limits::infinity(); + result.Y = std::numeric_limits::infinity(); + result.Width = -std::numeric_limits::infinity(); + result.Height = -std::numeric_limits::infinity(); + return result; +} + +// Update this rectangle to be the union of this and rect. +REACTWINDOWS_API_(winrt::Rect) UnionRect(winrt::Rect rect1, _In_ winrt::Rect rect2) { + winrt::Rect result = rect1; + if (IsEmptyRect(rect1)) { + result.X = rect2.X; + result.Y = rect2.Y; + result.Width = rect2.Width; + result.Height = rect2.Height; + } else { + if (IsEmptyRect(rect2)) { + float left = 0.0f; + float top = 0.0f; + + left = std::min(rect1.X, rect2.X); + top = std::min(rect1.Y, rect2.Y); + + // We need this check so that the math does not result in NaN + if (IsPositiveInfinity(rect2.Width) || IsPositiveInfinity(rect1.Width)) { + result.Width = std::numeric_limits::infinity(); + } else { + float right1 = GetRight(rect1); + float right2 = GetRight(rect2); + float maxRight = 0.0f; + + maxRight = std::max(right1, right1); + result.Width = std::max(maxRight - left, 0.0f); + } + + // We need this check so that the math does not result in NaN + if (IsPositiveInfinity(rect2.Height) || IsPositiveInfinity(rect1.Height)) { + result.Height = PositiveInfinity; + } else { + float bottom1 = GetBottom(rect1); + float bottom2 = GetBottom(rect2); + float maxBottom = 0.0f; + + // Max with 0 to prevent double weirdness from causing us to be + // (-epsilon..0) + maxBottom = std::max(bottom1, bottom2); + result.Height = std::max(maxBottom - top, 0.0f); + } + + result.X = static_cast(left); + result.Y = static_cast(top); + } + } + + return result; +} + +} // namespace uwp +} // namespace react diff --git a/vnext/ReactUWP/Views/ReactControl.cpp b/vnext/ReactUWP/Views/ReactControl.cpp index fd979a9c61d..74ef6ce672d 100644 --- a/vnext/ReactUWP/Views/ReactControl.cpp +++ b/vnext/ReactUWP/Views/ReactControl.cpp @@ -172,6 +172,9 @@ void ReactControl::AttachRoot() noexcept { if (!m_touchEventHandler) m_touchEventHandler = std::make_shared(m_reactInstance); + if (!m_SIPEventHandler) + m_SIPEventHandler = std::make_shared(m_reactInstance); + m_previewKeyboardEventHandlerOnRoot = std::make_shared(m_reactInstance); // Register callback from instance for errors @@ -268,6 +271,8 @@ void ReactControl::DetachInstance() { // Clear members with a dependency on the reactInstance m_touchEventHandler.reset(); + + m_SIPEventHandler.reset(); } } diff --git a/vnext/ReactUWP/Views/ReactControl.h b/vnext/ReactUWP/Views/ReactControl.h index 03db192607e..e6bd45f17e9 100644 --- a/vnext/ReactUWP/Views/ReactControl.h +++ b/vnext/ReactUWP/Views/ReactControl.h @@ -9,6 +9,7 @@ #include #include #include "IXamlRootView.h" +#include "SIPEventHandler.h" #include "TouchEventHandler.h" #include "Views/KeyboardEventHandler.h" @@ -75,6 +76,7 @@ class ReactControl : public std::enable_shared_from_this, public I std::shared_ptr m_moduleProvider; folly::dynamic m_initialProps; std::shared_ptr m_touchEventHandler; + std::shared_ptr m_SIPEventHandler; std::shared_ptr m_previewKeyboardEventHandlerOnRoot; int64_t m_rootTag = -1; diff --git a/vnext/ReactUWP/Views/SIPEventHandler.cpp b/vnext/ReactUWP/Views/SIPEventHandler.cpp new file mode 100644 index 00000000000..067ee1dd120 --- /dev/null +++ b/vnext/ReactUWP/Views/SIPEventHandler.cpp @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include + +#include "SIPEventHandler.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace winrt { +using namespace Windows::UI; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI::ViewManagement::Core; +} // namespace winrt +namespace react { +namespace uwp { + +SIPEventHandler::SIPEventHandler(const std::weak_ptr &reactInstance) + : m_wkReactInstance(reactInstance) { + auto coreInputView = winrt::CoreInputView::GetForCurrentView(); + if (coreInputView) { + m_occlusionsChnaged_revoker = coreInputView.OcclusionsChanged( + winrt::auto_revoke, [=](auto &&, const winrt::CoreInputViewOcclusionsChangedEventArgs &e) { + if (!e.Handled()) { + winrt::Rect finalRect = CreateEmptyRect(); + winrt::IVectorView occlusions = e.Occlusions(); + for (uint32_t i = 0; i < occlusions.Size(); i++) { + winrt::CoreInputViewOcclusion occlusion = occlusions.GetAt(i); + if (occlusion.OcclusionKind() == winrt::CoreInputViewOcclusionKind::Docked) { + finalRect = UnionRect(finalRect, occlusion.OccludingRect()); + } + } + + if (IsEmptyRect(finalRect)) { + folly::dynamic params = folly::dynamic::object("screenY", 0)("screenX", 0)("width", 0)("height", 0); + SendEvent("keyboardDidHide", std::move(params)); + } else { + folly::dynamic params = folly::dynamic::object( + "endCoordinates", + folly::dynamic::object("screenY", finalRect.Y)("screenX", finalRect.X)("width", finalRect.Width)( + "height", finalRect.Height)); + SendEvent("keyboardDidShow", std::move(params)); + } + } + }); + } +} + +SIPEventHandler::~SIPEventHandler() { + m_occlusionsChnaged_revoker = {}; +} + +void SIPEventHandler::SendEvent(std::string &&eventName, folly::dynamic &¶meters) { + if (auto instance = m_wkReactInstance.lock()) { + instance->CallJsFunction( + "RCTDeviceEventEmitter", "emit", folly::dynamic::array(std::move(eventName), std::move(parameters))); + } +} +} // namespace uwp +} // namespace react diff --git a/vnext/ReactUWP/Views/SIPEventHandler.h b/vnext/ReactUWP/Views/SIPEventHandler.h new file mode 100644 index 00000000000..646b7e6bc37 --- /dev/null +++ b/vnext/ReactUWP/Views/SIPEventHandler.h @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once +#include + +#include +#include + +namespace winrt { +using namespace Windows::UI; +using namespace Windows::Foundation; +using namespace Windows::UI::ViewManagement::Core; +} // namespace winrt + +namespace react { +namespace uwp { + +class SIPEventHandler { + public: + SIPEventHandler(const std::weak_ptr &reactInstance); + virtual ~SIPEventHandler(); + + private: + void SendEvent(std::string &&eventName, folly::dynamic &¶meters); + std::weak_ptr m_wkReactInstance; + winrt::CoreInputView::OcclusionsChanged_revoker m_occlusionsChnaged_revoker; +}; + +} // namespace uwp +} // namespace react diff --git a/vnext/include/ReactUWP/Utils/RectUtils.h b/vnext/include/ReactUWP/Utils/RectUtils.h new file mode 100644 index 00000000000..8e1d617da30 --- /dev/null +++ b/vnext/include/ReactUWP/Utils/RectUtils.h @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +#include +#include + +namespace react { +namespace uwp { + + REACTWINDOWS_API_(bool) IsEmptyRect(winrt::Windows::Foundation::Rect rect); + REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) CreateEmptyRect(); + REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) UnionRect(winrt::Windows::Foundation::Rect rect1, _In_ winrt::Windows::Foundation::Rect rect2); + + } // namespace uwp +} // namespace react From f8b6debb710fa742cf12e40054a600ab201a0537 Mon Sep 17 00:00:00 2001 From: Di Da Date: Mon, 28 Oct 2019 10:44:55 -0700 Subject: [PATCH 2/6] Change files --- ...eact-native-windows-2019-10-28-10-44-55-keyboard.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 change/react-native-windows-2019-10-28-10-44-55-keyboard.json diff --git a/change/react-native-windows-2019-10-28-10-44-55-keyboard.json b/change/react-native-windows-2019-10-28-10-44-55-keyboard.json new file mode 100644 index 00000000000..1e22476be3b --- /dev/null +++ b/change/react-native-windows-2019-10-28-10-44-55-keyboard.json @@ -0,0 +1,9 @@ +{ + "type": "prerelease", + "comment": "Support Keyboard events", + "packageName": "react-native-windows", + "email": "dida@ntdev.microsoft.com", + "commit": "45a2fb84e8cbe53ad7ea190efab3919124ffb90b", + "date": "2019-10-28T17:44:55.590Z", + "file": "D:\\react2\\react-native-windows\\change\\react-native-windows-2019-10-28-10-44-55-keyboard.json" +} \ No newline at end of file From 8683dada558b80557a99ae2c6760ee9f157cdba3 Mon Sep 17 00:00:00 2001 From: Di Da Date: Mon, 28 Oct 2019 11:52:48 -0700 Subject: [PATCH 3/6] format --- vnext/ReactUWP/Utils/RectUtils.cpp | 2 +- vnext/include/ReactUWP/Utils/RectUtils.h | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/vnext/ReactUWP/Utils/RectUtils.cpp b/vnext/ReactUWP/Utils/RectUtils.cpp index 681208ce96a..c48a5d62176 100644 --- a/vnext/ReactUWP/Utils/RectUtils.cpp +++ b/vnext/ReactUWP/Utils/RectUtils.cpp @@ -12,7 +12,7 @@ using namespace Windows::Foundation; namespace react { namespace uwp { - // Represents positive infinity. +// Represents positive infinity. const float PositiveInfinity = std::numeric_limits::infinity(); // Represents negative infinity. diff --git a/vnext/include/ReactUWP/Utils/RectUtils.h b/vnext/include/ReactUWP/Utils/RectUtils.h index 8e1d617da30..65ce6cbb011 100644 --- a/vnext/include/ReactUWP/Utils/RectUtils.h +++ b/vnext/include/ReactUWP/Utils/RectUtils.h @@ -3,15 +3,16 @@ #pragma once -#include #include +#include namespace react { namespace uwp { - REACTWINDOWS_API_(bool) IsEmptyRect(winrt::Windows::Foundation::Rect rect); - REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) CreateEmptyRect(); - REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) UnionRect(winrt::Windows::Foundation::Rect rect1, _In_ winrt::Windows::Foundation::Rect rect2); +REACTWINDOWS_API_(bool) IsEmptyRect(winrt::Windows::Foundation::Rect rect); +REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) CreateEmptyRect(); +REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) +UnionRect(winrt::Windows::Foundation::Rect rect1, _In_ winrt::Windows::Foundation::Rect rect2); - } // namespace uwp +} // namespace uwp } // namespace react From bb8407b9d0b544f57016b97116e0ac77764cb7a2 Mon Sep 17 00:00:00 2001 From: Di Da Date: Mon, 28 Oct 2019 12:54:36 -0700 Subject: [PATCH 4/6] buildci --- packages/playground/Samples/textinput.tsx | 37 ++++++++++++++--------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/playground/Samples/textinput.tsx b/packages/playground/Samples/textinput.tsx index 0a5e8ac4d3f..53ac5cb107a 100644 --- a/packages/playground/Samples/textinput.tsx +++ b/packages/playground/Samples/textinput.tsx @@ -5,31 +5,35 @@ */ import * as React from 'react'; -import {AppRegistry, Button, StyleSheet, TextInput, Keyboard, View, KeyboardAvoidingView} from 'react-native'; +import { + AppRegistry, + Button, + StyleSheet, + TextInput, + Keyboard, + View, + KeyboardAvoidingView, +} from 'react-native'; export default class Bootstrap extends React.Component<{}, any> { componentDidMount() { - this.keyboardDidShowListener = Keyboard.addListener( - 'keyboardDidShow', - this.keyboardDidShow, - ); - this.keyboardDidHideListener = Keyboard.addListener( - 'keyboardDidHide', - this.keyboardDidHide, - ); + Keyboard.addListener('keyboardDidShow', this.keyboardDidShow); + + Keyboard.addListener('keyboardDidHide', this.keyboardDidHide); } keyboardDidShow = () => { console.log('keyboardDidShow'); - } + }; keyboardDidHide = () => { console.log('keyboardDidHide'); - } + }; componentWillUnmount() { - this.keyboardDidShowListener.remove(); - this.keyboardDidHideListener.remove(); + Keyboard.removeListener('keyboardDidShow', this.keyboardDidShow); + + Keyboard.removeListener('keyboardDidHide', this.keyboardDidHide); } state = { @@ -106,12 +110,15 @@ export default class Bootstrap extends React.Component<{}, any> { } onPress={this.onPressShowPassword} /> - + - + ); } From fd22a00b92c0ae0fe6cd8fcdeed80e76676f083a Mon Sep 17 00:00:00 2001 From: Di Da Date: Mon, 28 Oct 2019 15:02:40 -0700 Subject: [PATCH 5/6] Use RectHelper --- vnext/ReactUWP/ReactUWP.vcxproj | 2 - vnext/ReactUWP/Utils/RectUtils.cpp | 117 ----------------------- vnext/ReactUWP/Views/SIPEventHandler.cpp | 16 +--- vnext/ReactUWP/Views/SIPEventHandler.h | 1 - vnext/include/ReactUWP/Utils/RectUtils.h | 18 ---- 5 files changed, 4 insertions(+), 150 deletions(-) delete mode 100644 vnext/ReactUWP/Utils/RectUtils.cpp delete mode 100644 vnext/include/ReactUWP/Utils/RectUtils.h diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index d0f2f1d0f55..43b2c9bba20 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -151,7 +151,6 @@ - @@ -278,7 +277,6 @@ - diff --git a/vnext/ReactUWP/Utils/RectUtils.cpp b/vnext/ReactUWP/Utils/RectUtils.cpp deleted file mode 100644 index c48a5d62176..00000000000 --- a/vnext/ReactUWP/Utils/RectUtils.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -#include - -namespace winrt { -using namespace Windows::Foundation; -} // namespace winrt - -namespace react { -namespace uwp { - -// Represents positive infinity. -const float PositiveInfinity = std::numeric_limits::infinity(); - -// Represents negative infinity. -const float NegativeInfinity = -std::numeric_limits::infinity(); - -bool IsPositiveInfinity(float value) { - return value == PositiveInfinity; -} - -bool IsNegativeInfinity(float value) { - return value == NegativeInfinity; -} - -// This is a read-only alias for X. If this is the empty rectangle, -// the value will be positive infinity. -float GetLeft(_In_ winrt::Rect rect) { - return rect.X; -} - -// This is a read-only alias for Y. If this is the empty rectangle, -// the value will be positive infinity. -float GetTop(_In_ winrt::Rect rect) { - return rect.Y; -} - -// This is a read-only alias for X + Width. If this is the empty -// rectangle, the value will be negative infinity. -float GetRight(_In_ winrt::Rect rect) { - return (IsEmptyRect(rect) ? NegativeInfinity : rect.X + rect.Width); -} - -// This is a read-only alias for Y + Height. If this is the empty -// rectangle, the value will be negative infinity. -float GetBottom(_In_ winrt::Rect rect) { - return (IsEmptyRect(rect) ? NegativeInfinity : rect.Y + rect.Height); -} - -REACTWINDOWS_API_(bool) IsEmptyRect(winrt::Rect rect) { - return rect.Width < 0; -} - -REACTWINDOWS_API_(winrt::Rect) CreateEmptyRect() { - winrt::Rect result; - result.X = std::numeric_limits::infinity(); - result.Y = std::numeric_limits::infinity(); - result.Width = -std::numeric_limits::infinity(); - result.Height = -std::numeric_limits::infinity(); - return result; -} - -// Update this rectangle to be the union of this and rect. -REACTWINDOWS_API_(winrt::Rect) UnionRect(winrt::Rect rect1, _In_ winrt::Rect rect2) { - winrt::Rect result = rect1; - if (IsEmptyRect(rect1)) { - result.X = rect2.X; - result.Y = rect2.Y; - result.Width = rect2.Width; - result.Height = rect2.Height; - } else { - if (IsEmptyRect(rect2)) { - float left = 0.0f; - float top = 0.0f; - - left = std::min(rect1.X, rect2.X); - top = std::min(rect1.Y, rect2.Y); - - // We need this check so that the math does not result in NaN - if (IsPositiveInfinity(rect2.Width) || IsPositiveInfinity(rect1.Width)) { - result.Width = std::numeric_limits::infinity(); - } else { - float right1 = GetRight(rect1); - float right2 = GetRight(rect2); - float maxRight = 0.0f; - - maxRight = std::max(right1, right1); - result.Width = std::max(maxRight - left, 0.0f); - } - - // We need this check so that the math does not result in NaN - if (IsPositiveInfinity(rect2.Height) || IsPositiveInfinity(rect1.Height)) { - result.Height = PositiveInfinity; - } else { - float bottom1 = GetBottom(rect1); - float bottom2 = GetBottom(rect2); - float maxBottom = 0.0f; - - // Max with 0 to prevent double weirdness from causing us to be - // (-epsilon..0) - maxBottom = std::max(bottom1, bottom2); - result.Height = std::max(maxBottom - top, 0.0f); - } - - result.X = static_cast(left); - result.Y = static_cast(top); - } - } - - return result; -} - -} // namespace uwp -} // namespace react diff --git a/vnext/ReactUWP/Views/SIPEventHandler.cpp b/vnext/ReactUWP/Views/SIPEventHandler.cpp index 067ee1dd120..77e61e8cff9 100644 --- a/vnext/ReactUWP/Views/SIPEventHandler.cpp +++ b/vnext/ReactUWP/Views/SIPEventHandler.cpp @@ -6,23 +6,15 @@ #include "SIPEventHandler.h" #include -#include #include -#include #include -#include -#include -#include -#include -#include -#include namespace winrt { -using namespace Windows::UI; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::UI::ViewManagement::Core; +using namespace Windows::UI::Xaml; } // namespace winrt namespace react { namespace uwp { @@ -34,16 +26,16 @@ SIPEventHandler::SIPEventHandler(const std::weak_ptr &reactInsta m_occlusionsChnaged_revoker = coreInputView.OcclusionsChanged( winrt::auto_revoke, [=](auto &&, const winrt::CoreInputViewOcclusionsChangedEventArgs &e) { if (!e.Handled()) { - winrt::Rect finalRect = CreateEmptyRect(); + winrt::Rect finalRect = winrt::RectHelper::Empty(); winrt::IVectorView occlusions = e.Occlusions(); for (uint32_t i = 0; i < occlusions.Size(); i++) { winrt::CoreInputViewOcclusion occlusion = occlusions.GetAt(i); if (occlusion.OcclusionKind() == winrt::CoreInputViewOcclusionKind::Docked) { - finalRect = UnionRect(finalRect, occlusion.OccludingRect()); + finalRect = winrt::RectHelper::Union(finalRect, occlusion.OccludingRect()); } } - if (IsEmptyRect(finalRect)) { + if (winrt::RectHelper::GetIsEmpty(finalRect)) { folly::dynamic params = folly::dynamic::object("screenY", 0)("screenX", 0)("width", 0)("height", 0); SendEvent("keyboardDidHide", std::move(params)); } else { diff --git a/vnext/ReactUWP/Views/SIPEventHandler.h b/vnext/ReactUWP/Views/SIPEventHandler.h index 646b7e6bc37..6781e1ea852 100644 --- a/vnext/ReactUWP/Views/SIPEventHandler.h +++ b/vnext/ReactUWP/Views/SIPEventHandler.h @@ -8,7 +8,6 @@ #include namespace winrt { -using namespace Windows::UI; using namespace Windows::Foundation; using namespace Windows::UI::ViewManagement::Core; } // namespace winrt diff --git a/vnext/include/ReactUWP/Utils/RectUtils.h b/vnext/include/ReactUWP/Utils/RectUtils.h deleted file mode 100644 index 65ce6cbb011..00000000000 --- a/vnext/include/ReactUWP/Utils/RectUtils.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include -#include - -namespace react { -namespace uwp { - -REACTWINDOWS_API_(bool) IsEmptyRect(winrt::Windows::Foundation::Rect rect); -REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) CreateEmptyRect(); -REACTWINDOWS_API_(winrt::Windows::Foundation::Rect) -UnionRect(winrt::Windows::Foundation::Rect rect1, _In_ winrt::Windows::Foundation::Rect rect2); - -} // namespace uwp -} // namespace react From 5a4a4f83d6f69a41a4af9ce14f4255458fa21b29 Mon Sep 17 00:00:00 2001 From: Di Da Date: Mon, 28 Oct 2019 15:04:59 -0700 Subject: [PATCH 6/6] typo --- vnext/ReactUWP/Views/SIPEventHandler.cpp | 4 ++-- vnext/ReactUWP/Views/SIPEventHandler.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vnext/ReactUWP/Views/SIPEventHandler.cpp b/vnext/ReactUWP/Views/SIPEventHandler.cpp index 77e61e8cff9..f3c7ec7c4b3 100644 --- a/vnext/ReactUWP/Views/SIPEventHandler.cpp +++ b/vnext/ReactUWP/Views/SIPEventHandler.cpp @@ -23,7 +23,7 @@ SIPEventHandler::SIPEventHandler(const std::weak_ptr &reactInsta : m_wkReactInstance(reactInstance) { auto coreInputView = winrt::CoreInputView::GetForCurrentView(); if (coreInputView) { - m_occlusionsChnaged_revoker = coreInputView.OcclusionsChanged( + m_occlusionsChanged_revoker = coreInputView.OcclusionsChanged( winrt::auto_revoke, [=](auto &&, const winrt::CoreInputViewOcclusionsChangedEventArgs &e) { if (!e.Handled()) { winrt::Rect finalRect = winrt::RectHelper::Empty(); @@ -51,7 +51,7 @@ SIPEventHandler::SIPEventHandler(const std::weak_ptr &reactInsta } SIPEventHandler::~SIPEventHandler() { - m_occlusionsChnaged_revoker = {}; + m_occlusionsChanged_revoker = {}; } void SIPEventHandler::SendEvent(std::string &&eventName, folly::dynamic &¶meters) { diff --git a/vnext/ReactUWP/Views/SIPEventHandler.h b/vnext/ReactUWP/Views/SIPEventHandler.h index 6781e1ea852..142bd258f55 100644 --- a/vnext/ReactUWP/Views/SIPEventHandler.h +++ b/vnext/ReactUWP/Views/SIPEventHandler.h @@ -23,7 +23,7 @@ class SIPEventHandler { private: void SendEvent(std::string &&eventName, folly::dynamic &¶meters); std::weak_ptr m_wkReactInstance; - winrt::CoreInputView::OcclusionsChanged_revoker m_occlusionsChnaged_revoker; + winrt::CoreInputView::OcclusionsChanged_revoker m_occlusionsChanged_revoker; }; } // namespace uwp