Skip to content

Commit

Permalink
Revert rollback of "Simplify root node lookups" (#10840)
Browse files Browse the repository at this point in the history
In #10797, #10689 was rolled back due to a build break that emerged due
to a conflicting new API surface on XamlUIService. This brings back the
original code in #10689 and fixes the build break.
  • Loading branch information
rozele committed Nov 8, 2022
1 parent ab44fb4 commit 2ca512a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Simplify root node lookups",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
1 change: 0 additions & 1 deletion vnext/Microsoft.ReactNative/INativeUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct INativeUIManagerHost {
virtual std::unordered_set<int64_t> &GetAllRootTags() = 0;
virtual ShadowNode &GetShadowNodeForTag(int64_t tag) = 0;
virtual ShadowNode *FindShadowNodeForTag(int64_t tag) = 0;
virtual ShadowNode *FindParentRootShadowNode(int64_t tag) = 0;
};

struct INativeUIManager {
Expand Down
4 changes: 2 additions & 2 deletions vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,8 @@ void NativeUIManager::blur(int64_t reactTag) {
// m_tagsToXamlReactControl to get the IXamlReactControl
winrt::weak_ref<winrt::Microsoft::ReactNative::ReactRootView> NativeUIManager::GetParentXamlReactControl(
int64_t tag) const {
if (auto shadowNode = static_cast<ShadowNodeBase *>(m_host->FindParentRootShadowNode(tag))) {
auto it = m_tagsToXamlReactControl.find(shadowNode->m_tag);
if (auto shadowNode = m_host->FindShadowNodeForTag(tag)) {
auto it = m_tagsToXamlReactControl.find(shadowNode->m_rootTag);
if (it != m_tagsToXamlReactControl.end()) {
return it->second;
}
Expand Down
19 changes: 1 addition & 18 deletions vnext/Microsoft.ReactNative/Modules/PaperUIManagerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,7 @@ class UIManagerModule : public std::enable_shared_from_this<UIManagerModule>, pu
std::function<void(double left, double top, double width, double height, double pageX, double pageY)>
&&callback) noexcept {
if (auto node = m_nodeRegistry.findNode(reactTag)) {
int64_t rootTag = reactTag;
while (true) {
if (auto currNode = m_nodeRegistry.findNode(rootTag)) {
if (currNode->m_parent == -1) {
break;
}
rootTag = currNode->m_parent;
} else {
callback(0, 0, 0, 0, 0, 0);
return;
}
}
auto &rootNode = m_nodeRegistry.getNode(rootTag);

auto &rootNode = m_nodeRegistry.getNode(node->m_rootTag);
m_nativeUIManager->measure(*node, rootNode, std::move(callback));
}
}
Expand Down Expand Up @@ -384,10 +371,6 @@ class UIManagerModule : public std::enable_shared_from_this<UIManagerModule>, pu
return m_nodeRegistry.findNode(tag);
}

ShadowNode *FindParentRootShadowNode(int64_t tag) {
return m_nodeRegistry.getParentRootShadowNode(tag);
}

ShadowNode &GetShadowNodeForTag(int64_t tag) {
return m_nodeRegistry.getNode(tag);
}
Expand Down
12 changes: 0 additions & 12 deletions vnext/Microsoft.ReactNative/Views/ShadowNodeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ std::unordered_set<int64_t> &ShadowNodeRegistry::getAllRoots() {
return m_roots;
}

// iterate its parent to get the root shadow node
ShadowNode *ShadowNodeRegistry::getParentRootShadowNode(int64_t nodeTag) {
auto node = findNode(nodeTag);
while (node) {
if (m_roots.find(node->m_tag) != m_roots.end()) {
return node;
}
node = findNode(node->m_parent);
}
return nullptr;
}

void ShadowNodeRegistry::ForAllNodes(const Mso::FunctorRef<void(int64_t, shadow_ptr const &) noexcept> &fnDo) noexcept {
for (auto &kvp : m_allNodes) {
fnDo(kvp.first, kvp.second);
Expand Down
2 changes: 0 additions & 2 deletions vnext/Microsoft.ReactNative/Views/ShadowNodeRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct ShadowNodeRegistry {

std::unordered_set<int64_t> &getAllRoots();

ShadowNode *getParentRootShadowNode(int64_t nodeTag);

void ForAllNodes(const Mso::FunctorRef<void(int64_t, shadow_ptr const &) noexcept> &fnDo) noexcept;

private:
Expand Down
14 changes: 7 additions & 7 deletions vnext/Microsoft.ReactNative/XamlUIService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ winrt::Microsoft::ReactNative::ReactRootView XamlUIService::GetReactRootView(
xaml::FrameworkElement const &view) noexcept {
if (auto uiManager = ::Microsoft::ReactNative::GetNativeUIManager(*m_context).lock()) {
const auto reactTag = ::Microsoft::ReactNative::GetTag(view);
auto shadowNode = uiManager->getHost()->FindParentRootShadowNode(reactTag);
if (!shadowNode)
return nullptr;

return static_cast<::Microsoft::ReactNative::ShadowNodeBase *>(shadowNode)
->GetView()
.as<winrt::Microsoft::ReactNative::ReactRootView>();
if (auto shadowNode = static_cast<::Microsoft::ReactNative::ShadowNodeBase *>(
uiManager->getHost()->FindShadowNodeForTag(reactTag))) {
if (auto rootNode = static_cast<::Microsoft::ReactNative::ShadowNodeBase *>(
uiManager->getHost()->FindShadowNodeForTag(shadowNode->m_rootTag))) {
return rootNode->GetView().as<winrt::Microsoft::ReactNative::ReactRootView>();
}
}
}
return nullptr;
}
Expand Down

0 comments on commit 2ca512a

Please sign in to comment.