88
99package io.element.android.appnav.room.joined
1010
11+ import android.app.Activity
1112import android.os.Parcelable
13+ import androidx.activity.compose.LocalActivity
1214import androidx.compose.runtime.Composable
15+ import androidx.compose.runtime.mutableStateOf
1316import androidx.compose.ui.Modifier
1417import androidx.lifecycle.lifecycleScope
1518import com.bumble.appyx.core.lifecycle.subscribe
@@ -96,6 +99,9 @@ class JoinedRoomLoadedFlowNode(
9699 private val callback: Callback = callback()
97100 override val graph = roomGraphFactory.create(inputs.room)
98101
102+ // This is an ugly hack to check activity recreation
103+ private val currentActivity = mutableStateOf<Activity ?>(null )
104+
99105 init {
100106 lifecycle.subscribe(
101107 onCreate = {
@@ -115,8 +121,12 @@ class JoinedRoomLoadedFlowNode(
115121 },
116122 onDestroy = {
117123 Timber .v(" OnDestroy" )
118- activeRoomsHolder.removeRoom(inputs.room.sessionId, inputs.room.roomId)
119- inputs.room.destroy()
124+ // If we're just going through an activity recreation there's no need to destroy the Room object
125+ // Destroying it would actually cause an issue where its methods can no longer be called
126+ if (currentActivity.value?.isChangingConfigurations != true ) {
127+ activeRoomsHolder.removeRoom(inputs.room.sessionId, inputs.room.roomId)
128+ inputs.room.destroy()
129+ }
120130 appNavigationStateService.onLeavingRoom(id)
121131 }
122132 )
@@ -289,6 +299,8 @@ class JoinedRoomLoadedFlowNode(
289299
290300 @Composable
291301 override fun View (modifier : Modifier ) {
302+ currentActivity.value = LocalActivity .current
303+
292304 BackstackView ()
293305 }
294306}
0 commit comments