Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ FabricMountingManager::FabricMountingManager(
: javaUIManager_(javaUIManager) {}

FabricMountingManager::~FabricMountingManager() {
// Manually reset `javaUIManager_` since FabricMountingManager may be retained
// from a GC thread (destroyUnmountedShadowNode)
jni::ThreadScope::WithClassLoader([&]() { javaUIManager_.reset(); });
// Release the Java references in a JNI thread scope, since
// FabricMountingManager may be retained from a GC thread
// (destroyUnmountedShadowNode)
jni::ThreadScope::WithClassLoader([&]() {
javaUIManager_.reset();
componentNames_.clear();
});
}

void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) {
Expand Down Expand Up @@ -291,20 +295,6 @@ inline std::pair<int, int> computeBufferSizes(
return std::make_pair(batchMountItemIntsSize, batchMountItemObjectsSize);
}

// TODO: this method will be removed when binding for components are code-gen
jni::local_ref<jstring> getPlatformComponentName(const ShadowView& shadowView) {
constexpr static std::string_view scrollViewComponentName = "ScrollView";

if (scrollViewComponentName == shadowView.componentName) {
const auto& newViewProps =
static_cast<const ScrollViewProps&>(*shadowView.props);
if (newViewProps.getProbablyMoreHorizontalThanVertical_DEPRECATED()) {
return jni::make_jstring("AndroidHorizontalScrollView");
}
}
return jni::make_jstring(shadowView.componentName);
}

inline float scale(Float value, Float pointScaleFactor) {
std::feclearexcept(FE_ALL_EXCEPT);
float result = value * pointScaleFactor;
Expand Down Expand Up @@ -424,14 +414,13 @@ inline void writeMountItemPreamble(

inline void writeCreateMountItem(
InstructionBuffer& buffer,
const CppMountItem& mountItem) {
const CppMountItem& mountItem,
jni::alias_ref<jstring> componentName) {
int isLayoutable =
mountItem.newChildShadowView.layoutMetrics != EmptyLayoutMetrics ? 1 : 0;
buffer.writeIntArray(
std::array<int, 2>{mountItem.newChildShadowView.tag, isLayoutable});

auto componentName = getPlatformComponentName(mountItem.newChildShadowView);

jni::local_ref<jobject> props =
getProps(mountItem.oldChildShadowView, mountItem.newChildShadowView);

Expand Down Expand Up @@ -589,6 +578,28 @@ inline void writeUpdateOverflowInsetMountItem(

} // namespace

// TODO: this method will be removed when binding for components are code-gen
jni::alias_ref<jstring> FabricMountingManager::getPlatformComponentName(
const ShadowView& shadowView) {
const char* name = shadowView.componentName;
if (std::string_view{name} == "ScrollView") {
const auto& scrollViewProps =
static_cast<const ScrollViewProps&>(*shadowView.props);
if (scrollViewProps.getProbablyMoreHorizontalThanVertical_DEPRECATED()) {
name = "AndroidHorizontalScrollView";
}
}

std::lock_guard lock(componentNamesMutex_);
auto it = componentNames_.find(std::string_view{name});
if (it == componentNames_.end()) {
it =
componentNames_.emplace(name, jni::make_global(jni::make_jstring(name)))
.first;
}
return it->second;
}

void FabricMountingManager::executeMount(
const MountingTransaction& transaction,
bool synchronous) {
Expand Down Expand Up @@ -970,7 +981,10 @@ void FabricMountingManager::executeMount(

switch (mountItemType) {
case CppMountItem::Type::Create:
writeCreateMountItem(buffer, mountItem);
writeCreateMountItem(
buffer,
mountItem,
getPlatformComponentName(mountItem.newChildShadowView));
break;
case CppMountItem::Type::Delete:
writeDeleteMountItem(buffer, mountItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>

#include <React/RendererCore.h>
#include <fbjni/fbjni.h>
#include <folly/container/F14Map.h>
#include <react/fabric/JFabricUIManager.h>
#include <react/renderer/mounting/ShadowView.h>

Expand Down Expand Up @@ -108,8 +110,18 @@ class FabricMountingManager final {

void preallocateRegisteredView(const ShadowView &shadowView);

/*
* Returns the component name Java looks the view's manager up by. Each name
* is one Java string, created on first use and kept for the lifetime of this
* FabricMountingManager.
*/
jni::alias_ref<jstring> getPlatformComponentName(const ShadowView &shadowView);

jni::global_ref<JFabricUIManager::javaobject> javaUIManager_;

folly::F14FastMap<std::string, jni::global_ref<jstring>> componentNames_{};
std::mutex componentNamesMutex_;

std::recursive_mutex commitMutex_;

/*
Expand Down
Loading