Skip to content

Commit a13be46

Browse files
jorge-cabgabrieldonadel
authored andcommitted
Add prerelease staging API for Android (facebook#49649)
Summary: Pull Request resolved: facebook#49649 - Added a new template to React Native's Feature Flag's script for Canary and Experimental prerelease stages - Added a parameter to `DefaultNewArchitectureEntryPoint.kt` to select prerelease stage Changelog: [Android] [Added] - On `DefaultNewArchitectureEntryPoint` class add property to specify the desired release level for an application Reviewed By: rubennorte, mdvacca Differential Revision: D69412971 fbshipit-source-id: 1a76ac723e1e06b40aad5910604e0384b208d3a5
1 parent 595e2e4 commit a13be46

File tree

8 files changed

+208
-9
lines changed

8 files changed

+208
-9
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,15 @@ public final class com/facebook/react/common/ReactConstants {
17471747
public static final field UNSET I
17481748
}
17491749

1750+
public final class com/facebook/react/common/ReleaseLevel : java/lang/Enum {
1751+
public static final field CANARY Lcom/facebook/react/common/ReleaseLevel;
1752+
public static final field EXPERIMENTAL Lcom/facebook/react/common/ReleaseLevel;
1753+
public static final field STABLE Lcom/facebook/react/common/ReleaseLevel;
1754+
public static fun getEntries ()Lkotlin/enums/EnumEntries;
1755+
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/common/ReleaseLevel;
1756+
public static fun values ()[Lcom/facebook/react/common/ReleaseLevel;
1757+
}
1758+
17501759
public final class com/facebook/react/common/ShakeDetector : android/hardware/SensorEventListener {
17511760
public fun <init> (Lcom/facebook/react/common/ShakeDetector$ShakeListener;)V
17521761
public fun <init> (Lcom/facebook/react/common/ShakeDetector$ShakeListener;I)V
@@ -1940,12 +1949,14 @@ public final class com/facebook/react/defaults/DefaultNewArchitectureEntryPoint
19401949
public static final fun getBridgelessEnabled ()Z
19411950
public static final fun getConcurrentReactEnabled ()Z
19421951
public static final fun getFabricEnabled ()Z
1952+
public final fun getReleaseLevel ()Lcom/facebook/react/common/ReleaseLevel;
19431953
public static final fun getTurboModulesEnabled ()Z
19441954
public static final fun load ()V
19451955
public static final fun load (Z)V
19461956
public static final fun load (ZZ)V
19471957
public static final fun load (ZZZ)V
19481958
public static synthetic fun load$default (ZZZILjava/lang/Object;)V
1959+
public final fun setReleaseLevel (Lcom/facebook/react/common/ReleaseLevel;)V
19491960
}
19501961

19511962
public class com/facebook/react/defaults/DefaultReactActivityDelegate : com/facebook/react/ReactActivityDelegate {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
package com.facebook.react.common
9+
10+
/**
11+
* This enum is used to determine the release level of a React Native application, which is then
12+
* used to determine what React Native Features will be enabled in the application.
13+
*/
14+
public enum class ReleaseLevel {
15+
EXPERIMENTAL,
16+
CANARY,
17+
STABLE
18+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
package com.facebook.react.defaults
1111

12+
import com.facebook.react.common.ReleaseLevel
1213
import com.facebook.react.common.annotations.VisibleForTesting
1314
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
14-
import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlagsDefaults
15+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android
16+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android
17+
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android
1518

1619
/**
1720
* A utility class that serves as an entry point for users setup the New Architecture.
@@ -26,6 +29,9 @@ import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatur
2629
* Bridgeless
2730
*/
2831
public object DefaultNewArchitectureEntryPoint {
32+
33+
public var releaseLevel: ReleaseLevel = ReleaseLevel.STABLE
34+
2935
@JvmStatic
3036
@JvmOverloads
3137
public fun load(
@@ -39,14 +45,20 @@ public object DefaultNewArchitectureEntryPoint {
3945
error(errorMessage)
4046
}
4147

42-
ReactNativeFeatureFlags.override(
43-
object : ReactNativeNewArchitectureFeatureFlagsDefaults(bridgelessEnabled) {
44-
override fun useFabricInterop(): Boolean = bridgelessEnabled || fabricEnabled
45-
46-
override fun enableFabricRenderer(): Boolean = bridgelessEnabled || fabricEnabled
47-
48-
override fun useTurboModules(): Boolean = bridgelessEnabled || turboModulesEnabled
49-
})
48+
when (releaseLevel) {
49+
ReleaseLevel.EXPERIMENTAL -> {
50+
ReactNativeFeatureFlags.override(
51+
ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android())
52+
}
53+
ReleaseLevel.CANARY -> {
54+
ReactNativeFeatureFlags.override(ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android())
55+
}
56+
ReleaseLevel.STABLE -> {
57+
ReactNativeFeatureFlags.override(
58+
ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android(
59+
fabricEnabled, bridgelessEnabled, turboModulesEnabled))
60+
}
61+
}
5062

5163
privateFabricEnabled = fabricEnabled
5264
privateTurboModulesEnabled = turboModulesEnabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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<<04b05f74eacf566f99d00c630dcb61f4>>
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+
package com.facebook.react.internal.featureflags
21+
22+
public open class ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android : ReactNativeFeatureFlagsDefaults() {
23+
// We could use JNI to get the defaults from C++,
24+
// but that is more expensive than just duplicating the defaults here.
25+
26+
override fun enableBridgelessArchitecture(): Boolean = true
27+
28+
override fun enableFabricRenderer(): Boolean = true
29+
30+
override fun useFabricInterop(): Boolean = true
31+
32+
override fun useNativeViewConfigsInBridgelessMode(): Boolean = true
33+
34+
override fun useTurboModuleInterop(): Boolean = true
35+
36+
override fun useTurboModules(): Boolean = true
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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<<c8b19934d19d6b4514a0395edecb1330>>
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+
package com.facebook.react.internal.featureflags
21+
22+
public open class ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android : ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android() {
23+
// We could use JNI to get the defaults from C++,
24+
// but that is more expensive than just duplicating the defaults here.
25+
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
package com.facebook.react.internal.featureflags
9+
10+
public class ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android(
11+
private val fabricEnabled: Boolean,
12+
private val bridgelessEnabled: Boolean,
13+
private val turboModulesEnabled: Boolean
14+
) : ReactNativeNewArchitectureFeatureFlagsDefaults(bridgelessEnabled) {
15+
override fun useFabricInterop(): Boolean = bridgelessEnabled || fabricEnabled
16+
17+
override fun enableFabricRenderer(): Boolean = bridgelessEnabled || fabricEnabled
18+
19+
override fun useTurboModules(): Boolean = bridgelessEnabled || turboModulesEnabled
20+
}

packages/react-native/scripts/featureflags/generateAndroidModules.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ReactNativeFeatureFlagsCxxAccessorKt from './templates/android/ReactNativ
1717
import ReactNativeFeatureFlagsCxxInteropKt from './templates/android/ReactNativeFeatureFlagsCxxInterop.kt-template';
1818
import ReactNativeFeatureFlagsDefaultsKt from './templates/android/ReactNativeFeatureFlagsDefaults.kt-template';
1919
import ReactNativeFeatureFlagsLocalAccessorKt from './templates/android/ReactNativeFeatureFlagsLocalAccessor.kt-template';
20+
import ReactNativeFeatureFlagsOverrides from './templates/android/ReactNativeFeatureFlagsOverrides_RNOSS__Stage__Android.kt-template.js';
2021
import ReactNativeFeatureFlagsProviderKt from './templates/android/ReactNativeFeatureFlagsProvider.kt-template';
2122
import path from 'path';
2223

@@ -36,6 +37,17 @@ export default function generateAndroidModules(
3637
ReactNativeFeatureFlagsCxxInteropKt(featureFlagDefinitions),
3738
[path.join(androidPath, 'ReactNativeFeatureFlagsDefaults.kt')]:
3839
ReactNativeFeatureFlagsDefaultsKt(featureFlagDefinitions),
40+
[path.join(
41+
androidPath,
42+
'ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android.kt',
43+
)]: ReactNativeFeatureFlagsOverrides(
44+
featureFlagDefinitions,
45+
'experimental',
46+
),
47+
[path.join(
48+
androidPath,
49+
'ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android.kt',
50+
)]: ReactNativeFeatureFlagsOverrides(featureFlagDefinitions, 'canary'),
3951
[path.join(androidPath, 'ReactNativeFeatureFlagsProvider.kt')]:
4052
ReactNativeFeatureFlagsProviderKt(featureFlagDefinitions),
4153
[path.join(androidJniPath, 'JReactNativeFeatureFlagsCxxInterop.h')]:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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, OSSReleaseStageValue} from '../../types';
12+
13+
import {
14+
DO_NOT_MODIFY_COMMENT,
15+
getKotlinTypeFromDefaultValue,
16+
} from '../../utils';
17+
import signedsource from 'signedsource';
18+
19+
function getClassSignature(ossReleaseStage: OSSReleaseStageValue): string {
20+
if (ossReleaseStage === 'experimental') {
21+
return 'ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android : ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android()';
22+
} else if (ossReleaseStage === 'canary') {
23+
return 'ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android : ReactNativeFeatureFlagsDefaults()';
24+
}
25+
26+
return 'ReactNativeFeatureFlagsOverrides_RNOSS_Stable_Android : ReactNativeFeatureFlagsProvider';
27+
}
28+
29+
export default function (
30+
definitions: FeatureFlagDefinitions,
31+
ossReleaseStage: OSSReleaseStageValue,
32+
): string {
33+
return signedsource.signFile(`/*
34+
* Copyright (c) Meta Platforms, Inc. and affiliates.
35+
*
36+
* This source code is licensed under the MIT license found in the
37+
* LICENSE file in the root directory of this source tree.
38+
*
39+
* ${signedsource.getSigningToken()}
40+
*/
41+
42+
${DO_NOT_MODIFY_COMMENT}
43+
44+
package com.facebook.react.internal.featureflags
45+
46+
public open class ${getClassSignature(ossReleaseStage)} {
47+
// We could use JNI to get the defaults from C++,
48+
// but that is more expensive than just duplicating the defaults here.
49+
50+
${Object.entries(definitions.common)
51+
.map(([flagName, flagConfig]) => {
52+
if (flagConfig.ossReleaseStage === ossReleaseStage) {
53+
return ` override fun ${flagName}(): ${getKotlinTypeFromDefaultValue(
54+
flagConfig.metadata.expectedReleaseValue,
55+
)} = ${JSON.stringify(flagConfig.metadata.expectedReleaseValue)}`;
56+
}
57+
})
58+
.filter(Boolean)
59+
.join('\n\n')}
60+
}
61+
`);
62+
}

0 commit comments

Comments
 (0)