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()
}
}Content copied to clipboard
Consuming the Handler
@Composable
fun MyScreen() {
val featureHandler = LocalFeatureHandler.current
val isDarkMode by featureHandler.isFeatureEnabled("dark_mode")
// Use the feature state...
}Content copied to clipboard
In ViewModels (via dependency injection)
class MyViewModel(
private val featureHandler: FeatureHandler
) : ViewModel() {
val newFeatureEnabled = featureHandler
.isFeatureEnabledFlow("new_feature")
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
}Content copied to clipboard
See also
Throws
if accessed without being provided in the composition tree.