假设有一个按钮定义如下
val btnEnabled by remember { mutableStateOf(true) }
...
Button(
colors = ButtonDefaults.buttonColors(
background = Color.Yellow
disabledBackgroundColor = Color.Black ),
enabled = btnEnabled
) {
...
}
Run Code Online (Sandbox Code Playgroud)
当 的值btnEnabled改变时,按钮的背景会立即刚性地改变。有什么办法让它变成动画过渡吗?
我是协程/流的新手,想知道collect当它获得所需的值时从 的代码块关闭流的适当方法。
代码是这样的:
suspend fun findService(scope:CoroutineScope, context:Context, name:String) {
val flow = getWifiDebuggingConnectDiscoveryFlow( context )
try {
flow.collect {
if(name == it.serviceName) {
/* need to exit the collection and execute the code that follows */
}
}
println("service found!")
} catch(e: Throwable) {
println("Exception from the flow: $e")
}
/* need to do something after service found */
}
private fun getWifiDebuggingConnectDiscoveryFlow(context:Context) = callbackFlow {
val nsdManager:NsdManager = context.getSystemService(Context.NSD_SERVICE) as NsdManager
val listener = object : NsdManager.DiscoveryListener …Run Code Online (Sandbox Code Playgroud)