Skip to content

Commit 0dbe6f1

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
clean up interfaces for view preallocation (facebook#44232)
Summary: Pull Request resolved: facebook#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
1 parent 42ceacd commit 0dbe6f1

File tree

9 files changed

+21
-28
lines changed

9 files changed

+21
-28
lines changed

packages/react-native/React/Fabric/RCTScheduler.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void schedulerShouldRenderTransactions(const MountingCoordinator::Shared &mounti
3737
[scheduler.delegate schedulerShouldRenderTransactions:mountingCoordinator];
3838
}
3939

40-
void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, const ShadowNode &shadowNode) override
40+
void schedulerDidRequestPreliminaryViewAllocation(const ShadowNode &shadowNode) override
4141
{
4242
// Does nothing.
4343
// This delegate method is not currently used on iOS.

packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
#include "FabricMountingManager.h"
1515
#include "JBackgroundExecutor.h"
1616
#include "ReactNativeConfigHolder.h"
17-
#include "StateWrapperImpl.h"
1817
#include "SurfaceHandlerBinding.h"
1918

20-
#include <cfenv>
21-
#include <cmath>
22-
2319
#include <fbjni/fbjni.h>
2420
#include <glog/logging.h>
2521
#include <jsi/JSIDynamic.h>
@@ -510,7 +506,6 @@ void Binding::schedulerShouldRenderTransactions(
510506
}
511507

512508
void Binding::schedulerDidRequestPreliminaryViewAllocation(
513-
const SurfaceId surfaceId,
514509
const ShadowNode& shadowNode) {
515510
if (!shadowNode.getTraits().check(ShadowNodeTraits::Trait::FormsView)) {
516511
return;
@@ -520,7 +515,7 @@ void Binding::schedulerDidRequestPreliminaryViewAllocation(
520515
if (!mountingManager) {
521516
return;
522517
}
523-
mountingManager->preallocateShadowView(surfaceId, ShadowView(shadowNode));
518+
mountingManager->preallocateShadowView(shadowNode);
524519
}
525520

526521
void Binding::schedulerDidRequestUpdateToPreallocatedView(

packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class Binding : public jni::HybridClass<Binding, JBinding>,
106106
const MountingCoordinator::Shared& mountingCoordinator) override;
107107

108108
void schedulerDidRequestPreliminaryViewAllocation(
109-
const SurfaceId surfaceId,
110109
const ShadowNode& shadowNode) override;
111110

112111
void schedulerDidRequestUpdateToPreallocatedView(

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,21 +776,23 @@ void FabricMountingManager::executeMount(
776776
}
777777

778778
void FabricMountingManager::preallocateShadowView(
779-
SurfaceId surfaceId,
780-
const ShadowView& shadowView) {
779+
const ShadowNode& shadowNode) {
781780
{
782781
std::lock_guard lock(allocatedViewsMutex_);
783-
auto allocatedViewsIterator = allocatedViewRegistry_.find(surfaceId);
782+
auto allocatedViewsIterator =
783+
allocatedViewRegistry_.find(shadowNode.getSurfaceId());
784784
if (allocatedViewsIterator == allocatedViewRegistry_.end()) {
785785
return;
786786
}
787787
auto& allocatedViews = allocatedViewsIterator->second;
788-
if (allocatedViews.find(shadowView.tag) != allocatedViews.end()) {
788+
if (allocatedViews.find(shadowNode.getTag()) != allocatedViews.end()) {
789789
return;
790790
}
791-
allocatedViews.insert(shadowView.tag);
791+
allocatedViews.insert(shadowNode.getTag());
792792
}
793793

794+
auto shadowView = ShadowView(shadowNode);
795+
794796
bool isLayoutableShadowNode = shadowView.layoutMetrics != EmptyLayoutMetrics;
795797

796798
static auto preallocateView =
@@ -818,7 +820,7 @@ void FabricMountingManager::preallocateShadowView(
818820

819821
preallocateView(
820822
javaUIManager_,
821-
surfaceId,
823+
shadowNode.getSurfaceId(),
822824
shadowView.tag,
823825
component.get(),
824826
props.get(),

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FabricMountingManager final {
3232

3333
void onSurfaceStop(SurfaceId surfaceId);
3434

35-
void preallocateShadowView(SurfaceId surfaceId, const ShadowView& shadowView);
35+
void preallocateShadowView(const ShadowNode& shadowNode);
3636
void updatePreallocatedShadowNode(const ShadowNode& shadowNode);
3737

3838
void executeMount(const MountingTransaction& transaction);

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ void Scheduler::uiManagerDidCreateShadowNode(const ShadowNode& shadowNode) {
317317
SystraceSection s("Scheduler::uiManagerDidCreateShadowNode");
318318

319319
if (delegate_ != nullptr) {
320-
delegate_->schedulerDidRequestPreliminaryViewAllocation(
321-
shadowNode.getSurfaceId(), shadowNode);
320+
delegate_->schedulerDidRequestPreliminaryViewAllocation(shadowNode);
322321
}
323322
}
324323

packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class SchedulerDelegate {
4343
* Called right after a new ShadowNode was created.
4444
*/
4545
virtual void schedulerDidRequestPreliminaryViewAllocation(
46-
SurfaceId surfaceId,
47-
const ShadowNode& shadowView) = 0;
46+
const ShadowNode& shadowNode) = 0;
4847

4948
/*
5049
* Called after shadow node is cloned with new props.

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,16 @@ std::shared_ptr<ShadowNode> UIManager::createNode(
8989

9090
auto shadowNode = componentDescriptor.createShadowNode(
9191
ShadowNodeFragment{
92-
/* .props = */
93-
fallbackDescriptor != nullptr &&
92+
.props = fallbackDescriptor != nullptr &&
9493
fallbackDescriptor->getComponentHandle() ==
9594
componentDescriptor.getComponentHandle()
9695
? componentDescriptor.cloneProps(
9796
propsParserContext,
9897
props,
9998
RawProps(folly::dynamic::object("name", name)))
10099
: props,
101-
/* .children = */ ShadowNodeFragment::childrenPlaceholder(),
102-
/* .state = */ state,
100+
.children = ShadowNodeFragment::childrenPlaceholder(),
101+
.state = state,
103102
},
104103
family);
105104

@@ -152,8 +151,8 @@ std::shared_ptr<ShadowNode> UIManager::cloneNode(
152151
auto clonedShadowNode = componentDescriptor.cloneShadowNode(
153152
shadowNode,
154153
{
155-
/* .props = */ props,
156-
/* .children = */ children,
154+
.props = props,
155+
.children = children,
157156
});
158157

159158
if (!rawProps.isEmpty() && delegate_ != nullptr) {

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ jsi::Value UIManagerBinding::get(
527527
strongUIManager->completeSurface(
528528
surfaceId,
529529
shadowNodeList,
530-
{/* .enableStateReconciliation = */ true,
531-
/* .mountSynchronously = */ false,
532-
/* .shouldYield = */ shouldYield});
530+
{.enableStateReconciliation = true,
531+
.mountSynchronously = false,
532+
.shouldYield = shouldYield});
533533
}
534534
});
535535
} else {

0 commit comments

Comments
 (0)