forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back out "Back out "[RN] Implement new feature flag system""
Summary: Original commit changeset: ace1222a861a Original Phabricator Diff: D53113947 Differential Revision: D53122992 fbshipit-source-id: 0713636c288bb8279e6a5822036b58c7caa96a4e
- Loading branch information
1 parent
5f75e9b
commit 1c23e45
Showing
73 changed files
with
3,140 additions
and
4 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
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
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
78 changes: 78 additions & 0 deletions
78
...Android/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt
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,78 @@ | ||
/* | ||
* 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. | ||
* | ||
* @generated SignedSource<<c201b2b577ab4aa4bf6071d6b99b43c9>> | ||
*/ | ||
|
||
/** | ||
* IMPORTANT: Do NOT modify this file directly. | ||
* | ||
* To change the definition of the flags, edit | ||
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. | ||
* | ||
* To regenerate this code, run the following script from the repo root: | ||
* yarn featureflags-update | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
/** | ||
* This object provides access to internal React Native feature flags. | ||
* | ||
* All the methods are thread-safe if you handle `override` correctly. | ||
*/ | ||
object ReactNativeFeatureFlags { | ||
private var accessorProvider: () -> ReactNativeFeatureFlagsAccessor = { ReactNativeFeatureFlagsCxxAccessor() } | ||
private var accessor: ReactNativeFeatureFlagsAccessor = accessorProvider() | ||
|
||
/** | ||
* Common flag for testing. Do NOT modify. | ||
*/ | ||
fun commonTestFlag() = accessor.commonTestFlag() | ||
|
||
/** | ||
* Overrides the feature flags with the ones provided by the given provider | ||
* (generally one that extends `ReactNativeFeatureFlagsDefaults`). | ||
* | ||
* This method must be called before you initialize the React Native runtime. | ||
* | ||
* @example | ||
* | ||
* ``` | ||
* ReactNativeFeatureFlags.override(object : ReactNativeFeatureFlagsDefaults() { | ||
* override fun someFlag(): Boolean = true // or a dynamic value | ||
* }) | ||
* ``` | ||
*/ | ||
fun override(provider: ReactNativeFeatureFlagsProvider) = accessor.override(provider) | ||
|
||
/** | ||
* Removes the overridden feature flags and makes the API return default | ||
* values again. | ||
* | ||
* This should only be called if you destroy the React Native runtime and | ||
* need to create a new one with different overrides. In that case, | ||
* call `dangerouslyReset` after destroying the runtime and `override` | ||
* again before initializing the new one. | ||
*/ | ||
fun dangerouslyReset() { | ||
// This is necessary when the accessor interops with C++ and we need to | ||
// remove the overrides set there. | ||
accessor.dangerouslyReset() | ||
|
||
// This discards the cached values and the overrides set in the JVM. | ||
accessor = accessorProvider() | ||
} | ||
|
||
/** | ||
* This is just used to replace the default ReactNativeFeatureFlagsCxxAccessor | ||
* that uses JNI with a version that doesn't, to simplify testing. | ||
*/ | ||
internal fun setAccessorProvider(newAccessorProvider: () -> ReactNativeFeatureFlagsAccessor) { | ||
accessorProvider = newAccessorProvider | ||
accessor = accessorProvider() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsAccessor.kt
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,14 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
interface ReactNativeFeatureFlagsAccessor : ReactNativeFeatureFlagsProvider { | ||
fun override(provider: ReactNativeFeatureFlagsProvider) | ||
|
||
fun dangerouslyReset() | ||
} |
38 changes: 38 additions & 0 deletions
38
.../main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt
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,38 @@ | ||
/* | ||
* 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. | ||
* | ||
* @generated SignedSource<<961f1fb0a7ad802a492437f15b1f2dcb>> | ||
*/ | ||
|
||
/** | ||
* IMPORTANT: Do NOT modify this file directly. | ||
* | ||
* To change the definition of the flags, edit | ||
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. | ||
* | ||
* To regenerate this code, run the following script from the repo root: | ||
* yarn featureflags-update | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor { | ||
private var commonTestFlagCache: Boolean? = null | ||
|
||
override fun commonTestFlag(): Boolean { | ||
var cached = commonTestFlagCache | ||
if (cached == null) { | ||
cached = ReactNativeFeatureFlagsCxxInterop.commonTestFlag() | ||
commonTestFlagCache = cached | ||
} | ||
return cached | ||
} | ||
|
||
override fun override(provider: ReactNativeFeatureFlagsProvider) = | ||
ReactNativeFeatureFlagsCxxInterop.override(provider as Any) | ||
|
||
override fun dangerouslyReset() = ReactNativeFeatureFlagsCxxInterop.dangerouslyReset() | ||
} |
36 changes: 36 additions & 0 deletions
36
...c/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt
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,36 @@ | ||
/* | ||
* 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. | ||
* | ||
* @generated SignedSource<<c2e41ac8c3d9471b4cb79f6147cc2bf2>> | ||
*/ | ||
|
||
/** | ||
* IMPORTANT: Do NOT modify this file directly. | ||
* | ||
* To change the definition of the flags, edit | ||
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. | ||
* | ||
* To regenerate this code, run the following script from the repo root: | ||
* yarn featureflags-update | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
import com.facebook.proguard.annotations.DoNotStrip | ||
import com.facebook.soloader.SoLoader | ||
|
||
@DoNotStrip | ||
object ReactNativeFeatureFlagsCxxInterop { | ||
init { | ||
SoLoader.loadLibrary("reactfeatureflagsjni") | ||
} | ||
|
||
@DoNotStrip @JvmStatic external fun commonTestFlag(): Boolean | ||
|
||
@DoNotStrip @JvmStatic external fun override(provider: Any) | ||
|
||
@DoNotStrip @JvmStatic external fun dangerouslyReset() | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt
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,27 @@ | ||
/* | ||
* 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. | ||
* | ||
* @generated SignedSource<<aa1eaeee7b715e5b1d3cbcf9b7a7062e>> | ||
*/ | ||
|
||
/** | ||
* IMPORTANT: Do NOT modify this file directly. | ||
* | ||
* To change the definition of the flags, edit | ||
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. | ||
* | ||
* To regenerate this code, run the following script from the repo root: | ||
* yarn featureflags-update | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvider { | ||
// We could use JNI to get the defaults from C++, | ||
// but that is more expensive than just duplicating the defaults here. | ||
|
||
override fun commonTestFlag(): Boolean = false | ||
} |
14 changes: 14 additions & 0 deletions
14
...src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsForTests.kt
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,14 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
object ReactNativeFeatureFlagsForTests { | ||
fun setUp() { | ||
ReactNativeFeatureFlags.setAccessorProvider({ ReactNativeFeatureFlagsLocalAccessor() }) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ain/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt
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,52 @@ | ||
/* | ||
* 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. | ||
* | ||
* @generated SignedSource<<8bbd7e8cc2c50cfbf44ba6671d095f23>> | ||
*/ | ||
|
||
/** | ||
* IMPORTANT: Do NOT modify this file directly. | ||
* | ||
* To change the definition of the flags, edit | ||
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. | ||
* | ||
* To regenerate this code, run the following script from the repo root: | ||
* yarn featureflags-update | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAccessor { | ||
private var currentProvider: ReactNativeFeatureFlagsProvider = ReactNativeFeatureFlagsDefaults() | ||
|
||
private val accessedFeatureFlags = mutableSetOf<String>() | ||
|
||
private var commonTestFlagCache: Boolean? = null | ||
|
||
override fun commonTestFlag(): Boolean { | ||
var cached = commonTestFlagCache | ||
if (cached == null) { | ||
cached = currentProvider.commonTestFlag() | ||
accessedFeatureFlags.add("commonTestFlag") | ||
commonTestFlagCache = cached | ||
} | ||
return cached | ||
} | ||
|
||
override fun override(provider: ReactNativeFeatureFlagsProvider) { | ||
if (accessedFeatureFlags.isNotEmpty()) { | ||
val accessedFeatureFlagsStr = accessedFeatureFlags.joinToString(separator = ", ") { it } | ||
throw IllegalStateException( | ||
"Feature flags were accessed before being overridden: $accessedFeatureFlagsStr") | ||
} | ||
currentProvider = provider | ||
} | ||
|
||
override fun dangerouslyReset() { | ||
// We don't need to do anything here because `ReactNativeFeatureFlags` will | ||
// just create a new instance of this class. | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt
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,27 @@ | ||
/* | ||
* 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. | ||
* | ||
* @generated SignedSource<<8fae1537ff23fbd7dacd81cc2521cd3c>> | ||
*/ | ||
|
||
/** | ||
* IMPORTANT: Do NOT modify this file directly. | ||
* | ||
* To change the definition of the flags, edit | ||
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json. | ||
* | ||
* To regenerate this code, run the following script from the repo root: | ||
* yarn featureflags-update | ||
*/ | ||
|
||
package com.facebook.react.internal.featureflags | ||
|
||
import com.facebook.proguard.annotations.DoNotStrip | ||
|
||
@DoNotStrip | ||
interface ReactNativeFeatureFlagsProvider { | ||
@DoNotStrip fun commonTestFlag(): Boolean | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
packages/react-native/ReactAndroid/src/main/jni/react/featureflags/CMakeLists.txt
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,34 @@ | ||
# 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. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
|
||
file(GLOB featureflagsjni_SRCS CONFIGURE_DEPENDS *.cpp) | ||
|
||
add_library( | ||
featureflagsjni | ||
SHARED | ||
${featureflagsjni_SRCS} | ||
) | ||
|
||
target_include_directories(featureflagsjni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
target_link_libraries( | ||
featureflagsjni | ||
fb | ||
fbjni | ||
react_featureflags | ||
reactnativejni | ||
) | ||
|
||
target_compile_options( | ||
featureflagsjni | ||
PRIVATE | ||
-DLOG_TAG=\"ReactNative\" | ||
-fexceptions | ||
-frtti | ||
-std=c++20 | ||
-Wall | ||
) |
Oops, something went wrong.