mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Forward-declare imports in Binding and FabricMountingManager (#36609)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36609 Some random cleanup as I prepare to make these classes a better injection point for future experiments. * Forward-declare classes where possible to reduce header import * Return references to shared_ptr instead of copies when there are no lifetime concerns * Use a shared JClass instance in JFabricUIManager Changelog: [Internal] Reviewed By: rshest Differential Revision: D44221018 fbshipit-source-id: 1660cac964abd10ce798473e26841503430efdfe
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3759a26214
commit
7259cb342e
@@ -24,10 +24,10 @@ class SchedulerDelegateProxy : public SchedulerDelegate {
|
||||
public:
|
||||
SchedulerDelegateProxy(void *scheduler) : scheduler_(scheduler) {}
|
||||
|
||||
void schedulerDidFinishTransaction(MountingCoordinator::Shared mountingCoordinator) override
|
||||
void schedulerDidFinishTransaction(const MountingCoordinator::Shared &mountingCoordinator) override
|
||||
{
|
||||
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
|
||||
[scheduler.delegate schedulerDidFinishTransaction:std::move(mountingCoordinator)];
|
||||
[scheduler.delegate schedulerDidFinishTransaction:mountingCoordinator];
|
||||
}
|
||||
|
||||
void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, const ShadowNode &shadowNode) override
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class Binding {
|
||||
private native void installFabricUIManager(
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
RuntimeScheduler runtimeScheduler,
|
||||
Object uiManager,
|
||||
FabricUIManager uiManager,
|
||||
EventBeatManager eventBeatManager,
|
||||
ComponentFactory componentsRegistry,
|
||||
Object reactNativeConfig);
|
||||
|
||||
@@ -8,20 +8,24 @@
|
||||
#include "Binding.h"
|
||||
|
||||
#include "AsyncEventBeat.h"
|
||||
#include "ComponentFactory.h"
|
||||
#include "EventBeatManager.h"
|
||||
#include "EventEmitterWrapper.h"
|
||||
#include "FabricMountingManager.h"
|
||||
#include "JBackgroundExecutor.h"
|
||||
#include "ReactNativeConfigHolder.h"
|
||||
#include "StateWrapperImpl.h"
|
||||
#include "SurfaceHandlerBinding.h"
|
||||
|
||||
#include <cfenv>
|
||||
#include <cmath>
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <glog/logging.h>
|
||||
#include <jsi/JSIDynamic.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/renderer/animations/LayoutAnimationDriver.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
|
||||
#include <react/renderer/components/scrollview/ScrollViewProps.h>
|
||||
#include <react/renderer/core/CoreFeatures.h>
|
||||
#include <react/renderer/core/EventBeat.h>
|
||||
#include <react/renderer/core/EventEmitter.h>
|
||||
@@ -33,14 +37,6 @@
|
||||
#include <react/renderer/uimanager/primitives.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
|
||||
// Included to set BaseTextProps config; can be deleted later.
|
||||
#include <react/renderer/components/text/BaseTextProps.h>
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
using namespace facebook::jni;
|
||||
using namespace facebook::jsi;
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
@@ -50,7 +46,7 @@ jni::local_ref<Binding::jhybriddata> Binding::initHybrid(
|
||||
}
|
||||
|
||||
// Thread-safe getter
|
||||
std::shared_ptr<Scheduler> Binding::getScheduler() {
|
||||
const std::shared_ptr<Scheduler> &Binding::getScheduler() {
|
||||
std::shared_lock lock(installMutex_);
|
||||
return scheduler_;
|
||||
}
|
||||
@@ -58,7 +54,7 @@ std::shared_ptr<Scheduler> Binding::getScheduler() {
|
||||
jni::local_ref<ReadableNativeMap::jhybridobject>
|
||||
Binding::getInspectorDataForInstance(
|
||||
jni::alias_ref<EventEmitterWrapper::javaobject> eventEmitterWrapper) {
|
||||
std::shared_ptr<Scheduler> scheduler = getScheduler();
|
||||
auto &scheduler = getScheduler();
|
||||
if (!scheduler) {
|
||||
LOG(ERROR) << "Binding::startSurface: scheduler disappeared";
|
||||
return ReadableNativeMap::newObjectCxxArgs(folly::dynamic::object());
|
||||
@@ -82,15 +78,14 @@ Binding::getInspectorDataForInstance(
|
||||
return ReadableNativeMap::newObjectCxxArgs(result);
|
||||
}
|
||||
|
||||
constexpr static auto ReactFeatureFlagsJavaDescriptor =
|
||||
constexpr static auto kReactFeatureFlagsJavaDescriptor =
|
||||
"com/facebook/react/config/ReactFeatureFlags";
|
||||
|
||||
static bool getFeatureFlagValue(const char *name) {
|
||||
static const auto reactFeatureFlagsJavaDescriptor =
|
||||
jni::findClassStatic(ReactFeatureFlagsJavaDescriptor);
|
||||
const auto field =
|
||||
reactFeatureFlagsJavaDescriptor->getStaticField<jboolean>(name);
|
||||
return reactFeatureFlagsJavaDescriptor->getStaticFieldValue(field);
|
||||
static const auto reactFeatureFlagsClass =
|
||||
jni::findClassStatic(kReactFeatureFlagsJavaDescriptor);
|
||||
const auto field = reactFeatureFlagsClass->getStaticField<jboolean>(name);
|
||||
return reactFeatureFlagsClass->getStaticFieldValue(field);
|
||||
}
|
||||
|
||||
void Binding::setPixelDensity(float pointScaleFactor) {
|
||||
@@ -109,7 +104,7 @@ void Binding::startSurface(
|
||||
NativeMap *initialProps) {
|
||||
SystraceSection s("FabricUIManagerBinding::startSurface");
|
||||
|
||||
std::shared_ptr<Scheduler> scheduler = getScheduler();
|
||||
auto &scheduler = getScheduler();
|
||||
if (!scheduler) {
|
||||
LOG(ERROR) << "Binding::startSurface: scheduler disappeared";
|
||||
return;
|
||||
@@ -137,7 +132,7 @@ void Binding::startSurface(
|
||||
surfaceHandlerRegistry_.emplace(surfaceId, std::move(surfaceHandler));
|
||||
}
|
||||
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("FabricUIManagerBinding::startSurface");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
@@ -165,7 +160,7 @@ void Binding::startSurfaceWithConstraints(
|
||||
<< this << ", surfaceId: " << surfaceId << ").";
|
||||
}
|
||||
|
||||
std::shared_ptr<Scheduler> scheduler = getScheduler();
|
||||
auto &scheduler = getScheduler();
|
||||
if (!scheduler) {
|
||||
LOG(ERROR) << "Binding::startSurfaceWithConstraints: scheduler disappeared";
|
||||
return;
|
||||
@@ -208,7 +203,7 @@ void Binding::startSurfaceWithConstraints(
|
||||
surfaceHandlerRegistry_.emplace(surfaceId, std::move(surfaceHandler));
|
||||
}
|
||||
|
||||
auto mountingManager = verifyMountingManager(
|
||||
auto &mountingManager = verifyMountingManager(
|
||||
"FabricUIManagerBinding::startSurfaceWithConstraints");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
@@ -219,13 +214,13 @@ void Binding::startSurfaceWithConstraints(
|
||||
void Binding::renderTemplateToSurface(jint surfaceId, jstring uiTemplate) {
|
||||
SystraceSection s("FabricUIManagerBinding::renderTemplateToSurface");
|
||||
|
||||
std::shared_ptr<Scheduler> scheduler = getScheduler();
|
||||
auto &scheduler = getScheduler();
|
||||
if (!scheduler) {
|
||||
LOG(ERROR) << "Binding::renderTemplateToSurface: scheduler disappeared";
|
||||
return;
|
||||
}
|
||||
|
||||
auto env = Environment::current();
|
||||
auto env = jni::Environment::current();
|
||||
const char *nativeString = env->GetStringUTFChars(uiTemplate, JNI_FALSE);
|
||||
scheduler->renderTemplateToSurface(surfaceId, nativeString);
|
||||
env->ReleaseStringUTFChars(uiTemplate, nativeString);
|
||||
@@ -239,7 +234,7 @@ void Binding::stopSurface(jint surfaceId) {
|
||||
<< ", surfaceId: " << surfaceId << ").";
|
||||
}
|
||||
|
||||
std::shared_ptr<Scheduler> scheduler = getScheduler();
|
||||
auto &scheduler = getScheduler();
|
||||
if (!scheduler) {
|
||||
LOG(ERROR) << "Binding::stopSurface: scheduler disappeared";
|
||||
return;
|
||||
@@ -261,7 +256,7 @@ void Binding::stopSurface(jint surfaceId) {
|
||||
scheduler->unregisterSurface(surfaceHandler);
|
||||
}
|
||||
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("FabricUIManagerBinding::stopSurface");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
@@ -278,7 +273,7 @@ void Binding::registerSurface(SurfaceHandlerBinding *surfaceHandlerBinding) {
|
||||
}
|
||||
scheduler->registerSurface(surfaceHandler);
|
||||
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("FabricUIManagerBinding::registerSurface");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
@@ -295,7 +290,7 @@ void Binding::unregisterSurface(SurfaceHandlerBinding *surfaceHandlerBinding) {
|
||||
}
|
||||
scheduler->unregisterSurface(surfaceHandler);
|
||||
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("FabricUIManagerBinding::unregisterSurface");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
@@ -315,7 +310,7 @@ void Binding::setConstraints(
|
||||
jboolean doLeftAndRightSwapInRTL) {
|
||||
SystraceSection s("FabricUIManagerBinding::setConstraints");
|
||||
|
||||
std::shared_ptr<Scheduler> scheduler = getScheduler();
|
||||
auto &scheduler = getScheduler();
|
||||
if (!scheduler) {
|
||||
LOG(ERROR) << "Binding::setConstraints: scheduler disappeared";
|
||||
return;
|
||||
@@ -358,7 +353,7 @@ void Binding::setConstraints(
|
||||
void Binding::installFabricUIManager(
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
|
||||
jni::alias_ref<JRuntimeScheduler::javaobject> runtimeSchedulerHolder,
|
||||
jni::alias_ref<jobject> javaUIManager,
|
||||
jni::alias_ref<JFabricUIManager::javaobject> javaUIManager,
|
||||
EventBeatManager *eventBeatManager,
|
||||
ComponentFactory *componentsRegistry,
|
||||
jni::alias_ref<jobject> reactNativeConfig) {
|
||||
@@ -375,8 +370,6 @@ void Binding::installFabricUIManager(
|
||||
<< this << ").";
|
||||
}
|
||||
|
||||
// Use std::lock and std::adopt_lock to prevent deadlocks by locking mutexes
|
||||
// at the same time
|
||||
std::unique_lock lock(installMutex_);
|
||||
|
||||
auto globalJavaUiManager = make_global(javaUIManager);
|
||||
@@ -431,13 +424,10 @@ void Binding::installFabricUIManager(
|
||||
|
||||
CoreFeatures::cacheLastTextMeasurement =
|
||||
getFeatureFlagValue("enableTextMeasureCachePerShadowNode");
|
||||
|
||||
// Props setter pattern feature
|
||||
CoreFeatures::enablePropIteratorSetter =
|
||||
getFeatureFlagValue("enableCppPropsIteratorSetter");
|
||||
|
||||
// NativeState experiment
|
||||
CoreFeatures::useNativeState = getFeatureFlagValue("useNativeState");
|
||||
CoreFeatures::enableMapBuffer = getFeatureFlagValue("useMapBufferProps");
|
||||
|
||||
// RemoveDelete mega-op
|
||||
ShadowViewMutation::PlatformSupportsRemoveDeleteTreeInstruction =
|
||||
@@ -480,24 +470,23 @@ void Binding::uninstallFabricUIManager() {
|
||||
reactNativeConfig_ = nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<FabricMountingManager> Binding::verifyMountingManager(
|
||||
std::string const &hint) {
|
||||
const std::shared_ptr<FabricMountingManager> &Binding::verifyMountingManager(
|
||||
const char *locationHint) {
|
||||
std::shared_lock lock(installMutex_);
|
||||
if (!mountingManager_) {
|
||||
LOG(ERROR) << hint << " mounting manager disappeared.";
|
||||
LOG(ERROR) << locationHint << " mounting manager disappeared.";
|
||||
}
|
||||
return mountingManager_;
|
||||
}
|
||||
|
||||
void Binding::schedulerDidFinishTransaction(
|
||||
MountingCoordinator::Shared mountingCoordinator) {
|
||||
auto mountingManager =
|
||||
const MountingCoordinator::Shared &mountingCoordinator) {
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("Binding::schedulerDidFinishTransaction");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->executeMount(std::move(mountingCoordinator));
|
||||
mountingManager->executeMount(mountingCoordinator);
|
||||
}
|
||||
|
||||
void Binding::schedulerDidRequestPreliminaryViewAllocation(
|
||||
@@ -515,11 +504,10 @@ void Binding::preallocateView(
|
||||
ShadowNode const &shadowNode) {
|
||||
auto name = std::string(shadowNode.getComponentName());
|
||||
auto shadowView = ShadowView(shadowNode);
|
||||
auto mountingManager = verifyMountingManager("Binding::preallocateView");
|
||||
auto &mountingManager = verifyMountingManager("Binding::preallocateView");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->preallocateShadowView(surfaceId, shadowView);
|
||||
}
|
||||
|
||||
@@ -527,24 +515,22 @@ void Binding::schedulerDidDispatchCommand(
|
||||
const ShadowView &shadowView,
|
||||
std::string const &commandName,
|
||||
folly::dynamic const &args) {
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("Binding::schedulerDidDispatchCommand");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->dispatchCommand(shadowView, commandName, args);
|
||||
}
|
||||
|
||||
void Binding::schedulerDidSendAccessibilityEvent(
|
||||
const ShadowView &shadowView,
|
||||
std::string const &eventType) {
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("Binding::schedulerDidSendAccessibilityEvent");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->sendAccessibilityEvent(shadowView, eventType);
|
||||
}
|
||||
|
||||
@@ -552,31 +538,28 @@ void Binding::schedulerDidSetIsJSResponder(
|
||||
ShadowView const &shadowView,
|
||||
bool isJSResponder,
|
||||
bool blockNativeResponder) {
|
||||
auto mountingManager =
|
||||
auto &mountingManager =
|
||||
verifyMountingManager("Binding::schedulerDidSetIsJSResponder");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->setIsJSResponder(
|
||||
shadowView, isJSResponder, blockNativeResponder);
|
||||
}
|
||||
|
||||
void Binding::onAnimationStarted() {
|
||||
auto mountingManager = verifyMountingManager("Binding::onAnimationStarted");
|
||||
auto &mountingManager = verifyMountingManager("Binding::onAnimationStarted");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->onAnimationStarted();
|
||||
}
|
||||
|
||||
void Binding::onAllAnimationsComplete() {
|
||||
auto mountingManager = verifyMountingManager("Binding::onAnimationComplete");
|
||||
auto &mountingManager = verifyMountingManager("Binding::onAnimationComplete");
|
||||
if (!mountingManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountingManager->onAllAnimationsComplete();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FabricMountingManager.h"
|
||||
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
|
||||
@@ -16,20 +14,25 @@
|
||||
#include <react/jni/JRuntimeExecutor.h>
|
||||
#include <react/jni/JRuntimeScheduler.h>
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
#include <react/renderer/animations/LayoutAnimationDriver.h>
|
||||
#include <react/renderer/scheduler/Scheduler.h>
|
||||
#include <react/renderer/scheduler/SchedulerDelegate.h>
|
||||
#include <react/renderer/scheduler/SurfaceHandler.h>
|
||||
#include <react/renderer/uimanager/LayoutAnimationStatusDelegate.h>
|
||||
#include <react/renderer/uimanager/primitives.h>
|
||||
|
||||
#include "ComponentFactory.h"
|
||||
#include "EventBeatManager.h"
|
||||
#include "EventEmitterWrapper.h"
|
||||
#include "SurfaceHandlerBinding.h"
|
||||
#include "JFabricUIManager.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class ComponentFactory;
|
||||
class EventBeatManager;
|
||||
class FabricMountingManager;
|
||||
class Instance;
|
||||
class LayoutAnimationDriver;
|
||||
class ReactNativeConfig;
|
||||
class Scheduler;
|
||||
class SurfaceHandlerBinding;
|
||||
|
||||
class Binding : public jni::HybridClass<Binding>,
|
||||
public SchedulerDelegate,
|
||||
@@ -40,7 +43,7 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
std::shared_ptr<Scheduler> getScheduler();
|
||||
const std::shared_ptr<Scheduler> &getScheduler();
|
||||
|
||||
private:
|
||||
void setConstraints(
|
||||
@@ -62,7 +65,7 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
void installFabricUIManager(
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
|
||||
jni::alias_ref<JRuntimeScheduler::javaobject> runtimeSchedulerHolder,
|
||||
jni::alias_ref<jobject> javaUIManager,
|
||||
jni::alias_ref<JFabricUIManager::javaobject> javaUIManager,
|
||||
EventBeatManager *eventBeatManager,
|
||||
ComponentFactory *componentsRegistry,
|
||||
jni::alias_ref<jobject> reactNativeConfig);
|
||||
@@ -94,7 +97,7 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
void unregisterSurface(SurfaceHandlerBinding *surfaceHandler);
|
||||
|
||||
void schedulerDidFinishTransaction(
|
||||
MountingCoordinator::Shared mountingCoordinator) override;
|
||||
const MountingCoordinator::Shared &mountingCoordinator) override;
|
||||
|
||||
void schedulerDidRequestPreliminaryViewAllocation(
|
||||
const SurfaceId surfaceId,
|
||||
@@ -127,8 +130,8 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
std::shared_ptr<FabricMountingManager> mountingManager_;
|
||||
std::shared_ptr<Scheduler> scheduler_;
|
||||
|
||||
std::shared_ptr<FabricMountingManager> verifyMountingManager(
|
||||
std::string const &locationHint);
|
||||
const std::shared_ptr<FabricMountingManager> &verifyMountingManager(
|
||||
const char *locationHint);
|
||||
|
||||
// LayoutAnimations
|
||||
void onAnimationStarted() override;
|
||||
|
||||
+48
-57
@@ -6,7 +6,9 @@
|
||||
*/
|
||||
|
||||
#include "FabricMountingManager.h"
|
||||
|
||||
#include "EventEmitterWrapper.h"
|
||||
#include "FabricMountItem.h"
|
||||
#include "StateWrapperImpl.h"
|
||||
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
@@ -14,6 +16,7 @@
|
||||
#include <react/renderer/core/CoreFeatures.h>
|
||||
#include <react/renderer/core/conversions.h>
|
||||
#include <react/renderer/debug/SystraceSection.h>
|
||||
#include <react/renderer/mounting/ShadowView.h>
|
||||
#include <react/renderer/mounting/ShadowViewMutation.h>
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
@@ -23,27 +26,25 @@
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
using namespace facebook::jni;
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
constexpr static auto kReactFeatureFlagsJavaDescriptor =
|
||||
"com/facebook/react/config/ReactFeatureFlags";
|
||||
|
||||
static bool getFeatureFlagValue(const char *name) {
|
||||
static const auto reactFeatureFlagsJavaDescriptor = jni::findClassStatic(
|
||||
FabricMountingManager::ReactFeatureFlagsJavaDescriptor);
|
||||
const auto field =
|
||||
reactFeatureFlagsJavaDescriptor->getStaticField<jboolean>(name);
|
||||
return reactFeatureFlagsJavaDescriptor->getStaticFieldValue(field);
|
||||
static const auto reactFeatureFlagsClass =
|
||||
jni::findClassStatic(kReactFeatureFlagsJavaDescriptor);
|
||||
const auto field = reactFeatureFlagsClass->getStaticField<jboolean>(name);
|
||||
return reactFeatureFlagsClass->getStaticFieldValue(field);
|
||||
}
|
||||
|
||||
FabricMountingManager::FabricMountingManager(
|
||||
std::shared_ptr<const ReactNativeConfig> &config,
|
||||
global_ref<jobject> &javaUIManager)
|
||||
jni::global_ref<JFabricUIManager::javaobject> &javaUIManager)
|
||||
: javaUIManager_(javaUIManager),
|
||||
reduceDeleteCreateMutation_(
|
||||
getFeatureFlagValue("reduceDeleteCreateMutation")) {
|
||||
CoreFeatures::enableMapBuffer = getFeatureFlagValue("useMapBufferProps");
|
||||
}
|
||||
getFeatureFlagValue("reduceDeleteCreateMutation")) {}
|
||||
|
||||
void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) {
|
||||
std::lock_guard lock(allocatedViewsMutex_);
|
||||
@@ -203,27 +204,21 @@ static inline void writeIntBufferTypePreamble(
|
||||
}
|
||||
}
|
||||
|
||||
inline local_ref<ReadableArray::javaobject> castReadableArray(
|
||||
local_ref<ReadableNativeArray::javaobject> const &nativeArray) {
|
||||
return make_local(
|
||||
reinterpret_cast<ReadableArray::javaobject>(nativeArray.get()));
|
||||
}
|
||||
|
||||
// TODO: this method will be removed when binding for components are code-gen
|
||||
local_ref<JString> getPlatformComponentName(ShadowView const &shadowView) {
|
||||
jni::local_ref<jstring> getPlatformComponentName(ShadowView const &shadowView) {
|
||||
static std::string scrollViewComponentName = std::string("ScrollView");
|
||||
|
||||
local_ref<JString> componentName;
|
||||
jni::local_ref<jstring> componentName;
|
||||
if (scrollViewComponentName == shadowView.componentName) {
|
||||
auto newViewProps =
|
||||
std::static_pointer_cast<const ScrollViewProps>(shadowView.props);
|
||||
if (newViewProps->getProbablyMoreHorizontalThanVertical_DEPRECATED()) {
|
||||
componentName = make_jstring("AndroidHorizontalScrollView");
|
||||
componentName = jni::make_jstring("AndroidHorizontalScrollView");
|
||||
return componentName;
|
||||
}
|
||||
}
|
||||
|
||||
componentName = make_jstring(shadowView.componentName);
|
||||
componentName = jni::make_jstring(shadowView.componentName);
|
||||
return componentName;
|
||||
}
|
||||
|
||||
@@ -243,7 +238,7 @@ static inline float scale(Float value, Float pointScaleFactor) {
|
||||
return result;
|
||||
}
|
||||
|
||||
local_ref<jobject> FabricMountingManager::getProps(
|
||||
jni::local_ref<jobject> FabricMountingManager::getProps(
|
||||
ShadowView const &oldShadowView,
|
||||
ShadowView const &newShadowView) {
|
||||
if (CoreFeatures::enableMapBuffer &&
|
||||
@@ -263,7 +258,7 @@ local_ref<jobject> FabricMountingManager::getProps(
|
||||
}
|
||||
|
||||
void FabricMountingManager::executeMount(
|
||||
MountingCoordinator::Shared mountingCoordinator) {
|
||||
const MountingCoordinator::Shared &mountingCoordinator) {
|
||||
std::lock_guard<std::recursive_mutex> lock(commitMutex_);
|
||||
|
||||
SystraceSection s(
|
||||
@@ -276,7 +271,7 @@ void FabricMountingManager::executeMount(
|
||||
return;
|
||||
}
|
||||
|
||||
auto env = Environment::current();
|
||||
auto env = jni::Environment::current();
|
||||
|
||||
auto telemetry = mountingTransaction->getTelemetry();
|
||||
auto surfaceId = mountingTransaction->getSurfaceId();
|
||||
@@ -515,12 +510,12 @@ void FabricMountingManager::executeMount(
|
||||
cppViewMutations);
|
||||
|
||||
static auto createMountItemsIntBufferBatchContainer =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(
|
||||
jint, jintArray, jtypeArray<jobject>, jint)>(
|
||||
JFabricUIManager::javaClassStatic()
|
||||
->getMethod<jni::alias_ref<JMountItem>(
|
||||
jint, jintArray, jni::jtypeArray<jobject>, jint)>(
|
||||
"createIntBufferBatchMountItem");
|
||||
|
||||
static auto scheduleMountItem = jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
static auto scheduleMountItem = JFabricUIManager::javaClassStatic()
|
||||
->getMethod<void(
|
||||
JMountItem::javaobject,
|
||||
jint,
|
||||
@@ -552,8 +547,8 @@ void FabricMountingManager::executeMount(
|
||||
// Allocate the intBuffer and object array, now that we know exact sizes
|
||||
// necessary
|
||||
jintArray intBufferArray = env->NewIntArray(batchMountItemIntsSize);
|
||||
local_ref<JArrayClass<jobject>> objBufferArray =
|
||||
JArrayClass<jobject>::newArray(batchMountItemObjectsSize);
|
||||
auto objBufferArray =
|
||||
jni::JArrayClass<jobject>::newArray(batchMountItemObjectsSize);
|
||||
|
||||
// Fill in arrays
|
||||
int intBufferPosition = 0;
|
||||
@@ -585,19 +580,19 @@ void FabricMountingManager::executeMount(
|
||||
|
||||
// TODO: multi-create, multi-insert, etc
|
||||
if (mountItemType == CppMountItem::Type::Create) {
|
||||
local_ref<JString> componentName =
|
||||
auto componentName =
|
||||
getPlatformComponentName(mountItem.newChildShadowView);
|
||||
|
||||
int isLayoutable =
|
||||
mountItem.newChildShadowView.layoutMetrics != EmptyLayoutMetrics ? 1
|
||||
: 0;
|
||||
local_ref<JObject> props =
|
||||
jni::local_ref<jobject> props =
|
||||
getProps(mountItem.oldChildShadowView, mountItem.newChildShadowView);
|
||||
|
||||
// Do not hold onto Java object from C
|
||||
// We DO want to hold onto C object from Java, since we don't know the
|
||||
// lifetime of the Java object
|
||||
local_ref<StateWrapperImpl::JavaPart> javaStateWrapper = nullptr;
|
||||
jni::local_ref<StateWrapperImpl::JavaPart> javaStateWrapper = nullptr;
|
||||
if (mountItem.newChildShadowView.state != nullptr) {
|
||||
javaStateWrapper = StateWrapperImpl::newObjectJavaArgs();
|
||||
StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper);
|
||||
@@ -675,7 +670,7 @@ void FabricMountingManager::executeMount(
|
||||
// Do not hold onto Java object from C
|
||||
// We DO want to hold onto C object from Java, since we don't know the
|
||||
// lifetime of the Java object
|
||||
local_ref<StateWrapperImpl::JavaPart> javaStateWrapper = nullptr;
|
||||
jni::local_ref<StateWrapperImpl::JavaPart> javaStateWrapper = nullptr;
|
||||
if (state != nullptr) {
|
||||
javaStateWrapper = StateWrapperImpl::newObjectJavaArgs();
|
||||
StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper);
|
||||
@@ -864,7 +859,7 @@ void FabricMountingManager::preallocateShadowView(
|
||||
bool isLayoutableShadowNode = shadowView.layoutMetrics != EmptyLayoutMetrics;
|
||||
|
||||
static auto preallocateView =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
JFabricUIManager::javaClassStatic()
|
||||
->getMethod<void(
|
||||
jint, jint, jstring, jobject, jobject, jobject, jboolean)>(
|
||||
"preallocateView");
|
||||
@@ -872,7 +867,7 @@ void FabricMountingManager::preallocateShadowView(
|
||||
// Do not hold onto Java object from C
|
||||
// We DO want to hold onto C object from Java, since we don't know the
|
||||
// lifetime of the Java object
|
||||
local_ref<StateWrapperImpl::JavaPart> javaStateWrapper = nullptr;
|
||||
jni::local_ref<StateWrapperImpl::JavaPart> javaStateWrapper = nullptr;
|
||||
if (shadowView.state != nullptr) {
|
||||
javaStateWrapper = StateWrapperImpl::newObjectJavaArgs();
|
||||
StateWrapperImpl *cStateWrapper = cthis(javaStateWrapper);
|
||||
@@ -880,9 +875,9 @@ void FabricMountingManager::preallocateShadowView(
|
||||
}
|
||||
|
||||
// Do not hold a reference to javaEventEmitter from the C++ side.
|
||||
local_ref<EventEmitterWrapper::JavaPart> javaEventEmitter = nullptr;
|
||||
jni::local_ref<EventEmitterWrapper::JavaPart> javaEventEmitter = nullptr;
|
||||
|
||||
local_ref<JObject> props = getProps({}, shadowView);
|
||||
jni::local_ref<jobject> props = getProps({}, shadowView);
|
||||
|
||||
auto component = getPlatformComponentName(shadowView);
|
||||
|
||||
@@ -902,15 +897,12 @@ void FabricMountingManager::dispatchCommand(
|
||||
std::string const &commandName,
|
||||
folly::dynamic const &args) {
|
||||
static auto dispatchCommand =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
JFabricUIManager::javaClassStatic()
|
||||
->getMethod<void(jint, jint, jstring, ReadableArray::javaobject)>(
|
||||
"dispatchCommand");
|
||||
|
||||
local_ref<JString> command = make_jstring(commandName);
|
||||
|
||||
local_ref<ReadableArray::javaobject> argsArray =
|
||||
castReadableArray(ReadableNativeArray::newObjectCxxArgs(args));
|
||||
|
||||
auto command = jni::make_jstring(commandName);
|
||||
auto argsArray = jni::adopt_local(reinterpret_cast<ReadableArray::javaobject>(
|
||||
ReadableNativeArray::newObjectCxxArgs(args).release()));
|
||||
dispatchCommand(
|
||||
javaUIManager_,
|
||||
shadowView.surfaceId,
|
||||
@@ -922,13 +914,11 @@ void FabricMountingManager::dispatchCommand(
|
||||
void FabricMountingManager::sendAccessibilityEvent(
|
||||
ShadowView const &shadowView,
|
||||
std::string const &eventType) {
|
||||
local_ref<JString> eventTypeStr = make_jstring(eventType);
|
||||
|
||||
static auto sendAccessibilityEventFromJS =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void(jint, jint, jstring)>(
|
||||
"sendAccessibilityEventFromJS");
|
||||
JFabricUIManager::javaClassStatic()->getMethod<void(jint, jint, jstring)>(
|
||||
"sendAccessibilityEventFromJS");
|
||||
|
||||
auto eventTypeStr = jni::make_jstring(eventType);
|
||||
sendAccessibilityEventFromJS(
|
||||
javaUIManager_, shadowView.surfaceId, shadowView.tag, eventTypeStr.get());
|
||||
}
|
||||
@@ -938,11 +928,12 @@ void FabricMountingManager::setIsJSResponder(
|
||||
bool isJSResponder,
|
||||
bool blockNativeResponder) {
|
||||
static auto setJSResponder =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
JFabricUIManager::javaClassStatic()
|
||||
->getMethod<void(jint, jint, jint, jboolean)>("setJSResponder");
|
||||
|
||||
static auto clearJSResponder = jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void()>("clearJSResponder");
|
||||
static auto clearJSResponder =
|
||||
JFabricUIManager::javaClassStatic()->getMethod<void()>(
|
||||
"clearJSResponder");
|
||||
|
||||
if (isJSResponder) {
|
||||
setJSResponder(
|
||||
@@ -962,16 +953,16 @@ void FabricMountingManager::setIsJSResponder(
|
||||
|
||||
void FabricMountingManager::onAnimationStarted() {
|
||||
static auto layoutAnimationsStartedJNI =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void()>("onAnimationStarted");
|
||||
JFabricUIManager::javaClassStatic()->getMethod<void()>(
|
||||
"onAnimationStarted");
|
||||
|
||||
layoutAnimationsStartedJNI(javaUIManager_);
|
||||
}
|
||||
|
||||
void FabricMountingManager::onAllAnimationsComplete() {
|
||||
static auto allAnimationsCompleteJNI =
|
||||
jni::findClassStatic(UIManagerJavaDescriptor)
|
||||
->getMethod<void()>("onAllAnimationsComplete");
|
||||
JFabricUIManager::javaClassStatic()->getMethod<void()>(
|
||||
"onAllAnimationsComplete");
|
||||
|
||||
allAnimationsCompleteJNI(javaUIManager_);
|
||||
}
|
||||
|
||||
+12
-20
@@ -7,33 +7,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FabricMountItem.h"
|
||||
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/renderer/animations/LayoutAnimationDriver.h>
|
||||
#include <react/renderer/mounting/MountingCoordinator.h>
|
||||
#include <react/renderer/mounting/ShadowView.h>
|
||||
#include <react/renderer/uimanager/LayoutAnimationStatusDelegate.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <butter/set.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <react/fabric/JFabricUIManager.h>
|
||||
#include <react/renderer/mounting/MountingCoordinator.h>
|
||||
#include <react/renderer/uimanager/primitives.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class ReactNativeConfig;
|
||||
struct ShadowView;
|
||||
|
||||
class FabricMountingManager final {
|
||||
public:
|
||||
constexpr static auto UIManagerJavaDescriptor =
|
||||
"com/facebook/react/fabric/FabricUIManager";
|
||||
|
||||
constexpr static auto ReactFeatureFlagsJavaDescriptor =
|
||||
"com/facebook/react/config/ReactFeatureFlags";
|
||||
|
||||
FabricMountingManager(
|
||||
std::shared_ptr<const ReactNativeConfig> &config,
|
||||
jni::global_ref<jobject> &javaUIManager);
|
||||
jni::global_ref<JFabricUIManager::javaobject> &javaUIManager);
|
||||
|
||||
void onSurfaceStart(SurfaceId surfaceId);
|
||||
|
||||
@@ -41,7 +33,7 @@ class FabricMountingManager final {
|
||||
|
||||
void preallocateShadowView(SurfaceId surfaceId, ShadowView const &shadowView);
|
||||
|
||||
void executeMount(MountingCoordinator::Shared mountingCoordinator);
|
||||
void executeMount(const MountingCoordinator::Shared &mountingCoordinator);
|
||||
|
||||
void dispatchCommand(
|
||||
ShadowView const &shadowView,
|
||||
@@ -62,7 +54,7 @@ class FabricMountingManager final {
|
||||
void onAllAnimationsComplete();
|
||||
|
||||
private:
|
||||
jni::global_ref<jobject> javaUIManager_;
|
||||
jni::global_ref<JFabricUIManager::javaobject> javaUIManager_;
|
||||
|
||||
std::recursive_mutex commitMutex_;
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "JFabricUIManager.h"
|
||||
|
||||
#include "Binding.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
Binding *JFabricUIManager::getBinding() {
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
|
||||
#include "Binding.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
class Binding;
|
||||
|
||||
class JFabricUIManager : public jni::JavaClass<JFabricUIManager> {
|
||||
public:
|
||||
static constexpr auto kJavaDescriptor =
|
||||
|
||||
@@ -320,15 +320,13 @@ void Scheduler::uiManagerDidFinishTransaction(
|
||||
[delegate = delegate_,
|
||||
mountingCoordinator =
|
||||
std::move(mountingCoordinator)](jsi::Runtime &) {
|
||||
delegate->schedulerDidFinishTransaction(
|
||||
std::move(mountingCoordinator));
|
||||
delegate->schedulerDidFinishTransaction(mountingCoordinator);
|
||||
});
|
||||
} else {
|
||||
delegate_->schedulerDidFinishTransaction(
|
||||
std::move(mountingCoordinator));
|
||||
delegate_->schedulerDidFinishTransaction(mountingCoordinator);
|
||||
}
|
||||
} else {
|
||||
delegate_->schedulerDidFinishTransaction(std::move(mountingCoordinator));
|
||||
delegate_->schedulerDidFinishTransaction(mountingCoordinator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class SchedulerDelegate {
|
||||
* to construct a new one.
|
||||
*/
|
||||
virtual void schedulerDidFinishTransaction(
|
||||
MountingCoordinator::Shared mountingCoordinator) = 0;
|
||||
const MountingCoordinator::Shared &mountingCoordinator) = 0;
|
||||
|
||||
/*
|
||||
* Called right after a new ShadowNode was created.
|
||||
|
||||
Reference in New Issue
Block a user