File tree Expand file tree Collapse file tree
packages/react-native/ReactCommon/react/renderer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -336,6 +336,13 @@ void Scheduler::uiManagerShouldRemoveEventListener(
336336 removeEventListener (listener);
337337}
338338
339+ void Scheduler::uiManagerDidStartSurface (const ShadowTree& shadowTree) {
340+ std::shared_lock lock (onSurfaceStartCallbackMutex_);
341+ if (onSurfaceStartCallback_) {
342+ onSurfaceStartCallback_ (shadowTree);
343+ }
344+ }
345+
339346void Scheduler::reportMount (SurfaceId surfaceId) const {
340347 uiManager_->reportMount (surfaceId);
341348}
@@ -362,4 +369,10 @@ void Scheduler::removeEventListener(
362369 }
363370}
364371
372+ void Scheduler::uiManagerShouldSetOnSurfaceStartCallback (
373+ OnSurfaceStartCallback&& callback) {
374+ std::shared_lock lock (onSurfaceStartCallbackMutex_);
375+ onSurfaceStartCallback_ = std::move (callback);
376+ }
377+
365378} // namespace facebook::react
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ class Scheduler final : public UIManagerDelegate {
101101 std::shared_ptr<const EventListener> listener) final ;
102102 void uiManagerShouldRemoveEventListener (
103103 const std::shared_ptr<const EventListener>& listener) final ;
104+ void uiManagerDidStartSurface (const ShadowTree& shadowTree) override ;
104105
105106#pragma mark - ContextContainer
106107 ContextContainer::Shared getContextContainer () const ;
@@ -115,6 +116,10 @@ class Scheduler final : public UIManagerDelegate {
115116 void removeEventListener (
116117 const std::shared_ptr<const EventListener>& listener);
117118
119+ #pragma mark - Surface start callback
120+ void uiManagerShouldSetOnSurfaceStartCallback (
121+ OnSurfaceStartCallback&& callback) override ;
122+
118123 private:
119124 friend class SurfaceHandler ;
120125
@@ -144,6 +149,9 @@ class Scheduler final : public UIManagerDelegate {
144149 ContextContainer::Shared contextContainer_;
145150
146151 RuntimeScheduler* runtimeScheduler_{nullptr };
152+
153+ mutable std::shared_mutex onSurfaceStartCallbackMutex_;
154+ OnSurfaceStartCallback onSurfaceStartCallback_;
147155};
148156
149157} // namespace facebook::react
Original file line number Diff line number Diff line change @@ -227,6 +227,13 @@ void UIManager::startSurface(
227227 auto surfaceId = shadowTree->getSurfaceId ();
228228 shadowTreeRegistry_.add (std::move (shadowTree));
229229
230+ shadowTreeRegistry_.visit (
231+ surfaceId, [delegate = delegate_](const ShadowTree& shadowTree) {
232+ if (delegate != nullptr ) {
233+ delegate->uiManagerDidStartSurface (shadowTree);
234+ }
235+ });
236+
230237 runtimeExecutor_ ([=](jsi::Runtime& runtime) {
231238 TraceSection s (" UIManager::startSurface::onRuntime" );
232239 AppRegistryBinding::startSurface (
@@ -706,4 +713,11 @@ void UIManager::removeEventListener(
706713 }
707714}
708715
716+ void UIManager::setOnSurfaceStartCallback (
717+ UIManagerDelegate::OnSurfaceStartCallback&& callback) {
718+ if (delegate_ != nullptr ) {
719+ delegate_->uiManagerShouldSetOnSurfaceStartCallback (std::move (callback));
720+ }
721+ }
722+
709723} // namespace facebook::react
Original file line number Diff line number Diff line change @@ -216,6 +216,10 @@ class UIManager final : public ShadowTreeDelegate {
216216 void removeEventListener (
217217 const std::shared_ptr<const EventListener>& listener);
218218
219+ #pragma mark - Set on surface start callback
220+ void setOnSurfaceStartCallback (
221+ UIManagerDelegate::OnSurfaceStartCallback&& callback);
222+
219223 private:
220224 friend class UIManagerBinding ;
221225 friend class Scheduler ;
Original file line number Diff line number Diff line change 1010#include < react/renderer/core/ReactPrimitives.h>
1111#include < react/renderer/core/ShadowNode.h>
1212#include < react/renderer/mounting/MountingCoordinator.h>
13+ #include < react/renderer/mounting/ShadowTree.h>
1314
1415namespace facebook ::react {
1516
@@ -77,6 +78,16 @@ class UIManagerDelegate {
7778 virtual void uiManagerShouldRemoveEventListener (
7879 const std::shared_ptr<const EventListener>& listener) = 0;
7980
81+ /*
82+ * Start surface.
83+ */
84+ virtual void uiManagerDidStartSurface (const ShadowTree& shadowTree) = 0;
85+
86+ using OnSurfaceStartCallback =
87+ std::function<void (const ShadowTree& shadowTree)>;
88+ virtual void uiManagerShouldSetOnSurfaceStartCallback (
89+ OnSurfaceStartCallback&& callback) = 0;
90+
8091 virtual ~UIManagerDelegate () noexcept = default ;
8192};
8293
You can’t perform that action at this time.
0 commit comments