Fix IllegalStateException when clicking login after logout
The previous login result was stored as live data and prevented AuthenticationFragment from being shown properly. However, an attempt to destroy RecipesFragment was made. This attempt caused IllegalStateException when accessing view in onDestroyView.
This commit is contained in:
@@ -8,6 +8,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -27,4 +28,9 @@ fun OnBackPressedDispatcher.backPressedFlow(): Flow<Unit> = callbackFlow {
|
||||
callback.isEnabled = false
|
||||
callback.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Fragment.collectWithViewLifecycle(
|
||||
flow: Flow<T>,
|
||||
crossinline collector: suspend (T) -> Unit,
|
||||
) = viewLifecycleOwner.lifecycleScope.launch { flow.collect(collector) }
|
||||
|
||||
Reference in New Issue
Block a user