diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 5d20142f7a..d1bf8fb3c8 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -32,7 +32,6 @@ #import #import #import -#import #import #import #import @@ -310,18 +309,11 @@ static BackgroundExecutor RCTGetBackgroundExecutor() return std::make_unique(std::move(runLoopObserver), runtimeExecutor, runtimeScheduler); }; - auto enableV2AsynchronousEventBeat = - reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_asynchronous_event_beat_v2_ios"); - - toolbox.asynchronousEventBeatFactory = [runtimeExecutor, enableV2AsynchronousEventBeat]( - EventBeat::SharedOwnerBox const &ownerBox) -> std::unique_ptr { + toolbox.asynchronousEventBeatFactory = + [runtimeExecutor](EventBeat::SharedOwnerBox const &ownerBox) -> std::unique_ptr { auto runLoopObserver = std::make_unique(RunLoopObserver::Activity::BeforeWaiting, ownerBox->owner); - if (enableV2AsynchronousEventBeat) { - return std::make_unique(std::move(runLoopObserver), runtimeExecutor); - } else { - return std::make_unique(std::move(runLoopObserver), runtimeExecutor); - } + return std::make_unique(std::move(runLoopObserver), runtimeExecutor); }; RCTScheduler *scheduler = [[RCTScheduler alloc] initWithToolbox:toolbox]; diff --git a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.cpp b/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.cpp index 4b8cabf43a..e625afe059 100644 --- a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.cpp +++ b/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.cpp @@ -9,8 +9,7 @@ #include -namespace facebook { -namespace react { +namespace facebook::react { AsynchronousEventBeat::AsynchronousEventBeat( RunLoopObserver::Unique uiRunLoopObserver, @@ -24,34 +23,36 @@ AsynchronousEventBeat::AsynchronousEventBeat( void AsynchronousEventBeat::activityDidChange( RunLoopObserver::Delegate const *delegate, - RunLoopObserver::Activity activity) const noexcept { + RunLoopObserver::Activity) const noexcept { react_native_assert(delegate == this); induce(); } void AsynchronousEventBeat::induce() const { - if (!isRequested_) { + if (!isRequested_ || isBeatCallbackScheduled_) { return; } + isRequested_ = false; + // Here we know that `this` object exists because the caller has a strong // pointer to `owner`. To ensure the object will exist inside // `runtimeExecutor_` callback, we need to copy the pointer there. auto weakOwner = uiRunLoopObserver_->getOwner(); - runtimeExecutor_([this, weakOwner](jsi::Runtime &runtime) mutable { + isBeatCallbackScheduled_ = true; + + runtimeExecutor_([this, weakOwner](jsi::Runtime &runtime) { + isBeatCallbackScheduled_ = false; + auto owner = weakOwner.lock(); if (!owner) { return; } - if (!isRequested_) { - return; + if (beatCallback_) { + beatCallback_(runtime); } - - this->beat(runtime); }); } - -} // namespace react -} // namespace facebook +} // namespace facebook::react diff --git a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.h b/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.h index 1acdcbb02d..c6751a0879 100644 --- a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.h +++ b/ReactCommon/react/renderer/scheduler/AsynchronousEventBeat.h @@ -9,8 +9,7 @@ #include #include -namespace facebook { -namespace react { +namespace facebook::react { /* * Event beat associated with JavaScript runtime. @@ -35,7 +34,8 @@ class AsynchronousEventBeat : public EventBeat, private: RunLoopObserver::Unique uiRunLoopObserver_; RuntimeExecutor runtimeExecutor_; + + mutable std::atomic isBeatCallbackScheduled_{false}; }; -} // namespace react -} // namespace facebook +} // namespace facebook::react diff --git a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeatV2.cpp b/ReactCommon/react/renderer/scheduler/AsynchronousEventBeatV2.cpp deleted file mode 100644 index 68f80973e5..0000000000 --- a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeatV2.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "AsynchronousEventBeatV2.h" - -#include - -namespace facebook::react { - -AsynchronousEventBeatV2::AsynchronousEventBeatV2( - RunLoopObserver::Unique uiRunLoopObserver, - RuntimeExecutor runtimeExecutor) - : EventBeat({}), - uiRunLoopObserver_(std::move(uiRunLoopObserver)), - runtimeExecutor_(std::move(runtimeExecutor)) { - uiRunLoopObserver_->setDelegate(this); - uiRunLoopObserver_->enable(); -} - -void AsynchronousEventBeatV2::activityDidChange( - RunLoopObserver::Delegate const *delegate, - RunLoopObserver::Activity) const noexcept { - react_native_assert(delegate == this); - induce(); -} - -void AsynchronousEventBeatV2::induce() const { - if (!isRequested_ || isBeatCallbackScheduled_) { - return; - } - - isRequested_ = false; - - // Here we know that `this` object exists because the caller has a strong - // pointer to `owner`. To ensure the object will exist inside - // `runtimeExecutor_` callback, we need to copy the pointer there. - auto weakOwner = uiRunLoopObserver_->getOwner(); - - isBeatCallbackScheduled_ = true; - - runtimeExecutor_([this, weakOwner](jsi::Runtime &runtime) { - isBeatCallbackScheduled_ = false; - - auto owner = weakOwner.lock(); - if (!owner) { - return; - } - - if (beatCallback_) { - beatCallback_(runtime); - } - }); -} -} // namespace facebook::react diff --git a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeatV2.h b/ReactCommon/react/renderer/scheduler/AsynchronousEventBeatV2.h deleted file mode 100644 index b0449fd8d6..0000000000 --- a/ReactCommon/react/renderer/scheduler/AsynchronousEventBeatV2.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include -#include -#include - -namespace facebook::react { - -/* - * Event beat associated with JavaScript runtime. - * The beat is called on `RuntimeExecutor`'s thread induced by the UI thread - * event loop. - */ -class AsynchronousEventBeatV2 : public EventBeat, - public RunLoopObserver::Delegate { - public: - AsynchronousEventBeatV2( - RunLoopObserver::Unique uiRunLoopObserver, - RuntimeExecutor runtimeExecutor); - - void induce() const override; - -#pragma mark - RunLoopObserver::Delegate - - void activityDidChange( - RunLoopObserver::Delegate const *delegate, - RunLoopObserver::Activity activity) const noexcept override; - - private: - RunLoopObserver::Unique uiRunLoopObserver_; - RuntimeExecutor runtimeExecutor_; - - mutable std::atomic isBeatCallbackScheduled_{false}; -}; - -} // namespace facebook::react