diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.cpp index 0d1e2c6f2da50b..27b4c1b3ceeaf3 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.cpp @@ -5,11 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -#include - -#include -#include - #include "ComponentNameResolverManager.h" #include @@ -18,12 +13,13 @@ namespace facebook::react { using namespace facebook::jni; +constexpr static auto ComponentNameResolverJavaDescriptor = + "com/facebook/react/uimanager/ComponentNameResolver"; + ComponentNameResolverManager::ComponentNameResolverManager( - jni::alias_ref jThis, RuntimeExecutor runtimeExecutor, jni::alias_ref componentNameResolver) - : javaPart_(jni::make_global(jThis)), - runtimeExecutor_(runtimeExecutor), + : runtimeExecutor_(std::move(runtimeExecutor)), componentNameResolver_(jni::make_global(componentNameResolver)) {} jni::local_ref @@ -32,7 +28,7 @@ ComponentNameResolverManager::initHybrid( jni::alias_ref runtimeExecutor, jni::alias_ref componentNameResolver) { return makeCxxInstance( - jThis, runtimeExecutor->cthis()->get(), componentNameResolver); + runtimeExecutor->cthis()->get(), componentNameResolver); } void ComponentNameResolverManager::registerNatives() { @@ -45,28 +41,23 @@ void ComponentNameResolverManager::registerNatives() { } void ComponentNameResolverManager::installJSIBindings() { - runtimeExecutor_([thizz = this](jsi::Runtime& runtime) { - auto viewManagerProvider = [thizz](const std::string& name) -> bool { - if (thizz->componentNames_.size() == 0) { + runtimeExecutor_([this](jsi::Runtime& runtime) { + auto viewManagerProvider = [this](const std::string& name) -> bool { + if (componentNames_.size() == 0) { static auto getComponentNames = - jni::findClassStatic(ComponentNameResolverManager:: - ComponentNameResolverJavaDescriptor) + jni::findClassStatic(ComponentNameResolverJavaDescriptor) ->getMethod>()>( "getComponentNames"); - auto componentNamesJArray = - getComponentNames(thizz->componentNameResolver_.get()); + auto componentNamesJArray = getComponentNames(componentNameResolver_); auto len = componentNamesJArray->size(); for (size_t i = 0; i < len; i++) { jni::local_ref elem = (*componentNamesJArray)[i]; - auto componentName = elem->toStdString(); - thizz->componentNames_.insert(componentName); + componentNames_.insert(elem->toStdString()); } } - - return thizz->componentNames_.find(name) != thizz->componentNames_.end(); + return componentNames_.find(name) != componentNames_.end(); }; - bindHasComponentProvider(runtime, std::move(viewManagerProvider)); }); } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.h b/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.h index db2a8fffc56187..c5462e510cb2cc 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/uimanager/ComponentNameResolverManager.h @@ -7,11 +7,10 @@ #pragma once -#include -#include +#include + #include #include -#include namespace facebook::react { @@ -21,9 +20,6 @@ class ComponentNameResolverManager static auto constexpr kJavaDescriptor = "Lcom/facebook/react/uimanager/ComponentNameResolverManager;"; - constexpr static auto ComponentNameResolverJavaDescriptor = - "com/facebook/react/uimanager/ComponentNameResolver"; - static facebook::jni::local_ref initHybrid( facebook::jni::alias_ref jThis, facebook::jni::alias_ref runtimeExecutor, @@ -33,18 +29,14 @@ class ComponentNameResolverManager private: friend HybridBase; - facebook::jni::global_ref javaPart_; - RuntimeExecutor runtimeExecutor_; + RuntimeExecutor runtimeExecutor_; facebook::jni::global_ref componentNameResolver_; - - std::set componentNames_; + std::unordered_set componentNames_; void installJSIBindings(); explicit ComponentNameResolverManager( - facebook::jni::alias_ref - jThis, RuntimeExecutor runtimeExecutor, facebook::jni::alias_ref componentNameResolver); };