diff --git a/React/Fabric/RCTScheduler.mm b/React/Fabric/RCTScheduler.mm index 5d275b2d993..bac276ca040 100644 --- a/React/Fabric/RCTScheduler.mm +++ b/React/Fabric/RCTScheduler.mm @@ -156,8 +156,10 @@ class LayoutAnimationDelegateProxy : public LayoutAnimationStatusDelegate, publi SystraceSection s("-[RCTScheduler startSurfaceWithSurfaceId:...]"); auto props = convertIdToFollyDynamic(initialProps); - _scheduler->startSurface( - surfaceId, RCTStringFromNSString(moduleName), props, layoutConstraints, layoutContext, _animationDriver); + _scheduler->startSurface(surfaceId, RCTStringFromNSString(moduleName), props, layoutConstraints, layoutContext); + + _scheduler->findMountingCoordinator(surfaceId)->setMountingOverrideDelegate(_animationDriver); + _scheduler->renderTemplateToSurface( surfaceId, props.getDefault("navigationConfig").getDefault("initialUITemplate", "").getString()); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp index 3cb4afdd5da..181250e0cd9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp @@ -255,7 +255,9 @@ void Binding::startSurface( moduleName->toStdString(), initialProps->consume(), {}, - context, + context); + + scheduler->findMountingCoordinator(surfaceId)->setMountingOverrideDelegate( animationDriver_); } @@ -306,7 +308,9 @@ void Binding::startSurfaceWithConstraints( moduleName->toStdString(), initialProps->consume(), constraints, - context, + context); + + scheduler->findMountingCoordinator(surfaceId)->setMountingOverrideDelegate( animationDriver_); } diff --git a/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp b/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp index 85dc2aec5e5..d753a43ba93 100644 --- a/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp +++ b/ReactCommon/react/renderer/mounting/MountingCoordinator.cpp @@ -19,12 +19,9 @@ namespace facebook { namespace react { -MountingCoordinator::MountingCoordinator( - ShadowTreeRevision baseRevision, - std::weak_ptr delegate) +MountingCoordinator::MountingCoordinator(ShadowTreeRevision baseRevision) : surfaceId_(baseRevision.rootShadowNode->getSurfaceId()), baseRevision_(baseRevision), - mountingOverrideDelegate_(delegate), telemetryController_(*this) { #ifdef RN_SHADOW_TREE_INTROSPECTION stubViewTree_ = buildStubViewTreeWithoutUsingDifferentiator( @@ -181,5 +178,11 @@ TelemetryController const &MountingCoordinator::getTelemetryController() const { return telemetryController_; } +void MountingCoordinator::setMountingOverrideDelegate( + std::weak_ptr delegate) const { + std::lock_guard lock(mutex_); + mountingOverrideDelegate_ = delegate; +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/react/renderer/mounting/MountingCoordinator.h b/ReactCommon/react/renderer/mounting/MountingCoordinator.h index 8d9aace9a86..9356126ed4e 100644 --- a/ReactCommon/react/renderer/mounting/MountingCoordinator.h +++ b/ReactCommon/react/renderer/mounting/MountingCoordinator.h @@ -43,9 +43,7 @@ class MountingCoordinator final { * The constructor is meant to be used only inside `ShadowTree`, and it's * `public` only to enable using with `std::make_shared<>`. */ - MountingCoordinator( - ShadowTreeRevision baseRevision, - std::weak_ptr delegate); + MountingCoordinator(ShadowTreeRevision baseRevision); /* * Returns the id of the surface that the coordinator belongs to. @@ -84,6 +82,9 @@ class MountingCoordinator final { void updateBaseRevision(ShadowTreeRevision const &baseRevision) const; void resetLatestRevision() const; + void setMountingOverrideDelegate( + std::weak_ptr delegate) const; + /* * Methods from this section are meant to be used by `ShadowTree` only. */ @@ -109,7 +110,8 @@ class MountingCoordinator final { mutable better::optional lastRevision_{}; mutable MountingTransaction::Number number_{0}; mutable std::condition_variable signal_; - std::weak_ptr mountingOverrideDelegate_; + mutable std::weak_ptr + mountingOverrideDelegate_; TelemetryController telemetryController_; diff --git a/ReactCommon/react/renderer/mounting/ShadowTree.cpp b/ReactCommon/react/renderer/mounting/ShadowTree.cpp index cd077e8c56d..88e3f3a8b3b 100644 --- a/ReactCommon/react/renderer/mounting/ShadowTree.cpp +++ b/ReactCommon/react/renderer/mounting/ShadowTree.cpp @@ -222,8 +222,7 @@ ShadowTree::ShadowTree( SurfaceId surfaceId, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext, - ShadowTreeDelegate const &delegate, - std::weak_ptr mountingOverrideDelegate) + ShadowTreeDelegate const &delegate) : surfaceId_(surfaceId), delegate_(delegate) { const auto noopEventEmitter = std::make_shared( nullptr, -1, std::shared_ptr()); @@ -250,8 +249,8 @@ ShadowTree::ShadowTree( currentRevision_ = ShadowTreeRevision{ rootShadowNode, ShadowTreeRevision::Number{0}, TransactionTelemetry{}}; - mountingCoordinator_ = std::make_shared( - currentRevision_, mountingOverrideDelegate); + mountingCoordinator_ = + std::make_shared(currentRevision_); } ShadowTree::~ShadowTree() { diff --git a/ReactCommon/react/renderer/mounting/ShadowTree.h b/ReactCommon/react/renderer/mounting/ShadowTree.h index 1bfd4b9339c..8dd6dff7428 100644 --- a/ReactCommon/react/renderer/mounting/ShadowTree.h +++ b/ReactCommon/react/renderer/mounting/ShadowTree.h @@ -67,8 +67,7 @@ class ShadowTree final { SurfaceId surfaceId, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext, - ShadowTreeDelegate const &delegate, - std::weak_ptr mountingOverrideDelegate); + ShadowTreeDelegate const &delegate); ~ShadowTree(); diff --git a/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp b/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp index 92709cb2435..2b6ccfe7f1d 100644 --- a/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp +++ b/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp @@ -95,11 +95,7 @@ TEST(StateReconciliationTest, testStateReconciliation) { auto state1 = shadowNodeAB->getState(); auto shadowTreeDelegate = DummyShadowTreeDelegate{}; ShadowTree shadowTree{ - SurfaceId{11}, - LayoutConstraints{}, - LayoutContext{}, - shadowTreeDelegate, - {}}; + SurfaceId{11}, LayoutConstraints{}, LayoutContext{}, shadowTreeDelegate}; shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) { diff --git a/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/ReactCommon/react/renderer/scheduler/Scheduler.cpp index ab9ea1f0f99..72ee9a457fc 100644 --- a/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -176,17 +176,11 @@ void Scheduler::startSurface( const std::string &moduleName, const folly::dynamic &initialProps, const LayoutConstraints &layoutConstraints, - const LayoutContext &layoutContext, - std::weak_ptr mountingOverrideDelegate) - const { + const LayoutContext &layoutContext) const { SystraceSection s("Scheduler::startSurface"); auto shadowTree = std::make_unique( - surfaceId, - layoutConstraints, - layoutContext, - *uiManager_, - mountingOverrideDelegate); + surfaceId, layoutConstraints, layoutContext, *uiManager_); auto uiManager = uiManager_; diff --git a/ReactCommon/react/renderer/scheduler/Scheduler.h b/ReactCommon/react/renderer/scheduler/Scheduler.h index b213d640c07..2d31b39ef19 100644 --- a/ReactCommon/react/renderer/scheduler/Scheduler.h +++ b/ReactCommon/react/renderer/scheduler/Scheduler.h @@ -45,9 +45,7 @@ class Scheduler final : public UIManagerDelegate { const std::string &moduleName, const folly::dynamic &initialProps, const LayoutConstraints &layoutConstraints = {}, - const LayoutContext &layoutContext = {}, - std::weak_ptr mountingOverrideDelegate = - {}) const; + const LayoutContext &layoutContext = {}) const; void renderTemplateToSurface( SurfaceId surfaceId,