Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 60ed2119 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé
Browse files

Fix for the ConcurrentModificationException caused by navigating back from the QR code screen

parent be2c5b60
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ import app.k9mail.feature.onboarding.permissions.ui.PermissionsScreen
import app.k9mail.feature.onboarding.welcome.ui.WelcomeScreen
import app.k9mail.feature.settings.import.ui.SettingsImportAction
import app.k9mail.feature.settings.import.ui.SettingsImportScreen
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.compose.koinInject

private const val NESTED_NAVIGATION_ROUTE_WELCOME = "welcome"
@@ -55,6 +58,7 @@ fun OnboardingNavHost(
    onFinish: (String?) -> Unit,
    hasRuntimePermissions: HasRuntimePermissions = koinInject(),
    onboardingMigrationManager: OnboardingMigrationManager = koinInject(),
    coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Main),
) {
    val navController = rememberNavController()
    var accountUuid by rememberSaveable { mutableStateOf<String?>(null) }
@@ -120,7 +124,17 @@ fun OnboardingNavHost(
            SettingsImportScreen(
                action = SettingsImportAction.ScanQrCode,
                onImportSuccess = ::onImportSuccess,
                onBack = { navController.popBackStack() },
                onBack = {
                    // Fix for the navigation issue causing a ConcurrentModificationException when navigating back
                    // from the QR code scanner that is nested in the settings import fragment.
                    // There is a race condition when the fragment result listener is triggered and the
                    // fragment lifecycle is handled within the composable.
                    // This is a workaround to postpone immediate interaction with the nav controller,
                    // until we have a better solution.
                    coroutineScope.launch {
                        navController.popBackStack()
                    }
                },
            )
        }