mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Fix navigation issue #2778
This commit is contained in:
+21
@@ -20,6 +20,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import com.bumble.appyx.core.children.nodeOrNull
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.node.ParentNode
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlin.coroutines.resume
|
||||
@@ -48,3 +49,23 @@ suspend inline fun <reified N : Node, NavTarget : Any> ParentNode<NavTarget>.wai
|
||||
continuation.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a child to be attached to the parent node, only using the NavTarget
|
||||
*/
|
||||
suspend inline fun <NavTarget : Any> ParentNode<NavTarget>.waitForNavTargetAttached(crossinline predicate: (NavTarget) -> Boolean) =
|
||||
suspendCancellableCoroutine { continuation ->
|
||||
lifecycleScope.launch {
|
||||
children.collect { childMap ->
|
||||
val node = childMap.entries
|
||||
.map { it.key.navTarget }
|
||||
.lastOrNull(predicate)
|
||||
if (node != null && !continuation.isCompleted) {
|
||||
continuation.resume(Unit)
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}.invokeOnCompletion {
|
||||
continuation.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user