Fabric: Migrating ScrollViewEventEmitter to JSI-based payload
Summary: Pretty straight-forward migration to using `JSI` instead of `folly::dynamic` in `ScrollViewEventEmitter`. Reviewed By: sahrens Differential Revision: D13123049 fbshipit-source-id: 2839976d0119c48fa2538dbaa53afbc24982c598
This commit is contained in:
Родитель
610dac4461
Коммит
847e6fdd99
|
@ -10,6 +10,54 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static jsi::Value scrollViewMetricsPayload(
|
||||
jsi::Runtime &runtime,
|
||||
const ScrollViewMetrics &scrollViewMetrics) {
|
||||
auto payload = jsi::Object(runtime);
|
||||
|
||||
{
|
||||
auto contentOffset = jsi::Object(runtime);
|
||||
contentOffset.setProperty(runtime, "x", scrollViewMetrics.contentOffset.x);
|
||||
contentOffset.setProperty(runtime, "y", scrollViewMetrics.contentOffset.y);
|
||||
payload.setProperty(runtime, "contentOffset", contentOffset);
|
||||
}
|
||||
|
||||
{
|
||||
auto contentInset = jsi::Object(runtime);
|
||||
contentInset.setProperty(
|
||||
runtime, "top", scrollViewMetrics.contentInset.top);
|
||||
contentInset.setProperty(
|
||||
runtime, "left", scrollViewMetrics.contentInset.left);
|
||||
contentInset.setProperty(
|
||||
runtime, "bottom", scrollViewMetrics.contentInset.bottom);
|
||||
contentInset.setProperty(
|
||||
runtime, "right", scrollViewMetrics.contentInset.right);
|
||||
payload.setProperty(runtime, "contentInset", contentInset);
|
||||
}
|
||||
|
||||
{
|
||||
auto contentSize = jsi::Object(runtime);
|
||||
contentSize.setProperty(
|
||||
runtime, "width", scrollViewMetrics.contentSize.width);
|
||||
contentSize.setProperty(
|
||||
runtime, "height", scrollViewMetrics.contentSize.height);
|
||||
payload.setProperty(runtime, "contentSize", contentSize);
|
||||
}
|
||||
|
||||
{
|
||||
auto containerSize = jsi::Object(runtime);
|
||||
containerSize.setProperty(
|
||||
runtime, "width", scrollViewMetrics.containerSize.width);
|
||||
containerSize.setProperty(
|
||||
runtime, "height", scrollViewMetrics.containerSize.height);
|
||||
payload.setProperty(runtime, "layoutMeasurement", containerSize);
|
||||
}
|
||||
|
||||
payload.setProperty(runtime, "zoomScale", scrollViewMetrics.zoomScale);
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
void ScrollViewEventEmitter::onScroll(
|
||||
const ScrollViewMetrics &scrollViewMetrics) const {
|
||||
dispatchScrollViewEvent("scroll", scrollViewMetrics);
|
||||
|
@ -38,34 +86,13 @@ void ScrollViewEventEmitter::onMomentumScrollEnd(
|
|||
void ScrollViewEventEmitter::dispatchScrollViewEvent(
|
||||
const std::string &name,
|
||||
const ScrollViewMetrics &scrollViewMetrics,
|
||||
const folly::dynamic &payload) const {
|
||||
folly::dynamic compoundPayload = folly::dynamic::object();
|
||||
|
||||
compoundPayload["contentOffset"] =
|
||||
folly::dynamic::object("x", scrollViewMetrics.contentOffset.x)(
|
||||
"y", scrollViewMetrics.contentOffset.y);
|
||||
|
||||
compoundPayload["contentInset"] =
|
||||
folly::dynamic::object("top", scrollViewMetrics.contentInset.top)(
|
||||
"left", scrollViewMetrics.contentInset.left)(
|
||||
"bottom", scrollViewMetrics.contentInset.bottom)(
|
||||
"right", scrollViewMetrics.contentInset.right);
|
||||
|
||||
compoundPayload["contentSize"] =
|
||||
folly::dynamic::object("width", scrollViewMetrics.contentSize.width)(
|
||||
"height", scrollViewMetrics.contentSize.height);
|
||||
|
||||
compoundPayload["layoutMeasurement"] =
|
||||
folly::dynamic::object("width", scrollViewMetrics.containerSize.width)(
|
||||
"height", scrollViewMetrics.containerSize.height);
|
||||
|
||||
compoundPayload["zoomScale"] = scrollViewMetrics.zoomScale;
|
||||
|
||||
if (!payload.isNull()) {
|
||||
compoundPayload.merge_patch(payload);
|
||||
}
|
||||
|
||||
dispatchEvent(name, compoundPayload);
|
||||
EventPriority priority) const {
|
||||
dispatchEvent(
|
||||
name,
|
||||
[scrollViewMetrics](jsi::Runtime &runtime) {
|
||||
return scrollViewMetricsPayload(runtime, scrollViewMetrics);
|
||||
},
|
||||
priority);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -44,7 +44,7 @@ class ScrollViewEventEmitter : public ViewEventEmitter {
|
|||
void dispatchScrollViewEvent(
|
||||
const std::string &name,
|
||||
const ScrollViewMetrics &scrollViewMetrics,
|
||||
const folly::dynamic &payload = {}) const;
|
||||
EventPriority priority = EventPriority::AsynchronousBatched) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
Загрузка…
Ссылка в новой задаче