Skip to content

Commit

Permalink
Fabric: UIManager::getRelativeLayoutMetrics
Browse files Browse the repository at this point in the history
Summary: This method is underlying infra for all `measure`-like methods exposed to JavaScript.

Reviewed By: mdvacca

Differential Revision: D13036553

fbshipit-source-id: cb5135f1db97ec8144b31a24ee4fb9f5d61f0df1
  • Loading branch information
shergin authored and facebook-github-bot committed Nov 22, 2018
1 parent f8be867 commit 7e57755
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ReactCommon/fabric/uimanager/ShadowTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class ShadowTree final {
*/
bool complete(const SharedShadowNodeUnsharedList &rootChildNodes) const;

/*
* Returns a root shadow node that represents the last committed three.
*/
SharedRootShadowNode getRootShadowNode() const;

#pragma mark - Delegate

/*
Expand Down Expand Up @@ -105,11 +110,6 @@ class ShadowTree final {
void toggleEventEmitters(const ShadowViewMutationList &mutations) const;
void emitLayoutEvents(const ShadowViewMutationList &mutations) const;

/*
* Return `rootShadowNodeMutex_` protected by `commitMutex_`.
*/
SharedRootShadowNode getRootShadowNode() const;

const SurfaceId surfaceId_;
mutable SharedRootShadowNode rootShadowNode_; // Protected by `commitMutex_`.
ShadowTreeDelegate const *delegate_;
Expand Down
23 changes: 23 additions & 0 deletions ReactCommon/fabric/uimanager/UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ void UIManager::completeSurface(
}
}

LayoutMetrics UIManager::getRelativeLayoutMetrics(
const ShadowNode &shadowNode,
const ShadowNode *ancestorShadowNode) const {
if (!ancestorShadowNode) {
shadowTreeRegistry_->get(
shadowNode.getRootTag(), [&](const ShadowTree &shadowTree) {
ancestorShadowNode = shadowTree.getRootShadowNode().get();
});
}

auto layoutableShadowNode =
dynamic_cast<const LayoutableShadowNode *>(&shadowNode);
auto layoutableAncestorShadowNode =
dynamic_cast<const LayoutableShadowNode *>(ancestorShadowNode);

if (!layoutableShadowNode || !layoutableAncestorShadowNode) {
return EmptyLayoutMetrics;
}

return layoutableShadowNode->getRelativeLayoutMetrics(
*layoutableAncestorShadowNode);
}

void UIManager::setShadowTreeRegistry(ShadowTreeRegistry *shadowTreeRegistry) {
shadowTreeRegistry_ = shadowTreeRegistry;
}
Expand Down
9 changes: 9 additions & 0 deletions ReactCommon/fabric/uimanager/UIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ class UIManager {
SurfaceId surfaceId,
const SharedShadowNodeUnsharedList &rootChildren) const;

/*
* Returns layout metrics of given `shadowNode` relative to
* `ancestorShadowNode` (relative to the root node in case if provided
* `ancestorShadowNode` is nullptr).
*/
LayoutMetrics getRelativeLayoutMetrics(
const ShadowNode &shadowNode,
const ShadowNode *ancestorShadowNode) const;

ShadowTreeRegistry *shadowTreeRegistry_;
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
UIManagerDelegate *delegate_;
Expand Down

0 comments on commit 7e57755

Please sign in to comment.