-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
c803a5b
commit a9618b3
Showing
8 changed files
with
95 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...e/ReactCommon/react/bridgeless/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <jsi/jsi.h> | ||
|
||
namespace facebook::react::LegacyUIManagerConstantsProviderBinding { | ||
|
||
using ProviderType = std::function<jsi::Value()>; | ||
|
||
/* | ||
* Installs RN$LegacyInterop_UIManager_getConstants binding into JavaScript | ||
* runtime. It is supposed to be used as a substitute to UIManager.getConstants | ||
* in bridgeless mode. | ||
*/ | ||
void install(jsi::Runtime &runtime, ProviderType &&provider); | ||
} // namespace facebook::react::LegacyUIManagerConstantsProviderBinding |
20 changes: 0 additions & 20 deletions
20
...ct-native/ReactCommon/react/bridgeless/nativeviewconfig/NativeViewConfigProviderBinding.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...mmon/react/bridgeless/platform/ios/NativeViewConfig/RCTLegacyUIManagerConstantsProvider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <jsi/jsi.h> | ||
|
||
namespace facebook::react { | ||
/* | ||
* Installs UIManger constants provider into JavaScript runtime. This is needed | ||
* to implement UIManager.getConstants in bridgeless mode. The constants object | ||
* contains view configs for every legacy native component. | ||
*/ | ||
void installLegacyUIManagerConstantsProviderBinding(jsi::Runtime &runtime); | ||
} // namespace facebook::react |
44 changes: 44 additions & 0 deletions
44
...mon/react/bridgeless/platform/ios/NativeViewConfig/RCTLegacyUIManagerConstantsProvider.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 "RCTLegacyUIManagerConstantsProvider.h" | ||
|
||
#import <React/RCTBridge+Private.h> | ||
#import <React/RCTComponentData.h> | ||
#import <React/RCTUIManager.h> | ||
#import <React/RCTViewManager.h> | ||
#import <ReactCommon/RCTTurboModule.h> | ||
#import <react/bridgeless/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.h> | ||
|
||
namespace facebook::react { | ||
namespace { | ||
|
||
jsi::Value getConstants(facebook::jsi::Runtime &runtime) | ||
{ | ||
static NSMutableDictionary<NSString *, NSObject *> *result = [NSMutableDictionary new]; | ||
auto directEvents = [NSMutableDictionary new]; | ||
auto bubblingEvents = [NSMutableDictionary new]; | ||
for (Class moduleClass in RCTGetModuleClasses()) { | ||
if ([moduleClass isSubclassOfClass:RCTViewManager.class]) { | ||
auto name = RCTViewManagerModuleNameForClass(moduleClass); | ||
auto viewConfig = [RCTComponentData viewConfigForViewMangerClass:moduleClass]; | ||
auto moduleConstants = | ||
RCTModuleConstantsForDestructuredComponent(directEvents, bubblingEvents, moduleClass, name, viewConfig); | ||
result[name] = moduleConstants; | ||
} | ||
} | ||
return TurboModuleConvertUtils::convertObjCObjectToJSIValue(runtime, result); | ||
}; | ||
|
||
} // namespace | ||
|
||
void installLegacyUIManagerConstantsProviderBinding(jsi::Runtime &runtime) | ||
{ | ||
auto constantsProvider = [&runtime]() -> jsi::Value { return getConstants(runtime); }; | ||
LegacyUIManagerConstantsProviderBinding::install(runtime, std::move(constantsProvider)); | ||
} | ||
} // namespace facebook::react |
17 changes: 0 additions & 17 deletions
17
.../ReactCommon/react/bridgeless/platform/ios/NativeViewConfig/RCTNativeViewConfigProvider.h
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
...ReactCommon/react/bridgeless/platform/ios/NativeViewConfig/RCTNativeViewConfigProvider.mm
This file was deleted.
Oops, something went wrong.