File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed
Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,32 @@ void LayoutableShadowNode::layout(LayoutContext layoutContext) {
114114 }
115115}
116116
117+ ShadowNode::Shared LayoutableShadowNode::findNodeAtPoint (
118+ ShadowNode::Shared node,
119+ Point point) {
120+ auto layoutableShadowNode =
121+ dynamic_cast <const LayoutableShadowNode *>(node.get ());
122+
123+ if (!layoutableShadowNode) {
124+ return nullptr ;
125+ }
126+ auto frame = layoutableShadowNode->getLayoutMetrics ().frame ;
127+ auto isPointInside = frame.containsPoint (point);
128+
129+ if (!isPointInside) {
130+ return nullptr ;
131+ }
132+
133+ auto newPoint = point - frame.origin ;
134+ for (const auto &childShadowNode : node->getChildren ()) {
135+ auto hitView = findNodeAtPoint (childShadowNode, newPoint);
136+ if (hitView) {
137+ return hitView;
138+ }
139+ }
140+ return isPointInside ? node : nullptr ;
141+ }
142+
117143void LayoutableShadowNode::layoutChildren (LayoutContext layoutContext) {
118144 // Default implementation does nothing.
119145}
Original file line number Diff line number Diff line change 1717#include < react/core/Sealable.h>
1818#include < react/core/ShadowNode.h>
1919#include < react/debug/DebugStringConvertible.h>
20+ #include < react/graphics/Geometry.h>
2021#include < react/graphics/Transform.h>
2122
2223namespace facebook {
@@ -86,6 +87,14 @@ class LayoutableShadowNode : public virtual Sealable {
8687 LayoutableShadowNode const &ancestorLayoutableShadowNode,
8788 LayoutInspectingPolicy policy) const ;
8889
90+ /*
91+ * Returns the ShadowNode that is rendered at the Point received as a
92+ * parameter.
93+ */
94+ static ShadowNode::Shared findNodeAtPoint (
95+ ShadowNode::Shared node,
96+ Point point);
97+
8998 protected:
9099 /*
91100 * Clean or Dirty layout state:
Original file line number Diff line number Diff line change 99
1010#include < react/core/ShadowNodeFragment.h>
1111#include < react/debug/SystraceSection.h>
12+ #include < react/graphics/Geometry.h>
1213
1314#include < glog/logging.h>
1415
@@ -134,6 +135,12 @@ void UIManager::clearJSResponder() const {
134135 }
135136}
136137
138+ ShadowNode::Shared UIManager::findNodeAtPoint (
139+ const ShadowNode::Shared &node,
140+ Point point) const {
141+ return LayoutableShadowNode::findNodeAtPoint (node, point);
142+ }
143+
137144void UIManager::setNativeProps (
138145 ShadowNode const &shadowNode,
139146 RawProps const &rawProps) const {
Original file line number Diff line number Diff line change @@ -88,6 +88,10 @@ class UIManager final : public ShadowTreeDelegate {
8888
8989 void clearJSResponder () const ;
9090
91+ ShadowNode::Shared findNodeAtPoint (
92+ const ShadowNode::Shared &shadowNode,
93+ Point point) const ;
94+
9195 /*
9296 * Returns layout metrics of given `shadowNode` relative to
9397 * `ancestorShadowNode` (relative to the root node in case if provided
You can’t perform that action at this time.
0 commit comments