Created
April 27, 2022 09:28
-
-
Save habibg1232191/a601fbe39475631110febac115370e2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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