Fixed: WebView scrolling is lagging with compose UI. * Fixed: the bottomAppBar is not showing when closing the tabs.

This commit is contained in:
MohitMaliFtechiz 2025-07-23 21:11:26 +05:30
parent 877c4a7166
commit 16c5cc78ee
5 changed files with 28 additions and 26 deletions

View File

@ -43,7 +43,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.compose.rememberNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import androidx.room.util.copy
import eu.mhutti1.utils.storage.StorageDevice
import eu.mhutti1.utils.storage.StorageDeviceUtils
import kotlinx.coroutines.delay
@ -59,6 +59,7 @@ import org.kiwix.kiwixmobile.core.base.FragmentActivityExtensions
import org.kiwix.kiwixmobile.core.dao.LibkiwixBookOnDisk
import org.kiwix.kiwixmobile.core.downloader.downloadManager.DOWNLOAD_NOTIFICATION_TITLE
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.extensions.update
import org.kiwix.kiwixmobile.core.main.ACTION_NEW_TAB
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.DrawerMenuItem
@ -151,21 +152,12 @@ class KiwixMainActivity : CoreMainActivity() {
}
DialogHost(alertDialogShower)
}
// activityKiwixMainBinding.drawerNavView.apply {
// setupWithNavController(navController)
// setNavigationItemSelectedListener { item ->
// closeNavigationDrawer()
// onNavigationItemSelected(item)
// }
// }
// activityKiwixMainBinding.bottomNavView.setupWithNavController(navController)
lifecycleScope.launch {
migrateInternalToPublicAppDirectory()
}
handleZimFileIntent(intent)
handleNotificationIntent(intent)
handleGetContentIntent(intent)
// activityKiwixMainBinding.root.applyEdgeToEdgeInsets()
}
private suspend fun migrateInternalToPublicAppDirectory() {
@ -200,7 +192,6 @@ class KiwixMainActivity : CoreMainActivity() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
Log.e("CONFIGURATION", "onConfigurationChanged: ")
leftDrawerMenu.clear()
leftDrawerMenu.addAll(leftNavigationDrawerMenuItems)
}
@ -361,11 +352,12 @@ class KiwixMainActivity : CoreMainActivity() {
}
override fun hideBottomAppBar() {
shouldShowBottomAppBar.value = false
shouldShowBottomAppBar.update { false }
}
override fun showBottomAppBar() {
shouldShowBottomAppBar.value = true
Log.e("SHOW_BOTTOM_APP", "showBottomAppBar: ")
shouldShowBottomAppBar.update { true }
}
// Outdated shortcut ids(new_tab, get_content)

View File

@ -18,12 +18,12 @@
package org.kiwix.kiwixmobile.main
import android.util.Log
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.BottomAppBarDefaults
import androidx.compose.material3.BottomAppBarScrollBehavior
import androidx.compose.material3.DrawerState
import androidx.compose.material3.ExperimentalMaterial3Api
@ -65,6 +65,9 @@ fun KiwixMainActivityScreen(
bottomAppBarScrollBehaviour: BottomAppBarScrollBehavior
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
val shouldShowBottomBar = currentRoute in topLevelDestinationsRoute && shouldShowBottomAppBar
Log.e("CURRENT_DESTINATION", "KiwixMainActivityScreen: $currentRoute and $shouldShowBottomAppBar")
KiwixTheme {
ModalNavigationDrawer(
drawerState = leftDrawerState,
@ -73,12 +76,18 @@ fun KiwixMainActivityScreen(
LeftDrawerMenu(leftDrawerContent)
}
},
gesturesEnabled = enableLeftDrawer && navBackStackEntry?.destination?.route in topLevelDestinationsRoute
gesturesEnabled = enableLeftDrawer &&
currentRoute in topLevelDestinationsRoute &&
// Fixing the webView scrolling is lagging when navigation gesture is enabled,
// since navigation consumes the swipes event makes webView lagging.
// However, on reader screen navigation drawer can be opened by clicking
// on the hamburger button.
(currentRoute != KiwixDestination.Reader.route || leftDrawerState.isOpen)
) {
Box {
Scaffold(
bottomBar = {
if (navBackStackEntry?.destination?.route in topLevelDestinationsRoute && shouldShowBottomAppBar) {
if (shouldShowBottomBar) {
BottomNavigationBar(
navController = navController,
bottomAppBarScrollBehaviour = bottomAppBarScrollBehaviour,

View File

@ -54,13 +54,12 @@ import javax.inject.Inject
private const val INITIAL_SCALE = 100
@SuppressLint("ViewConstructor")
@SuppressWarnings("LongParameterList")
open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor(
context: Context,
private val callback: WebViewCallback,
attrs: AttributeSet,
videoView: ViewGroup?,
private val webViewClient: CoreWebViewClient,
private val coreWebViewClient: CoreWebViewClient,
val sharedPreferenceUtil: SharedPreferenceUtil
) : VideoEnabledWebView(context, attrs) {
@Inject
@ -99,7 +98,7 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor(
}
setInitialScale(INITIAL_SCALE)
clearCache(true)
setWebViewClient(webViewClient)
webViewClient = coreWebViewClient
webChromeClient =
KiwixWebChromeClient(callback, videoView, this).apply {
setOnToggledFullscreen(
@ -117,7 +116,7 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor(
val result = hitTestResult
if (result.type == HitTestResult.SRC_ANCHOR_TYPE) {
result.extra?.let {
if (!webViewClient.handleUnsupportedFiles(it)) {
if (!coreWebViewClient.handleUnsupportedFiles(it)) {
callback.webViewLongClick(it)
}
}

View File

@ -52,6 +52,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
@ -424,6 +425,7 @@ abstract class CoreReaderFragment :
}
}
@OptIn(ExperimentalMaterial3Api::class)
@SuppressLint("ClickableViewAccessibility")
@Suppress("LongMethod")
override fun onViewCreated(
@ -483,7 +485,8 @@ abstract class CoreReaderFragment :
onClick = { navigationIconClick() },
iconTint = navigationIconTint()
)
}
},
bottomAppBarScrollBehaviour = (requireActivity() as CoreMainActivity).bottomAppBarScrollBehaviour
)
DialogHost(alertDialogShower as AlertDialogShower)
}
@ -587,11 +590,6 @@ abstract class CoreReaderFragment :
if (readerMenuState?.isInTabSwitcher == true) {
onHomeMenuClicked()
} else {
// Manually handle the navigation open/close.
// Since currently we are using the view based navigation drawer in other screens.
// Once we fully migrate to jetpack compose we will refactor this code to use the
// compose navigation.
// TODO Replace with compose based navigation when migration is done.
val activity = activity as CoreMainActivity
if (activity.navigationDrawerIsOpen()) {
activity.closeNavigationDrawer()
@ -788,6 +786,7 @@ abstract class CoreReaderFragment :
protected open fun hideTabSwitcher(shouldCloseZimBook: Boolean = true) {
setUpDrawerToggle()
(requireActivity() as CoreMainActivity).showBottomAppBar()
Log.e("SHOW_BOTTOM_APP", "hideTabSwitcher: ")
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
readerScreenState.update {
copy(

View File

@ -89,6 +89,7 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
@ -160,6 +161,7 @@ fun ReaderScreen(
state: ReaderScreenState,
actionMenuItems: List<ActionMenuItem>,
onBottomScrollOffsetChanged: (Float) -> Unit,
bottomAppBarScrollBehaviour: BottomAppBarScrollBehavior,
navigationIcon: @Composable () -> Unit
) {
val bottomNavHeightInDp = with(LocalDensity.current) { state.bottomNavigationHeight.toDp() }
@ -183,6 +185,7 @@ fun ReaderScreen(
modifier = Modifier
.systemBarsPadding()
.padding(bottom = bottomNavHeightInDp)
.nestedScroll(bottomAppBarScrollBehaviour.nestedScrollConnection)
.semantics { testTag = READER_SCREEN_TESTING_TAG }
) { paddingValues ->
ReaderContentLayout(