Room lifecycle: fix close room crash
This commit is contained in:
parent
848afbf36d
commit
16f95cac16
1 changed files with 10 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ package io.element.android.appnav
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.bumble.appyx.core.composable.Children
|
import com.bumble.appyx.core.composable.Children
|
||||||
|
|
@ -88,14 +89,12 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
lifecycle.subscribe(
|
lifecycle.subscribe(
|
||||||
onCreate = {
|
onCreate = {
|
||||||
Timber.v("OnCreate")
|
Timber.v("OnCreate")
|
||||||
inputs.room.open()
|
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowCreated(id, inputs.room) }
|
plugins<LifecycleCallback>().forEach { it.onFlowCreated(id, inputs.room) }
|
||||||
appNavigationStateService.onNavigateToRoom(id, inputs.room.roomId)
|
appNavigationStateService.onNavigateToRoom(id, inputs.room.roomId)
|
||||||
fetchRoomMembers()
|
fetchRoomMembers()
|
||||||
},
|
},
|
||||||
onDestroy = {
|
onDestroy = {
|
||||||
Timber.v("OnDestroy")
|
Timber.v("OnDestroy")
|
||||||
inputs.room.close()
|
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.room) }
|
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.room) }
|
||||||
appNavigationStateService.onLeavingRoom(id)
|
appNavigationStateService.onLeavingRoom(id)
|
||||||
}
|
}
|
||||||
|
|
@ -161,6 +160,15 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun View(modifier: Modifier) {
|
override fun View(modifier: Modifier) {
|
||||||
|
// Rely on the View Lifecycle instead of the Node Lifecycle,
|
||||||
|
// because this node enters 'onDestroy' before his children, so it can leads to
|
||||||
|
// using the room in a child node where it's already closed.
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
inputs.room.open()
|
||||||
|
onDispose {
|
||||||
|
inputs.room.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
Children(
|
Children(
|
||||||
navModel = backstack,
|
navModel = backstack,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue