Skip to content

Commit a2df86c

Browse files
authored
View focus fixes, remove click fallback (#2968)
* Only send focus/blur from OriginalSource, remove Click event for enter/space * Change files
1 parent a60cfee commit a2df86c

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Only send focus/blur from OriginalSource, remove Click event for enter/space",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"commit": "bb3ed51419101c4de0d51016cad3fd8703a0bb0e",
7+
"date": "2019-08-20T21:12:15.173Z"
8+
}

vnext/ReactUWP/Views/ViewViewManager.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,22 @@ class ViewShadowNode : public ShadowNodeBase {
175175
winrt::make<winrt::react::uwp::implementation::ViewControl>();
176176

177177
m_contentControlGotFocusRevoker =
178-
contentControl.GotFocus(winrt::auto_revoke, [=](auto &&, auto &&) {
179-
DispatchEvent(
180-
"topFocus", std::move(folly::dynamic::object("target", m_tag)));
178+
contentControl.GotFocus(winrt::auto_revoke, [=](auto &&, auto &&args) {
179+
if (args.OriginalSource().try_as<winrt::UIElement>() ==
180+
contentControl.as<winrt::UIElement>()) {
181+
auto tag = m_tag;
182+
DispatchEvent(
183+
"topFocus", std::move(folly::dynamic::object("target", tag)));
184+
}
181185
});
182186

183187
m_contentControlLostFocusRevoker =
184-
contentControl.LostFocus(winrt::auto_revoke, [=](auto &&, auto &&) {
185-
DispatchEvent(
186-
"topBlur", std::move(folly::dynamic::object("target", m_tag)));
187-
});
188-
189-
// FUTURE: The space/enter handler can be removed in August 2019, still here
190-
// to enable transitioning to new events if native code is updated before JS
191-
m_contentControlKeyDownRevoker = contentControl.KeyDown(
192-
winrt::auto_revoke, [=](auto &&, winrt::KeyRoutedEventArgs const &e) {
193-
if (e.Key() == winrt::VirtualKey::Enter ||
194-
e.Key() == winrt::VirtualKey::Space) {
195-
if (OnClick()) {
196-
DispatchEvent(
197-
"topClick",
198-
std::move(folly::dynamic::object("target", m_tag)));
199-
e.Handled(true);
200-
}
188+
contentControl.LostFocus(winrt::auto_revoke, [=](auto &&, auto &&args) {
189+
if (args.OriginalSource().try_as<winrt::UIElement>() ==
190+
contentControl.as<winrt::UIElement>()) {
191+
auto tag = m_tag;
192+
DispatchEvent(
193+
"topBlur", std::move(folly::dynamic::object("target", tag)));
201194
}
202195
});
203196

@@ -220,7 +213,6 @@ class ViewShadowNode : public ShadowNodeBase {
220213

221214
winrt::ContentControl::GotFocus_revoker m_contentControlGotFocusRevoker{};
222215
winrt::ContentControl::LostFocus_revoker m_contentControlLostFocusRevoker{};
223-
winrt::ContentControl::KeyDown_revoker m_contentControlKeyDownRevoker{};
224216
};
225217

226218
// ViewPanel uses a ViewBackground property, not Background, so need to

0 commit comments

Comments
 (0)