Files
react-native/ReactCommon/react/renderer/components/view/ViewEventEmitter.cpp
T
David Vacca 3093010ea5 move fabric to ReactCommon/react/renderer
Summary:
This diff moves fabric C++ code from ReactCommon/fabric to ReactCommon/react/renderer
As part of this diff I also refactored components, codegen and callsites on CatalystApp, FB4A and venice

Script: P137350694

changelog: [internal] internal refactor

Reviewed By: fkgozali

Differential Revision: D22852139

fbshipit-source-id: f85310ba858b6afd81abfd9cbe6d70b28eca7415
2020-07-31 13:34:29 -07:00

63 lines
1.8 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ViewEventEmitter.h"
namespace facebook {
namespace react {
#pragma mark - Accessibility
void ViewEventEmitter::onAccessibilityAction(const std::string &name) const {
dispatchEvent("accessibilityAction", [name](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "action", name);
return payload;
});
}
void ViewEventEmitter::onAccessibilityTap() const {
dispatchEvent("accessibilityTap");
}
void ViewEventEmitter::onAccessibilityMagicTap() const {
dispatchEvent("magicTap");
}
void ViewEventEmitter::onAccessibilityEscape() const {
dispatchEvent("accessibilityEscape");
}
#pragma mark - Layout
void ViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
// Due to State Reconciliation, `onLayout` can be called potentially many
// times with identical layoutMetrics. Ensure that the JS event is only
// dispatched when the value changes.
{
std::lock_guard<std::mutex> guard(layoutMetricsMutex_);
if (lastLayoutMetrics_ == layoutMetrics) {
return;
}
lastLayoutMetrics_ = layoutMetrics;
}
dispatchEvent("layout", [frame = layoutMetrics.frame](jsi::Runtime &runtime) {
auto layout = jsi::Object(runtime);
layout.setProperty(runtime, "x", frame.origin.x);
layout.setProperty(runtime, "y", frame.origin.y);
layout.setProperty(runtime, "width", frame.size.width);
layout.setProperty(runtime, "height", frame.size.height);
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "layout", std::move(layout));
return payload;
});
}
} // namespace react
} // namespace facebook