Skip to content

Commit a9618b3

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Expose UIManager.getConstants instead of getNativeViewConfig to JS in bridgeless mode (#37865)
Summary: Pull Request resolved: #37865 In bridge mode UIManager's `constants` contain view configs for every registered native component and possibly some extra data. On iOS there is no extra data, but on Android in addition to view configs there are `genericBubblingEventTypes` and `genericDirectEventTypes`. They are then [merged](https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js#L110-L116) into `bubblingEventTypes` and `directEventTypes` of every view config. This diff replaces `getNativeViewConfig` binding with `getConstants` to make this behaviour possible in the bridgeless mode. This diff also removes caching on native side with the expectation that `constants` will be cached on JS side just as [it is done](https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/ReactNative/PaperUIManager.js#L24-L32) in bridge mode. Changelog: [Internal] - Expose UIManager.getConstants instead of getNativeViewConfig to JS in bridgeless mode. Reviewed By: RSNara Differential Revision: D46698717 fbshipit-source-id: f9c96e220e49f6947766336ea545c01e38cb46ac
1 parent c803a5b commit a9618b3

File tree

8 files changed

+95
-105
lines changed

8 files changed

+95
-105
lines changed

packages/react-native/ReactCommon/react/bridgeless/nativeviewconfig/NativeViewConfigProviderBinding.cpp renamed to packages/react-native/ReactCommon/react/bridgeless/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include "NativeViewConfigProviderBinding.h"
8+
#include "LegacyUIManagerConstantsProviderBinding.h"
99

10-
namespace facebook::react::NativeViewConfigProviderBinding {
10+
namespace facebook::react::LegacyUIManagerConstantsProviderBinding {
1111

1212
void install(jsi::Runtime &runtime, ProviderType &&provider) {
13-
auto name = "RN$NativeComponentRegistry_getNativeViewConfig";
13+
auto name = "RN$LegacyInterop_UIManager_getConstants";
1414
auto hostFunction = [provider = std::move(provider)](
1515
jsi::Runtime &runtime,
1616
jsi::Value const & /*thisValue*/,
17-
jsi::Value const *args,
17+
jsi::Value const * /*arguments*/,
1818
size_t count) -> jsi::Value {
19-
if (count != 1 || !args[0].isString()) {
20-
throw new jsi::JSError(runtime, "1 argument of type String expected.");
19+
if (count != 0) {
20+
throw new jsi::JSError(runtime, "0 arguments expected.");
2121
}
22-
return provider(args[0].getString(runtime).utf8(runtime));
22+
return provider();
2323
};
2424

2525
auto jsiFunction = jsi::Function::createFromHostFunction(
2626
runtime, jsi::PropNameID::forAscii(runtime, name), 2, hostFunction);
2727

2828
runtime.global().setProperty(runtime, name, jsiFunction);
2929
}
30-
} // namespace facebook::react::NativeViewConfigProviderBinding
30+
} // namespace facebook::react::LegacyUIManagerConstantsProviderBinding
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <jsi/jsi.h>
11+
12+
namespace facebook::react::LegacyUIManagerConstantsProviderBinding {
13+
14+
using ProviderType = std::function<jsi::Value()>;
15+
16+
/*
17+
* Installs RN$LegacyInterop_UIManager_getConstants binding into JavaScript
18+
* runtime. It is supposed to be used as a substitute to UIManager.getConstants
19+
* in bridgeless mode.
20+
*/
21+
void install(jsi::Runtime &runtime, ProviderType &&provider);
22+
} // namespace facebook::react::LegacyUIManagerConstantsProviderBinding

packages/react-native/ReactCommon/react/bridgeless/nativeviewconfig/NativeViewConfigProviderBinding.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#import <React/RCTModuleData.h>
2929
#import <React/RCTPerformanceLogger.h>
3030
#import <React/RCTSurfacePresenter.h>
31-
#import <ReactCommon/RCTNativeViewConfigProvider.h>
31+
#import <ReactCommon/RCTLegacyUIManagerConstantsProvider.h>
3232
#import <ReactCommon/RCTTurboModuleManager.h>
3333
#import <ReactCommon/RuntimeExecutor.h>
3434
#import <cxxreact/ReactMarker.h>
@@ -296,7 +296,7 @@ - (void)_start
296296
RCTInstallNativeComponentRegistryBinding(runtime);
297297

298298
if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
299-
installNativeViewConfigProviderBinding(runtime);
299+
installLegacyUIManagerConstantsProviderBinding(runtime);
300300
}
301301

302302
[strongSelf->_delegate instance:strongSelf didInitializeRuntime:runtime];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <jsi/jsi.h>
11+
12+
namespace facebook::react {
13+
/*
14+
* Installs UIManger constants provider into JavaScript runtime. This is needed
15+
* to implement UIManager.getConstants in bridgeless mode. The constants object
16+
* contains view configs for every legacy native component.
17+
*/
18+
void installLegacyUIManagerConstantsProviderBinding(jsi::Runtime &runtime);
19+
} // namespace facebook::react
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "RCTLegacyUIManagerConstantsProvider.h"
9+
10+
#import <React/RCTBridge+Private.h>
11+
#import <React/RCTComponentData.h>
12+
#import <React/RCTUIManager.h>
13+
#import <React/RCTViewManager.h>
14+
#import <ReactCommon/RCTTurboModule.h>
15+
#import <react/bridgeless/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.h>
16+
17+
namespace facebook::react {
18+
namespace {
19+
20+
jsi::Value getConstants(facebook::jsi::Runtime &runtime)
21+
{
22+
static NSMutableDictionary<NSString *, NSObject *> *result = [NSMutableDictionary new];
23+
auto directEvents = [NSMutableDictionary new];
24+
auto bubblingEvents = [NSMutableDictionary new];
25+
for (Class moduleClass in RCTGetModuleClasses()) {
26+
if ([moduleClass isSubclassOfClass:RCTViewManager.class]) {
27+
auto name = RCTViewManagerModuleNameForClass(moduleClass);
28+
auto viewConfig = [RCTComponentData viewConfigForViewMangerClass:moduleClass];
29+
auto moduleConstants =
30+
RCTModuleConstantsForDestructuredComponent(directEvents, bubblingEvents, moduleClass, name, viewConfig);
31+
result[name] = moduleConstants;
32+
}
33+
}
34+
return TurboModuleConvertUtils::convertObjCObjectToJSIValue(runtime, result);
35+
};
36+
37+
} // namespace
38+
39+
void installLegacyUIManagerConstantsProviderBinding(jsi::Runtime &runtime)
40+
{
41+
auto constantsProvider = [&runtime]() -> jsi::Value { return getConstants(runtime); };
42+
LegacyUIManagerConstantsProviderBinding::install(runtime, std::move(constantsProvider));
43+
}
44+
} // namespace facebook::react

packages/react-native/ReactCommon/react/bridgeless/platform/ios/NativeViewConfig/RCTNativeViewConfigProvider.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/react-native/ReactCommon/react/bridgeless/platform/ios/NativeViewConfig/RCTNativeViewConfigProvider.mm

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)