clean up interfaces for view preallocation (#44232)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44232

changelog: [internal]

surfaceId parameter is not needed `schedulerDidRequestPreliminaryViewAllocation` as it can be derived from shadow node.
Additionally, conversion to ShadowView can happen on the lower layers.

Reviewed By: NickGerleman

Differential Revision: D56350599

fbshipit-source-id: 9c38cc0df36911bbd6927fe0a0d5e64c248d87c4
This commit is contained in:
Samuel Susla
2024-04-25 04:39:08 -07:00
committed by Facebook GitHub Bot
parent 42ceacd281
commit 0dbe6f10c1
9 changed files with 21 additions and 28 deletions
@@ -37,7 +37,7 @@ class SchedulerDelegateProxy : public SchedulerDelegate {
[scheduler.delegate schedulerShouldRenderTransactions:mountingCoordinator];
}
void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, const ShadowNode &shadowNode) override
void schedulerDidRequestPreliminaryViewAllocation(const ShadowNode &shadowNode) override
{
// Does nothing.
// This delegate method is not currently used on iOS.
@@ -14,12 +14,8 @@
#include "FabricMountingManager.h"
#include "JBackgroundExecutor.h"
#include "ReactNativeConfigHolder.h"
#include "StateWrapperImpl.h"
#include "SurfaceHandlerBinding.h"
#include <cfenv>
#include <cmath>
#include <fbjni/fbjni.h>
#include <glog/logging.h>
#include <jsi/JSIDynamic.h>
@@ -510,7 +506,6 @@ void Binding::schedulerShouldRenderTransactions(
}
void Binding::schedulerDidRequestPreliminaryViewAllocation(
const SurfaceId surfaceId,
const ShadowNode& shadowNode) {
if (!shadowNode.getTraits().check(ShadowNodeTraits::Trait::FormsView)) {
return;
@@ -520,7 +515,7 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation(
if (!mountingManager) {
return;
}
mountingManager->preallocateShadowView(surfaceId, ShadowView(shadowNode));
mountingManager->preallocateShadowView(shadowNode);
}
void Binding::schedulerDidRequestUpdateToPreallocatedView(
@@ -106,7 +106,6 @@ class Binding : public jni::HybridClass<Binding, JBinding>,
const MountingCoordinator::Shared& mountingCoordinator) override;
void schedulerDidRequestPreliminaryViewAllocation(
const SurfaceId surfaceId,
const ShadowNode& shadowNode) override;
void schedulerDidRequestUpdateToPreallocatedView(
@@ -776,21 +776,23 @@ void FabricMountingManager::executeMount(
}
void FabricMountingManager::preallocateShadowView(
SurfaceId surfaceId,
const ShadowView& shadowView) {
const ShadowNode& shadowNode) {
{
std::lock_guard lock(allocatedViewsMutex_);
auto allocatedViewsIterator = allocatedViewRegistry_.find(surfaceId);
auto allocatedViewsIterator =
allocatedViewRegistry_.find(shadowNode.getSurfaceId());
if (allocatedViewsIterator == allocatedViewRegistry_.end()) {
return;
}
auto& allocatedViews = allocatedViewsIterator->second;
if (allocatedViews.find(shadowView.tag) != allocatedViews.end()) {
if (allocatedViews.find(shadowNode.getTag()) != allocatedViews.end()) {
return;
}
allocatedViews.insert(shadowView.tag);
allocatedViews.insert(shadowNode.getTag());
}
auto shadowView = ShadowView(shadowNode);
bool isLayoutableShadowNode = shadowView.layoutMetrics != EmptyLayoutMetrics;
static auto preallocateView =
@@ -818,7 +820,7 @@ void FabricMountingManager::preallocateShadowView(
preallocateView(
javaUIManager_,
surfaceId,
shadowNode.getSurfaceId(),
shadowView.tag,
component.get(),
props.get(),
@@ -32,7 +32,7 @@ class FabricMountingManager final {
void onSurfaceStop(SurfaceId surfaceId);
void preallocateShadowView(SurfaceId surfaceId, const ShadowView& shadowView);
void preallocateShadowView(const ShadowNode& shadowNode);
void updatePreallocatedShadowNode(const ShadowNode& shadowNode);
void executeMount(const MountingTransaction& transaction);
@@ -317,8 +317,7 @@ void Scheduler::uiManagerDidCreateShadowNode(const ShadowNode& shadowNode) {
SystraceSection s("Scheduler::uiManagerDidCreateShadowNode");
if (delegate_ != nullptr) {
delegate_->schedulerDidRequestPreliminaryViewAllocation(
shadowNode.getSurfaceId(), shadowNode);
delegate_->schedulerDidRequestPreliminaryViewAllocation(shadowNode);
}
}
@@ -43,8 +43,7 @@ class SchedulerDelegate {
* Called right after a new ShadowNode was created.
*/
virtual void schedulerDidRequestPreliminaryViewAllocation(
SurfaceId surfaceId,
const ShadowNode& shadowView) = 0;
const ShadowNode& shadowNode) = 0;
/*
* Called after shadow node is cloned with new props.
@@ -89,8 +89,7 @@ std::shared_ptr<ShadowNode> UIManager::createNode(
auto shadowNode = componentDescriptor.createShadowNode(
ShadowNodeFragment{
/* .props = */
fallbackDescriptor != nullptr &&
.props = fallbackDescriptor != nullptr &&
fallbackDescriptor->getComponentHandle() ==
componentDescriptor.getComponentHandle()
? componentDescriptor.cloneProps(
@@ -98,8 +97,8 @@ std::shared_ptr<ShadowNode> UIManager::createNode(
props,
RawProps(folly::dynamic::object("name", name)))
: props,
/* .children = */ ShadowNodeFragment::childrenPlaceholder(),
/* .state = */ state,
.children = ShadowNodeFragment::childrenPlaceholder(),
.state = state,
},
family);
@@ -152,8 +151,8 @@ std::shared_ptr<ShadowNode> UIManager::cloneNode(
auto clonedShadowNode = componentDescriptor.cloneShadowNode(
shadowNode,
{
/* .props = */ props,
/* .children = */ children,
.props = props,
.children = children,
});
if (!rawProps.isEmpty() && delegate_ != nullptr) {
@@ -527,9 +527,9 @@ jsi::Value UIManagerBinding::get(
strongUIManager->completeSurface(
surfaceId,
shadowNodeList,
{/* .enableStateReconciliation = */ true,
/* .mountSynchronously = */ false,
/* .shouldYield = */ shouldYield});
{.enableStateReconciliation = true,
.mountSynchronously = false,
.shouldYield = shouldYield});
}
});
} else {