Browse Source
Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>pull/1452/head
Oleksandr Karpovich
3 years ago
committed by
GitHub
7 changed files with 82 additions and 31 deletions
@ -0,0 +1,4 @@
|
||||
import androidx.compose.runtime.Composable |
||||
import androidx.compose.runtime.Composition |
||||
|
||||
expect fun callComposable(content: @Composable () -> Unit) |
@ -0,0 +1,33 @@
|
||||
import androidx.compose.runtime.* |
||||
import kotlinx.coroutines.* |
||||
|
||||
class UnitApplier : Applier<Unit> { |
||||
override val current: Unit |
||||
get() = Unit |
||||
|
||||
override fun down(node: Unit) {} |
||||
override fun up() {} |
||||
override fun insertTopDown(index: Int, instance: Unit) {} |
||||
override fun insertBottomUp(index: Int, instance: Unit) {} |
||||
override fun remove(index: Int, count: Int) {} |
||||
override fun move(from: Int, to: Int, count: Int) {} |
||||
override fun clear() {} |
||||
} |
||||
|
||||
fun createRecomposer(): Recomposer { |
||||
val mainScope = CoroutineScope( |
||||
NonCancellable + Dispatchers.Main + DefaultMonotonicFrameClock |
||||
) |
||||
|
||||
return Recomposer(mainScope.coroutineContext).also { |
||||
mainScope.launch(start = CoroutineStart.UNDISPATCHED) { |
||||
it.runRecomposeAndApplyChanges() |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
actual fun callComposable(content: @Composable () -> Unit) { |
||||
val c = ControlledComposition(UnitApplier(), createRecomposer()) |
||||
c.setContent(content) |
||||
} |
Loading…
Reference in new issue