From e47e869a00d318cc381504da6015a66d4531f1fd Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Thu, 10 Feb 2022 06:46:12 -0800 Subject: [PATCH] Remove gating for react_fabric.enableV2AsynchronousEventBeat Summary: changelog: [internal] enableV2AsynchronousEventBeat is shipped, let's remove gating Reviewed By: javache Differential Revision: D34108109 fbshipit-source-id: 0264c85cf01f011ab368d56e12f79cc978f9e106 --- ...syncEventBeatV2.cpp => AsyncEventBeat.cpp} | 12 ++--- .../react/fabric/jni/AsyncEventBeat.h | 48 ++++--------------- .../react/fabric/jni/AsyncEventBeatV2.h | 40 ---------------- .../com/facebook/react/fabric/jni/Binding.cpp | 34 ++++--------- 4 files changed, 22 insertions(+), 112 deletions(-) rename ReactAndroid/src/main/java/com/facebook/react/fabric/jni/{AsyncEventBeatV2.cpp => AsyncEventBeat.cpp} (87%) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.h diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.cpp similarity index 87% rename from ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.cpp rename to ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.cpp index 3bf94580a2f..d6e0e63062e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.cpp @@ -9,11 +9,11 @@ #include #include -#include "AsyncEventBeatV2.h" +#include "AsyncEventBeat.h" namespace facebook::react { -AsyncEventBeatV2::AsyncEventBeatV2( +AsyncEventBeat::AsyncEventBeat( EventBeat::SharedOwnerBox const &ownerBox, EventBeatManager *eventBeatManager, RuntimeExecutor runtimeExecutor, @@ -25,11 +25,11 @@ AsyncEventBeatV2::AsyncEventBeatV2( eventBeatManager->addObserver(*this); } -AsyncEventBeatV2::~AsyncEventBeatV2() { +AsyncEventBeat::~AsyncEventBeat() { eventBeatManager_->removeObserver(*this); } -void AsyncEventBeatV2::tick() const { +void AsyncEventBeat::tick() const { if (!isRequested_ || isBeatCallbackScheduled_) { return; } @@ -50,11 +50,11 @@ void AsyncEventBeatV2::tick() const { }); } -void AsyncEventBeatV2::induce() const { +void AsyncEventBeat::induce() const { tick(); } -void AsyncEventBeatV2::request() const { +void AsyncEventBeat::request() const { bool alreadyRequested = isRequested_; EventBeat::request(); if (!alreadyRequested) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h index 072de4e255a..f0316d55776 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeat.h @@ -7,14 +7,11 @@ #pragma once -#include #include -#include #include "EventBeatManager.h" -namespace facebook { -namespace react { +namespace facebook::react { class AsyncEventBeat final : public EventBeat, public EventBeatManagerObserver { public: @@ -22,50 +19,21 @@ class AsyncEventBeat final : public EventBeat, public EventBeatManagerObserver { EventBeat::SharedOwnerBox const &ownerBox, EventBeatManager *eventBeatManager, RuntimeExecutor runtimeExecutor, - jni::global_ref javaUIManager) - : EventBeat(ownerBox), - eventBeatManager_(eventBeatManager), - runtimeExecutor_(std::move(runtimeExecutor)), - javaUIManager_(std::move(javaUIManager)) { - eventBeatManager->addObserver(*this); - } + jni::global_ref javaUIManager); - ~AsyncEventBeat() { - eventBeatManager_->removeObserver(*this); - } + ~AsyncEventBeat() override; - void tick() const override { - runtimeExecutor_([this, ownerBox = ownerBox_](jsi::Runtime &runtime) { - auto owner = ownerBox->owner.lock(); - if (!owner) { - return; - } + void tick() const override; - this->beat(runtime); - }); - } + void induce() const override; - void induce() const override { - tick(); - } - - void request() const override { - bool alreadyRequested = isRequested_; - EventBeat::request(); - if (!alreadyRequested) { - // Notifies java side that an event will be dispatched (e.g. LayoutEvent) - static auto onRequestEventBeat = - jni::findClassStatic("com/facebook/react/fabric/FabricUIManager") - ->getMethod("onRequestEventBeat"); - onRequestEventBeat(javaUIManager_); - } - } + void request() const override; private: EventBeatManager *eventBeatManager_; RuntimeExecutor runtimeExecutor_; jni::global_ref javaUIManager_; + mutable std::atomic isBeatCallbackScheduled_{false}; }; -} // namespace react -} // namespace facebook +} // namespace facebook::react diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.h deleted file mode 100644 index 569af7c96cd..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/AsyncEventBeatV2.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -#include "EventBeatManager.h" - -namespace facebook::react { - -class AsyncEventBeatV2 final : public EventBeat, - public EventBeatManagerObserver { - public: - AsyncEventBeatV2( - EventBeat::SharedOwnerBox const &ownerBox, - EventBeatManager *eventBeatManager, - RuntimeExecutor runtimeExecutor, - jni::global_ref javaUIManager); - - ~AsyncEventBeatV2() override; - - void tick() const override; - - void induce() const override; - - void request() const override; - - private: - EventBeatManager *eventBeatManager_; - RuntimeExecutor runtimeExecutor_; - jni::global_ref javaUIManager_; - mutable std::atomic isBeatCallbackScheduled_{false}; -}; - -} // namespace facebook::react 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 56d2f63ca23..bf6495340eb 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 @@ -7,7 +7,6 @@ #include "Binding.h" #include "AsyncEventBeat.h" -#include "AsyncEventBeatV2.h" #include "EventEmitterWrapper.h" #include "ReactNativeConfigHolder.h" #include "StateWrapperImpl.h" @@ -402,38 +401,21 @@ void Binding::installFabricUIManager( } } - auto enableV2AsynchronousEventBeat = - config->getBool("react_fabric:enable_asynchronous_event_beat_v2_android"); - // TODO: T31905686 Create synchronous Event Beat EventBeat::Factory synchronousBeatFactory = - [eventBeatManager, - runtimeExecutor, - globalJavaUiManager, - enableV2AsynchronousEventBeat](EventBeat::SharedOwnerBox const &ownerBox) + [eventBeatManager, runtimeExecutor, globalJavaUiManager]( + EventBeat::SharedOwnerBox const &ownerBox) -> std::unique_ptr { - if (enableV2AsynchronousEventBeat) { - return std::make_unique( - ownerBox, eventBeatManager, runtimeExecutor, globalJavaUiManager); - } else { - return std::make_unique( - ownerBox, eventBeatManager, runtimeExecutor, globalJavaUiManager); - } + return std::make_unique( + ownerBox, eventBeatManager, runtimeExecutor, globalJavaUiManager); }; EventBeat::Factory asynchronousBeatFactory = - [eventBeatManager, - runtimeExecutor, - globalJavaUiManager, - enableV2AsynchronousEventBeat](EventBeat::SharedOwnerBox const &ownerBox) + [eventBeatManager, runtimeExecutor, globalJavaUiManager]( + EventBeat::SharedOwnerBox const &ownerBox) -> std::unique_ptr { - if (enableV2AsynchronousEventBeat) { - return std::make_unique( - ownerBox, eventBeatManager, runtimeExecutor, globalJavaUiManager); - } else { - return std::make_unique( - ownerBox, eventBeatManager, runtimeExecutor, globalJavaUiManager); - } + return std::make_unique( + ownerBox, eventBeatManager, runtimeExecutor, globalJavaUiManager); }; contextContainer->insert("ReactNativeConfig", config);