LocalFeatureHandler

CompositionLocal providing access to the current FeatureHandler.

This allows components deep in the composition tree to access the FeatureHandler instance for checking and managing feature flags without explicit parameter passing.

Usage

Providing the Handler

@Composable
fun App() {
val features = remember { /* your features */}
val featureHandler = rememberFeatureHandler(features)

CompositionLocalProvider(LocalFeatureHandler provides featureHandler) {
Content()
}
}

Consuming the Handler

@Composable
fun MyScreen() {
val featureHandler = LocalFeatureHandler.current
val isDarkMode by featureHandler.isFeatureEnabled("dark_mode")

// Use the feature state...
}

In ViewModels (via dependency injection)

class MyViewModel(
private val featureHandler: FeatureHandler
) : ViewModel() {
val newFeatureEnabled = featureHandler
.isFeatureEnabledFlow("new_feature")
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
}

See also

Throws

if accessed without being provided in the composition tree.