Skip to content

Commit 7c4c615

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Native view configs in bridgeless mode: constantsToExport support (#39519)
Summary: Pull Request resolved: #39519 If the `constantsToExport` method is overridden by RCTViewManager subclass, we'll out those constants in "Constants" property of the view config. This diff also defines a property on UIManager for every view configs. This add support for `UIManager.RNTMyLegacyNativeView.Constants.PI` syntax in bridgeless mode. Changelog: [Internal] Differential Revision: https://internalfb.com/D49372561 fbshipit-source-id: 0ba1621e3ee4045d31a0b230a137f6b5fe0e8cb6
1 parent ea85b31 commit 7c4c615

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

packages/react-native/Libraries/ReactNative/BridgelessUIManager.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getCachedConstants(): Object {
2929
return cachedConstants;
3030
}
3131

32-
module.exports = {
32+
const UIManagerJS: {[string]: $FlowFixMe} = {
3333
getViewManagerConfig: (viewManagerName: string): mixed => {
3434
if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode()) {
3535
return getCachedConstants()[viewManagerName];
@@ -178,3 +178,11 @@ module.exports = {
178178
dismissPopupMenu: (): void =>
179179
console.error(errorMessageForMethod('dismissPopupMenu')),
180180
};
181+
182+
if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode()) {
183+
Object.keys(getCachedConstants()).forEach(viewConfigName => {
184+
UIManagerJS[viewConfigName] = getCachedConstants()[viewConfigName];
185+
});
186+
}
187+
188+
module.exports = UIManagerJS;

packages/react-native/React/Modules/RCTUIManager.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,8 +1490,7 @@ static void RCTMeasureLayout(RCTShadowView *view, RCTShadowView *ancestor, RCTRe
14901490
// New Architecture. To make native view configs work in the New Architecture we will populate these properties in
14911491
// native.
14921492
moduleConstants[@"Commands"] = viewConfig[@"Commands"];
1493-
// In the Old Architecture "Constants" are empty.
1494-
moduleConstants[@"Constants"] = [NSDictionary new];
1493+
moduleConstants[@"Constants"] = viewConfig[@"Constants"];
14951494

14961495
// Add direct events
14971496
for (NSString *eventName in viewConfig[@"directEvents"]) {

packages/react-native/React/Views/RCTComponentData.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
414414
return commands;
415415
}
416416

417+
+ (NSDictionary<NSString *, id> *)constantsForViewMangerClass:(Class)managerClass
418+
{
419+
if ([managerClass instancesRespondToSelector:@selector(constantsToExport)]) {
420+
return [[managerClass new] constantsToExport];
421+
}
422+
return @{};
423+
}
424+
417425
+ (NSDictionary<NSString *, id> *)viewConfigForViewMangerClass:(Class)managerClass
418426
{
419427
NSMutableArray<NSString *> *bubblingEvents = [NSMutableArray new];
@@ -498,6 +506,7 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
498506
@"capturingEvents" : capturingEvents,
499507
@"baseModuleName" : superClass == [NSObject class] ? (id)kCFNull : RCTViewManagerModuleNameForClass(superClass),
500508
@"Commands" : commands,
509+
@"Constants" : [self constantsForViewMangerClass:managerClass],
501510
};
502511
}
503512

0 commit comments

Comments
 (0)