Skip to content

Commit 60bd497

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Native view configs in bridgeless mode: constantsToExport support
Summary: 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: D49372561 fbshipit-source-id: 9af8b1ed7d824a323360c4351bec4b151ded6b2b
1 parent 8498976 commit 60bd497

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import type {RootTag} from '../Types/RootTagTypes';
1414

1515
import {unstable_hasComponent} from '../NativeComponent/NativeComponentRegistryUnstable';
16+
import NativeUIManager from './NativeUIManager';
1617
import ReactNativeFeatureFlags from './ReactNativeFeatureFlags';
1718

1819
let cachedConstants = null;
@@ -29,7 +30,11 @@ function getCachedConstants(): Object {
2930
return cachedConstants;
3031
}
3132

32-
module.exports = {
33+
/* $FlowFixMe[cannot-spread-interface] (>=0.123.0 site=react_native_fb) This
34+
* comment suppresses an error found when Flow v0.123.0 was deployed. To see
35+
* the error, delete this comment and run Flow. */
36+
const UIManagerJS = {
37+
...NativeUIManager,
3338
getViewManagerConfig: (viewManagerName: string): mixed => {
3439
if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode()) {
3540
return getCachedConstants()[viewManagerName];
@@ -178,3 +183,9 @@ module.exports = {
178183
dismissPopupMenu: (): void =>
179184
console.error(errorMessageForMethod('dismissPopupMenu')),
180185
};
186+
187+
for (const viewConfigName: string in getCachedConstants()) {
188+
UIManagerJS[viewConfigName] = getCachedConstants()[viewConfigName];
189+
}
190+
191+
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)