adeln
02/06/2019, 11:02 AMadeln
02/06/2019, 11:46 AMghedeon
02/06/2019, 11:54 AMghedeon
02/06/2019, 11:55 AM.produce{}
to create a channeladeln
02/06/2019, 11:56 AMadeln
02/06/2019, 12:00 PMsuspend fun View.globalLayout(): View =
suspendCancellableCoroutine { cont ->
val listener = ViewTreeObserver.OnGlobalLayoutListener {
cont.resume(this)
}
cont.invokeOnCancellation {
viewTreeObserver.removeOnGlobalLayoutListener(listener)
}
viewTreeObserver.addOnGlobalLayoutListener(listener)
}
fun View.globalLayouts(context: CoroutineContext = Dispatchers.Unconfined): ReceiveChannel<View> =
GlobalScope.produce(context) {
while (true) {
send(globalLayout())
}
}
?adeln
02/06/2019, 12:01 PMadeln
02/06/2019, 12:22 PM