rememberFeatureHandler
Remembers and returns a FeatureHandler instance for the current composition.
This composable creates a FeatureHandler backed by a platform-specific DataStore and automatically initializes it with the provided features. The instance is remembered across recompositions and tied to the composition lifecycle.
Platform-Specific Storage
Android: Stored in
{appFilesDir}/feature_flip_datastore.preferences_pbiOS: Stored in
{documentDirectory}/feature_flip_datastore.preferences_pb
Usage
Basic Setup
@Composable
fun App() {
val features = remember {
listOf(
Feature.LocalFeature(
name = "dark_mode",
description = "Enable dark theme",
isEnabled = false
),
Feature.RemoteFeature(
name = "new_checkout",
description = "New checkout flow",
defaultRemoteValue = true,
state = FeatureState.REMOTE
)
)
}
val featureHandler = rememberFeatureHandler(features)
CompositionLocalProvider(LocalFeatureHandler provides featureHandler) {
NavigationHost()
}
}Content copied to clipboard
With Dynamic Features
@Composable
fun App(remoteConfig: RemoteConfig) {
val features = remember(remoteConfig) {
buildList {
add(Feature.LocalFeature("dark_mode", null, false))
// Add remote features based on remote config
remoteConfig.getAllKeys().forEach { key ->
add(Feature.RemoteFeature(
name = key,
description = null,
defaultRemoteValue = remoteConfig.getBoolean(key),
state = FeatureState.REMOTE
))
}
}
}
val handler = rememberFeatureHandler(features)
// Use handler...
}Content copied to clipboard
Return
A remembered FeatureHandler instance bound to the composition lifecycle.
Parameters
features
The list of features to initialize the handler with. These features will be registered and their initial state persisted.