Skip to content

Commit

Permalink
surface setup issues in EventBeat and Scheduler (facebook#47253)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#47253

changelog: [internal]

Add assert statements to make sure EventBeat and Scheduler classes are correctly setup.

Scheduler must receive RuntimeScheduler through ContextContainer.
Callers of EventBeat must set beatCallback before calling request.

Reviewed By: javache

Differential Revision: D65001802

fbshipit-source-id: 5e044e1e6b0249bc89c11cccd51801add2e85b88
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 28, 2024
1 parent 3111473 commit 92d743a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "EventBeat.h"

#include <react/debug/react_native_assert.h>
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
#include <utility>

Expand All @@ -18,6 +19,9 @@ EventBeat::EventBeat(
: ownerBox_(std::move(ownerBox)), runtimeScheduler_(runtimeScheduler) {}

void EventBeat::request() const {
react_native_assert(
beatCallback_ &&
"Unexpected state: EventBeat::setBeatCallback was not called before EventBeat::request.");
isRequested_ = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ Scheduler::Scheduler(
auto weakRuntimeScheduler =
contextContainer_->find<std::weak_ptr<RuntimeScheduler>>(
"RuntimeScheduler");
auto runtimeScheduler = weakRuntimeScheduler.has_value()
? weakRuntimeScheduler.value().lock()
: nullptr;
react_native_assert(
weakRuntimeScheduler.has_value() &&
"Unexpected state: RuntimeScheduler was not provided.");

auto runtimeScheduler = weakRuntimeScheduler.value().lock();

if (runtimeScheduler && ReactNativeFeatureFlags::enableUIConsistency()) {
if (ReactNativeFeatureFlags::enableUIConsistency()) {
runtimeScheduler->setShadowTreeRevisionConsistencyManager(
uiManager->getShadowTreeRevisionConsistencyManager());
}

if (runtimeScheduler &&
ReactNativeFeatureFlags::enableReportEventPaintTime()) {
if (ReactNativeFeatureFlags::enableReportEventPaintTime()) {
runtimeScheduler->setEventTimingDelegate(eventPerformanceLogger_.get());
}

Expand Down

0 comments on commit 92d743a

Please sign in to comment.