react-native/ReactCommon/fabric/components/scrollview/ScrollViewEventEmitter.cpp
Valentin Shergin 3ad5c9e016 Fabric: Enabling clang-format for half of Fabric modules
Summary:
All code styles are terribly ugly. We have the only choise - choise something and embrace it.
This particular code style was borrowed from a neibour Fabric-friendly project because it follows established Facebook guides and respects client-side traditions.

Reviewed By: mdvacca

Differential Revision: D10218598

fbshipit-source-id: 8c4cf6713c07768566dadef479191661c79988f0
2018-10-05 11:03:23 -07:00

73 lines
2.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 "ScrollViewEventEmitter.h"
namespace facebook {
namespace react {
void ScrollViewEventEmitter::onScroll(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scroll", scrollViewMetrics);
}
void ScrollViewEventEmitter::onScrollBeginDrag(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scrollBeginDrag", scrollViewMetrics);
}
void ScrollViewEventEmitter::onScrollEndDrag(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scrollEndDrag", scrollViewMetrics);
}
void ScrollViewEventEmitter::onMomentumScrollBegin(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("momentumScrollBegin", scrollViewMetrics);
}
void ScrollViewEventEmitter::onMomentumScrollEnd(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("momentumScrollEnd", scrollViewMetrics);
}
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);
}
} // namespace react
} // namespace facebook