Skip to content

Instantly share code, notes, and snippets.

@habibg1232191
Created April 27, 2022 09:28
Show Gist options
  • Save habibg1232191/a601fbe39475631110febac115370e2a to your computer and use it in GitHub Desktop.
Save habibg1232191/a601fbe39475631110febac115370e2a to your computer and use it in GitHub Desktop.
import androidx.compose.animation.*
import androidx.compose.animation.core.*
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.*
@ExperimentalAnimationApi
@Composable
fun App() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
var value by remember { mutableStateOf("") }
LocalTest.current.testTitle = value
TextField(
value = value,
onValueChange = { value = it }
)
}
}
@ExperimentalAnimationApi
@ExperimentalFoundationApi
fun main() = application {
CompositionLocalProvider(
LocalTest provides Test("Test")
) {
Window(onCloseRequest = ::exitApplication, title = LocalTest.current.testTitle) {
MaterialTheme {
Surface {
App()
}
}
}
}
}
val LocalTest = compositionLocalOf<Test> {
noLocalProvidedFor("LocalWindowState")
}
data class Test(
val testTitle: String
)
fun noLocalProvidedFor(name: String): Nothing {
error("CompositionLocal $name not present")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment