Files
react-native/ReactCommon/react/renderer/componentregistry/native/NativeComponentRegistryBinding.cpp
T
Samuel Susla 51af7cdcde Use nested namespace name
Summary:
changelog: [internal]

Enable two new clang tidy checks:
- modernize-concat-nested-namespaces
- google-build-using-namespace

jest_e2e[run_all_tests]

Reviewed By: rshest

Differential Revision: D40020646

fbshipit-source-id: f3be80b5f829dd0ba376bdd70ed13332e114d48a
2022-10-13 05:07:59 -07:00

67 lines
1.9 KiB
C++

/*
* 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.
*/
#include "NativeComponentRegistryBinding.h"
#include <stdexcept>
#include <string>
using namespace facebook;
namespace facebook::react {
/**
* Public API to install the NativeComponentRegistryBinding.
*/
NativeComponentRegistryBinding::NativeComponentRegistryBinding(
const HasComponentProviderFunctionType &&hasComponentProvider)
: hasComponentProvider_(hasComponentProvider) {}
void NativeComponentRegistryBinding::install(
jsi::Runtime &runtime,
const HasComponentProviderFunctionType &&hasComponentProvider) {
runtime.global().setProperty(
runtime,
"__nativeComponentRegistry__hasComponent",
jsi::Function::createFromHostFunction(
runtime,
jsi::PropNameID::forAscii(
runtime, "__nativeComponentRegistry__hasComponent"),
1,
[binding = std::make_shared<NativeComponentRegistryBinding>(
std::move(hasComponentProvider))](
jsi::Runtime &rt,
const jsi::Value &thisVal,
const jsi::Value *args,
size_t count) {
return binding->jsProxy(rt, thisVal, args, count);
}));
}
bool NativeComponentRegistryBinding::hasComponent(const std::string &name) {
return hasComponentProvider_(name);
}
jsi::Value NativeComponentRegistryBinding::jsProxy(
jsi::Runtime &runtime,
const jsi::Value & /*thisVal*/,
const jsi::Value *args,
size_t count) {
if (count != 1) {
throw std::invalid_argument(
"__nativeComponentRegistry__hasComponent must be called with 1 argument");
}
std::string moduleName = args[0].getString(runtime).utf8(runtime);
jsi::Value nullSchema = jsi::Value::undefined();
bool result = hasComponent(moduleName);
return {result};
}
} // namespace facebook::react