Files
react-native/packages/react-native/ReactCommon/react/bridgeless/nativeviewconfig/NativeViewConfigProviderBinding.cpp
T
Dmitry Rykun 7f22db8ea0 Introduce __nativeComponentRegistry__getNativeViewConfig (#37522)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37522

This diff adds cross-platform Cxx binding helper and iOS specific implementation of `__nativeComponentRegistry__getNativeViewConfig` to JS runtime. This function provides native view config for a native component in bridgeless mode.

Changelog:
[Internal] - Introduce `__nativeComponentRegistry__getNativeViewConfig` in iOS.

Reviewed By: javache

Differential Revision: D43538804

fbshipit-source-id: 0aeca40c1c2a625eca5d60e466eb24df30453ba7
2023-05-30 08:04:23 -07:00

31 lines
1.1 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 "NativeViewConfigProviderBinding.h"
namespace facebook::react::NativeViewConfigProviderBinding {
void install(jsi::Runtime &runtime, ProviderType &&provider) {
auto name = "RN$NativeComponentRegistry_getNativeViewConfig";
auto hostFunction = [provider = std::move(provider)](
jsi::Runtime &runtime,
jsi::Value const & /*thisValue*/,
jsi::Value const *args,
size_t count) -> jsi::Value {
if (count != 1 || !args[0].isString()) {
throw new jsi::JSError(runtime, "1 argument of type String expected.");
}
return provider(args[0].getString(runtime).utf8(runtime));
};
auto jsiFunction = jsi::Function::createFromHostFunction(
runtime, jsi::PropNameID::forAscii(runtime, name), 2, hostFunction);
runtime.global().setProperty(runtime, name, jsiFunction);
}
} // namespace facebook::react::NativeViewConfigProviderBinding