-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Note: Some features are not suported yet, e.g. event throttling. Reviewed By: fkgozali Differential Revision: D8082771 fbshipit-source-id: d60f6e9011283aeee7aff77dc9178e99f06deb5c
- Loading branch information
1 parent
2064568
commit 21189be
Showing
6 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "ScrollViewEventHandlers.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
void ScrollViewEventHandlers::onScroll(const ScrollViewMetrics &scrollViewMetrics) const { | ||
dispatchScrollViewEvent("scroll", scrollViewMetrics); | ||
} | ||
|
||
void ScrollViewEventHandlers::onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const { | ||
dispatchScrollViewEvent("scrollBeginDrag", scrollViewMetrics); | ||
} | ||
|
||
void ScrollViewEventHandlers::onScrollEndDrag(const ScrollViewMetrics &scrollViewMetrics) const { | ||
dispatchScrollViewEvent("scrollEndDrag", scrollViewMetrics); | ||
} | ||
|
||
void ScrollViewEventHandlers::onMomentumScrollBegin(const ScrollViewMetrics &scrollViewMetrics) const { | ||
dispatchScrollViewEvent("momentumScrollBegin", scrollViewMetrics); | ||
} | ||
|
||
void ScrollViewEventHandlers::onMomentumScrollEnd(const ScrollViewMetrics &scrollViewMetrics) const { | ||
dispatchScrollViewEvent("momentumScrollEnd", scrollViewMetrics); | ||
} | ||
|
||
void ScrollViewEventHandlers::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <fabric/graphics/Geometry.h> | ||
#include <fabric/core/EventHandlers.h> | ||
#include <fabric/view/ViewEventHandlers.h> | ||
|
||
#include <folly/dynamic.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class ScrollViewMetrics { | ||
public: | ||
Size contentSize; | ||
Point contentOffset; | ||
EdgeInsets contentInset; | ||
Size containerSize; | ||
Float zoomScale; | ||
}; | ||
|
||
class ScrollViewEventHandlers; | ||
|
||
using SharedScrollViewEventHandlers = std::shared_ptr<const ScrollViewEventHandlers>; | ||
|
||
class ScrollViewEventHandlers: | ||
public ViewEventHandlers { | ||
|
||
public: | ||
|
||
using ViewEventHandlers::ViewEventHandlers; | ||
|
||
void onScroll(const ScrollViewMetrics &scrollViewMetrics) const; | ||
void onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const; | ||
void onScrollEndDrag(const ScrollViewMetrics &scrollViewMetrics) const; | ||
void onMomentumScrollBegin(const ScrollViewMetrics &scrollViewMetrics) const; | ||
void onMomentumScrollEnd(const ScrollViewMetrics &scrollViewMetrics) const; | ||
|
||
private: | ||
|
||
void dispatchScrollViewEvent(const std::string &name, const ScrollViewMetrics &scrollViewMetrics, const folly::dynamic &payload = {}) const; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters