Skip to content

Commit

Permalink
Fabric: Dispatching onLayout events to only nodes which requested it
Browse files Browse the repository at this point in the history
Summary:
@public
The current Fabric architecture, in general, does not support "subscribing" for events, so all kinds of events are always delivered no matter have JavaScript components `on`-handlers for them or not.
At this point, we are not sure should it be this way or not. But we are sure that for some extremely noisy events (like onLayout) we have to make an exception right now (otherwise overall performance will suffer).
So, this diff implements that for `onLayout`.

Reviewed By: fkgozali

Differential Revision: D8597408

fbshipit-source-id: 6933b7cb96e24f0660bd7850b625ff27e3146a2b
  • Loading branch information
shergin authored and facebook-github-bot committed Jun 23, 2018
1 parent 250cc3c commit 6942408
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ReactCommon/fabric/uimanager/ShadowTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ void ShadowTree::emitLayoutEvents(const TreeMutationInstructionList &instruction
if (viewEventEmitter) {
// Now we know that both (old and new) shadow nodes must be `LayoutableShadowNode` subclasses.
assert(std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode));

// Checking if the `onLayout` event was requested for the particular Shadow Node.
const auto &viewProps = std::dynamic_pointer_cast<const ViewProps>(newShadowNode->getProps());
if (viewProps && !viewProps->onLayout) {
continue;
}

// TODO(T29661055): Consider using `std::reinterpret_pointer_cast`.
const auto &newLayoutableShadowNode =
std::dynamic_pointer_cast<const LayoutableShadowNode>(newShadowNode);
Expand Down
3 changes: 2 additions & 1 deletion ReactCommon/fabric/view/ViewProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ ViewProps::ViewProps(const ViewProps &sourceProps, const RawProps &rawProps):
shouldRasterize(convertRawProp(rawProps, "shouldRasterize", sourceProps.shouldRasterize)),
zIndex(convertRawProp(rawProps, "zIndex", sourceProps.zIndex)),
pointerEvents(convertRawProp(rawProps, "pointerEvents", sourceProps.pointerEvents)),
hitSlop(convertRawProp(rawProps, "hitSlop", sourceProps.hitSlop)) {};
hitSlop(convertRawProp(rawProps, "hitSlop", sourceProps.hitSlop)),
onLayout(convertRawProp(rawProps, "onLayout", sourceProps.onLayout)) {};

#pragma mark - DebugStringConvertible

Expand Down
1 change: 1 addition & 0 deletions ReactCommon/fabric/view/ViewProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ViewProps:
// Events
const PointerEventsMode pointerEvents {};
const EdgeInsets hitSlop {};
const bool onLayout {false};

#pragma mark - DebugStringConvertible

Expand Down

0 comments on commit 6942408

Please sign in to comment.