Android Jetpack Compose 中 'emit' 的确切含义是什么?
What is the exact meaning of 'emit' in Android Jetpack Compose?
emit这个词在Jetpack Compose的文档或者codelab中经常用到,如下:
The function doesn't return anything. Compose functions that "emit" UI do not need to return anything, because they describe the desired screen state instead of constructing UI widgets.
emit 在 Android Jetpack Compose 中的确切含义是什么?
谁处理 Compose 函数发出的 UI? Compose 框架是否检测并处理发出的 UI?
是否有关于如何以及由谁处理发出的 UI 的信息的文档?
“Emit”表示 Compose 将一个新组插入到当前合成中。
查看 source code:
@Suppress("NONREADONLY_CALL_IN_READONLY_COMPOSABLE", "UnnecessaryLambdaCreation")
@Composable inline fun <T : Any, reified E : Applier<*>> ReusableComposeNode(
noinline factory: () -> T,
update: @DisallowComposableCalls Updater<T>.() -> Unit
) {
if (currentComposer.applier !is E) invalidApplier()
currentComposer.startReusableNode() // <--- EMITTING THE NODE
if (currentComposer.inserting) {
currentComposer.createNode { factory() }
} else {
currentComposer.useNode()
}
currentComposer.disableReusing()
Updater<T>(currentComposer).update()
currentComposer.enableReusing()
currentComposer.endNode()
}
emit这个词在Jetpack Compose的文档或者codelab中经常用到,如下:
The function doesn't return anything. Compose functions that "emit" UI do not need to return anything, because they describe the desired screen state instead of constructing UI widgets.
emit 在 Android Jetpack Compose 中的确切含义是什么?
谁处理 Compose 函数发出的 UI? Compose 框架是否检测并处理发出的 UI?
是否有关于如何以及由谁处理发出的 UI 的信息的文档?
“Emit”表示 Compose 将一个新组插入到当前合成中。
查看 source code:
@Suppress("NONREADONLY_CALL_IN_READONLY_COMPOSABLE", "UnnecessaryLambdaCreation") @Composable inline fun <T : Any, reified E : Applier<*>> ReusableComposeNode( noinline factory: () -> T, update: @DisallowComposableCalls Updater<T>.() -> Unit ) { if (currentComposer.applier !is E) invalidApplier() currentComposer.startReusableNode() // <--- EMITTING THE NODE if (currentComposer.inserting) { currentComposer.createNode { factory() } } else { currentComposer.useNode() } currentComposer.disableReusing() Updater<T>(currentComposer).update() currentComposer.enableReusing() currentComposer.endNode() }