-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support Keyboard events
- Loading branch information
Showing
7 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
change/react-native-windows-2019-10-28-10-44-55-keyboard.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Support Keyboard events", | ||
"packageName": "react-native-windows", | ||
"email": "[email protected]", | ||
"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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include <pch.h> | ||
|
||
#include "SIPEventHandler.h" | ||
|
||
#include <Modules/NativeUIManager.h> | ||
|
||
#include <winrt/Windows.ApplicationModel.Core.h> | ||
#include <winrt/Windows.Foundation.h> | ||
|
||
namespace winrt { | ||
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 { | ||
|
||
SIPEventHandler::SIPEventHandler(const std::weak_ptr<IReactInstance> &reactInstance) | ||
: m_wkReactInstance(reactInstance) { | ||
auto coreInputView = winrt::CoreInputView::GetForCurrentView(); | ||
if (coreInputView) { | ||
m_occlusionsChanged_revoker = coreInputView.OcclusionsChanged( | ||
winrt::auto_revoke, [=](auto &&, const winrt::CoreInputViewOcclusionsChangedEventArgs &e) { | ||
if (!e.Handled()) { | ||
winrt::Rect finalRect = winrt::RectHelper::Empty(); | ||
winrt::IVectorView<winrt::CoreInputViewOcclusion> 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 = winrt::RectHelper::Union(finalRect, occlusion.OccludingRect()); | ||
} | ||
} | ||
|
||
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 { | ||
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_occlusionsChanged_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include <folly/dynamic.h> | ||
|
||
#include <IReactInstance.h> | ||
#include <winrt/Windows.UI.ViewManagement.Core.h> | ||
|
||
namespace winrt { | ||
using namespace Windows::Foundation; | ||
using namespace Windows::UI::ViewManagement::Core; | ||
} // namespace winrt | ||
|
||
namespace react { | ||
namespace uwp { | ||
|
||
class SIPEventHandler { | ||
public: | ||
SIPEventHandler(const std::weak_ptr<IReactInstance> &reactInstance); | ||
virtual ~SIPEventHandler(); | ||
|
||
private: | ||
void SendEvent(std::string &&eventName, folly::dynamic &¶meters); | ||
std::weak_ptr<IReactInstance> m_wkReactInstance; | ||
winrt::CoreInputView::OcclusionsChanged_revoker m_occlusionsChanged_revoker; | ||
}; | ||
|
||
} // namespace uwp | ||
} // namespace react |