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

Commit 098ecd9d authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Fix destination reset after configuration change

Also enable predictive back gesture for Gallery App.

Bug: 244122804
Test: Manual with Gallery App
Change-Id: I68bb694c87b2614aa908f1e973aea8fa7288f47c
parent 826ce0df
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@
    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_label"
        android:supportsRtl="true">
        android:supportsRtl="true"
        android:enableOnBackInvokedCallback="true">
        <activity
            android:name=".MainActivity"
            android:exported="true">
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ android {
}

dependencies {
    api "androidx.appcompat:appcompat:1.6.0-rc01"
    api "androidx.compose.material3:material3:$jetpack_compose_material3_version"
    api "androidx.compose.material:material-icons-extended:$jetpack_compose_version"
    api "androidx.compose.runtime:runtime-livedata:$jetpack_compose_version"
+18 −8
Original line number Diff line number Diff line
@@ -22,7 +22,10 @@ import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
@@ -50,9 +53,6 @@ open class BrowseActivity(

    @Composable
    private fun MainContent() {
        val destination =
            intent?.getStringExtra(KEY_DESTINATION) ?: sppRepository.getDefaultStartPageName()

        val navController = rememberNavController()
        CompositionLocalProvider(navController.localNavController()) {
            NavHost(navController, ROOT_PAGE_NAME) {
@@ -70,9 +70,20 @@ open class BrowseActivity(
                    }
                }
            }
        }

            if (destination.isNotEmpty()) {
        InitialDestinationNavigator(navController)
    }

    @Composable
    private fun InitialDestinationNavigator(navController: NavHostController) {
        val destinationNavigated = rememberSaveable { mutableStateOf(false) }
        if (destinationNavigated.value) return
        destinationNavigated.value = true
        LaunchedEffect(Unit) {
            val destination =
                intent?.getStringExtra(KEY_DESTINATION) ?: sppRepository.getDefaultStartPageName()
            if (destination.isNotEmpty()) {
                navController.navigate(destination) {
                    popUpTo(navController.graph.findStartDestination().id) {
                        inclusive = true
@@ -81,7 +92,6 @@ open class BrowseActivity(
            }
        }
    }
    }

    companion object {
        const val KEY_DESTINATION = "spa:SpaActivity:destination"