Skip to content

Commit 2be9e30

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Generate public feature flags entry point (#58742)
Summary: Pull Request resolved: #58742 Adds a `dangerouslyExposeInPublicCppHeaders` option to the feature flags config. Flags that opt in are generated into `ReactNativePublicFeatureFlags.h`, whose getters forward to `ReactNativeFeatureFlags` from a generated `.cpp`, so exported headers can read them without including the rest of the module. Opts in the flags that exported headers currently read inline. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D122353811
1 parent 085caf0 commit 2be9e30

8 files changed

Lines changed: 245 additions & 1 deletion

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
* @generated SignedSource<<95f86b3476aeff097f532b10cabf067e>>
8+
*/
9+
10+
/**
11+
* IMPORTANT: Do NOT modify this file directly.
12+
*
13+
* To change the definition of the flags, edit
14+
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
15+
*
16+
* To regenerate this code, run the following script from the repo root:
17+
* yarn featureflags --update
18+
*/
19+
20+
#include "ReactNativeFeatureFlags.h"
21+
#include "ReactNativePublicFeatureFlags.h"
22+
23+
namespace facebook::react {
24+
25+
bool ReactNativeFeatureFlags_DO_NOT_USE::enableAccumulatedUpdatesInRawPropsAndroid() {
26+
return ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid();
27+
}
28+
29+
bool ReactNativeFeatureFlags_DO_NOT_USE::enableCppPropsIteratorSetter() {
30+
return ReactNativeFeatureFlags::enableCppPropsIteratorSetter();
31+
}
32+
33+
bool ReactNativeFeatureFlags_DO_NOT_USE::enableExclusivePropsUpdateAndroid() {
34+
return ReactNativeFeatureFlags::enableExclusivePropsUpdateAndroid();
35+
}
36+
37+
bool ReactNativeFeatureFlags_DO_NOT_USE::enableNativeCSSParsing() {
38+
return ReactNativeFeatureFlags::enableNativeCSSParsing();
39+
}
40+
41+
bool ReactNativeFeatureFlags_DO_NOT_USE::enablePropsUpdateReconciliationAndroid() {
42+
return ReactNativeFeatureFlags::enablePropsUpdateReconciliationAndroid();
43+
}
44+
45+
bool ReactNativeFeatureFlags_DO_NOT_USE::useSharedAnimatedBackend() {
46+
return ReactNativeFeatureFlags::useSharedAnimatedBackend();
47+
}
48+
49+
} // namespace facebook::react
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
* @generated SignedSource<<39037a69a47b86d0c6643d90f4058002>>
8+
*/
9+
10+
/**
11+
* IMPORTANT: Do NOT modify this file directly.
12+
*
13+
* To change the definition of the flags, edit
14+
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
15+
*
16+
* To regenerate this code, run the following script from the repo root:
17+
* yarn featureflags --update
18+
*/
19+
20+
#pragma once
21+
22+
#include <string>
23+
24+
#ifndef RN_EXPORT
25+
#define RN_EXPORT __attribute__((visibility("default")))
26+
#endif
27+
28+
namespace facebook::react {
29+
30+
/**
31+
* This class provides public access to select internal React Native feature flags.
32+
*/
33+
class ReactNativeFeatureFlags_DO_NOT_USE {
34+
public:
35+
/**
36+
* When enabled, Android will accumulate updates in rawProps to reduce the number of mounting instructions for cascading re-renders.
37+
*/
38+
RN_EXPORT static bool enableAccumulatedUpdatesInRawPropsAndroid();
39+
40+
/**
41+
* Enable prop iterator setter-style construction of Props in C++ (this flag is not used in Java).
42+
*/
43+
RN_EXPORT static bool enableCppPropsIteratorSetter();
44+
45+
/**
46+
* When enabled, Android will disable Props 1.5 raw value merging when Props 2.0 is available.
47+
*/
48+
RN_EXPORT static bool enableExclusivePropsUpdateAndroid();
49+
50+
/**
51+
* Parse CSS strings using the Fabric CSS parser instead of ViewConfig processing
52+
*/
53+
RN_EXPORT static bool enableNativeCSSParsing();
54+
55+
/**
56+
* When enabled, Android will receive prop updates based on the differences between the last rendered shadow node and the last committed shadow node.
57+
*/
58+
RN_EXPORT static bool enablePropsUpdateReconciliationAndroid();
59+
60+
/**
61+
* Use shared animation backend in C++ Animated
62+
*/
63+
RN_EXPORT static bool useSharedAnimatedBackend();
64+
};
65+
66+
} // namespace facebook::react

‎packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const definitions: FeatureFlagDefinitions = {
181181
ossReleaseStage: 'canary',
182182
},
183183
enableAccumulatedUpdatesInRawPropsAndroid: {
184+
dangerouslyExposeInPublicCppHeaders: true,
184185
defaultValue: false,
185186
metadata: {
186187
dateAdded: '2024-12-10',
@@ -233,6 +234,7 @@ const definitions: FeatureFlagDefinitions = {
233234
ossReleaseStage: 'none',
234235
},
235236
enableCppPropsIteratorSetter: {
237+
dangerouslyExposeInPublicCppHeaders: true,
236238
defaultValue: false,
237239
metadata: {
238240
dateAdded: '2024-09-13',
@@ -287,6 +289,7 @@ const definitions: FeatureFlagDefinitions = {
287289
ossReleaseStage: 'none',
288290
},
289291
enableExclusivePropsUpdateAndroid: {
292+
dangerouslyExposeInPublicCppHeaders: true,
290293
defaultValue: false,
291294
metadata: {
292295
dateAdded: '2025-11-11',
@@ -517,6 +520,7 @@ const definitions: FeatureFlagDefinitions = {
517520
ossReleaseStage: 'none',
518521
},
519522
enableNativeCSSParsing: {
523+
dangerouslyExposeInPublicCppHeaders: true,
520524
defaultValue: false,
521525
metadata: {
522526
dateAdded: '2025-02-07',
@@ -538,6 +542,7 @@ const definitions: FeatureFlagDefinitions = {
538542
ossReleaseStage: 'none',
539543
},
540544
enablePropsUpdateReconciliationAndroid: {
545+
dangerouslyExposeInPublicCppHeaders: true,
541546
defaultValue: false,
542547
metadata: {
543548
dateAdded: '2024-07-12',
@@ -923,6 +928,7 @@ const definitions: FeatureFlagDefinitions = {
923928
ossReleaseStage: 'none',
924929
},
925930
useSharedAnimatedBackend: {
931+
dangerouslyExposeInPublicCppHeaders: true,
926932
defaultValue: false,
927933
metadata: {
928934
dateAdded: '2025-08-02',

‎packages/react-native/scripts/featureflags/generateCommonCxxModules.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import ReactNativeFeatureFlagsDefaultsH from './templates/common-cxx/ReactNative
1818
import ReactNativeFeatureFlagsDynamicProviderH from './templates/common-cxx/ReactNativeFeatureFlagsDynamicProvider.h-template';
1919
import ReactNativeFeatureFlagsOverrides from './templates/common-cxx/ReactNativeFeatureFlagsOverridesOSS_Stage_.h-template';
2020
import ReactNativeFeatureFlagsProviderH from './templates/common-cxx/ReactNativeFeatureFlagsProvider.h-template';
21+
import ReactNativePublicFeatureFlagsCPP from './templates/common-cxx/ReactNativePublicFeatureFlags.cpp-template';
22+
import ReactNativePublicFeatureFlagsH from './templates/common-cxx/ReactNativePublicFeatureFlags.h-template';
2123
import path from 'node:path';
2224

2325
export default function generateCommonCxxModules(
@@ -30,6 +32,10 @@ export default function generateCommonCxxModules(
3032
ReactNativeFeatureFlagsH(featureFlagDefinitions),
3133
[path.join(commonCxxPath, 'ReactNativeFeatureFlags.cpp')]:
3234
ReactNativeFeatureFlagsCPP(featureFlagDefinitions),
35+
[path.join(commonCxxPath, 'ReactNativePublicFeatureFlags.h')]:
36+
ReactNativePublicFeatureFlagsH(featureFlagDefinitions),
37+
[path.join(commonCxxPath, 'ReactNativePublicFeatureFlags.cpp')]:
38+
ReactNativePublicFeatureFlagsCPP(featureFlagDefinitions),
3339
[path.join(commonCxxPath, 'ReactNativeFeatureFlagsAccessor.h')]:
3440
ReactNativeFeatureFlagsAccessorH(featureFlagDefinitions),
3541
[path.join(commonCxxPath, 'ReactNativeFeatureFlagsAccessor.cpp')]:

‎packages/react-native/scripts/featureflags/generateFiles.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ export default function generateFiles(
3434
...generatorConfig.featureFlagDefinitions,
3535
common: Object.fromEntries(
3636
Object.entries(generatorConfig.featureFlagDefinitions.common).filter(
37-
([_, definition]) => !definition.skipNativeAPI,
37+
([name, definition]) => {
38+
if (
39+
definition.skipNativeAPI &&
40+
definition.dangerouslyExposeInPublicCppHeaders
41+
) {
42+
throw new Error(
43+
`${name} cannot have both skipNativeAPI and dangerouslyExposeInPublicCppHeaders enabled at the same time.`,
44+
);
45+
}
46+
47+
return !definition.skipNativeAPI;
48+
},
3849
),
3950
),
4051
},
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
* @flow strict
8+
* @format
9+
*/
10+
11+
import type {FeatureFlagDefinitions} from '../../types';
12+
13+
import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils';
14+
import signedsource from 'signedsource';
15+
16+
export default function (definitions: FeatureFlagDefinitions): string {
17+
return signedsource.signFile(`/*
18+
* Copyright (c) Meta Platforms, Inc. and affiliates.
19+
*
20+
* This source code is licensed under the MIT license found in the
21+
* LICENSE file in the root directory of this source tree.
22+
*
23+
* ${signedsource.getSigningToken()}
24+
*/
25+
26+
${DO_NOT_MODIFY_COMMENT}
27+
28+
#include "ReactNativeFeatureFlags.h"
29+
#include "ReactNativePublicFeatureFlags.h"
30+
31+
namespace facebook::react {
32+
33+
${Object.entries(definitions.common)
34+
.filter(([_, flagConfig]) => flagConfig.dangerouslyExposeInPublicCppHeaders)
35+
.map(
36+
([flagName, flagConfig]) =>
37+
`${getCxxTypeFromDefaultValue(
38+
flagConfig.defaultValue,
39+
)} ReactNativeFeatureFlags_DO_NOT_USE::${flagName}() {
40+
return ReactNativeFeatureFlags::${flagName}();
41+
}`,
42+
)
43+
.join('\n\n')}
44+
45+
} // namespace facebook::react
46+
`);
47+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
* @flow strict
8+
* @format
9+
*/
10+
11+
import type {FeatureFlagDefinitions} from '../../types';
12+
13+
import {DO_NOT_MODIFY_COMMENT, getCxxTypeFromDefaultValue} from '../../utils';
14+
import signedsource from 'signedsource';
15+
16+
export default function (definitions: FeatureFlagDefinitions): string {
17+
return signedsource.signFile(`/*
18+
* Copyright (c) Meta Platforms, Inc. and affiliates.
19+
*
20+
* This source code is licensed under the MIT license found in the
21+
* LICENSE file in the root directory of this source tree.
22+
*
23+
* ${signedsource.getSigningToken()}
24+
*/
25+
26+
${DO_NOT_MODIFY_COMMENT}
27+
28+
#pragma once
29+
30+
#include <string>
31+
32+
#ifndef RN_EXPORT
33+
#define RN_EXPORT __attribute__((visibility("default")))
34+
#endif
35+
36+
namespace facebook::react {
37+
38+
/**
39+
* This class provides public access to select internal React Native feature flags.
40+
*/
41+
class ReactNativeFeatureFlags_DO_NOT_USE {
42+
public:
43+
${Object.entries(definitions.common)
44+
.filter(([_, flagConfig]) => flagConfig.dangerouslyExposeInPublicCppHeaders)
45+
.map(
46+
([flagName, flagConfig]) =>
47+
` /**
48+
* ${flagConfig.metadata.description}
49+
*/
50+
RN_EXPORT static ${getCxxTypeFromDefaultValue(flagConfig.defaultValue)} ${flagName}();`,
51+
)
52+
.join('\n\n')}
53+
};
54+
55+
} // namespace facebook::react
56+
`);
57+
}

‎packages/react-native/scripts/featureflags/types.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export type CommonFeatureFlagConfig<
3434
// Indicates if this API should only be defined in JavaScript, only to
3535
// preserve backwards compatibility with existing native code temporarily.
3636
skipNativeAPI?: true,
37+
// Whether this flag should be exposed by the public feature flags entrypoint.
38+
dangerouslyExposeInPublicCppHeaders?: true,
3739
}>;
3840

3941
export type CommonFeatureFlagList = Readonly<{

0 commit comments

Comments
 (0)