Valentin Shergin 610dac4461 Fabric: Migrating ViewEventEmitter to JSI-based payload
Summary: Pretty straight-forward migration to using `JSI` instead of `folly::dynamic` in ViewEventEmitter.

Reviewed By: sahrens

Differential Revision: D13123048

fbshipit-source-id: 3c323912d3e65b684f99df6cda99c785876164af
2018-11-27 21:00:56 -08:00

48 lines
1.3 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");
}
#pragma mark - Layout
void ViewEventEmitter::onLayout(const LayoutMetrics &layoutMetrics) const {
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