How to use CompositionLocal in Jetpack Compose

PHOTO EMBED

Tue Jan 11 2022 15:14:38 GMT+0000 (Coordinated Universal Time)

Saved by @GoodRequest. #kotlin

CompositionLocalProvider(LocalContentColor provides Color.Blue) {
		// content color for all components in this scope is blue
    Text(text = "Lorem")
    CompositionLocalProvider(LocalContentColor provides Color.Red) {
				// content color for all components in this scope is blue
        Text(text = "ipsum")
        Text(text = "dolor")
        CompositionLocalProvider(LocalContentAlpha provides 0.2f) {
						// alpha of all components in this scope is 0.2f
            Text(text = "sit...")
        }
    }
}
content_copyCOPY