mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 05:04:50 -04:00
Fixed: When changing the app's language, a blank screen appeared instead of the settings screen.
* The issue occurred because we reopened the settings screen immediately after removing it from the back stack, causing Compose to not settle the previous frame and display a blank screen. * Resolved by allowing the popBackStack frame to settle before reopening the settings screen. * Removed some unused code from the project.
This commit is contained in:
parent
fe7ded693a
commit
456e348078
@ -35,6 +35,7 @@ import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat
|
||||
@ -183,12 +184,27 @@ abstract class CoreSettingsFragment : SettingsContract.View, BaseFragment() {
|
||||
composeView = it
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the Settings screen by popping it from the back stack and reopening it.
|
||||
*
|
||||
* This is useful when we need to refresh the Settings UI (e.g., after a app's language
|
||||
* change) without fully recreating the activity.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Get the CoreMainActivity reference to access the NavController.
|
||||
* 2. Pop the Settings fragment from the navigation back stack.
|
||||
* 3. Wait for one frame so the back stack can settle after the pop operation.
|
||||
* 4. Navigate back to the Settings fragment route.
|
||||
*/
|
||||
private fun restartActivity() {
|
||||
(activity as CoreMainActivity?)?.let {
|
||||
it.navController.apply {
|
||||
popBackStack()
|
||||
navigate(it.settingsFragmentRoute)
|
||||
}
|
||||
val coreMainActivity = activity as? CoreMainActivity ?: return
|
||||
val navController = coreMainActivity.navController
|
||||
navController.popBackStack()
|
||||
coreMainActivity.uiCoroutineScope.launch {
|
||||
// Wait for one frame to ensure the back stack has settled before navigation
|
||||
// Bug fix #4387
|
||||
withFrameNanos { }
|
||||
navController.navigate(coreMainActivity.settingsFragmentRoute)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.only
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBars
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
@ -44,21 +43,16 @@ import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarScrollBehavior
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import org.kiwix.kiwixmobile.core.downloader.downloadManager.ZERO
|
||||
import org.kiwix.kiwixmobile.core.ui.models.ActionMenuItem
|
||||
import org.kiwix.kiwixmobile.core.ui.models.toPainter
|
||||
import org.kiwix.kiwixmobile.core.ui.theme.Black
|
||||
@ -234,23 +228,3 @@ private fun OverflowMenuItems(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun rememberBottomNavigationVisibility(lazyListState: LazyListState?): Boolean {
|
||||
var isToolbarVisible by remember { mutableStateOf(true) }
|
||||
var lastScrollIndex by remember { mutableIntStateOf(ZERO) }
|
||||
val updatedLazyListState = rememberUpdatedState(lazyListState)
|
||||
|
||||
LaunchedEffect(updatedLazyListState) {
|
||||
updatedLazyListState.value?.let { state ->
|
||||
snapshotFlow { state.firstVisibleItemIndex }
|
||||
.collect { newScrollIndex ->
|
||||
if (newScrollIndex != lastScrollIndex) {
|
||||
isToolbarVisible = newScrollIndex < lastScrollIndex
|
||||
lastScrollIndex = newScrollIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return isToolbarVisible
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user