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

View File

@ -18,12 +18,12 @@
package org.kiwix.kiwixmobile.main package org.kiwix.kiwixmobile.main
import android.util.Log
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.BottomAppBar import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.BottomAppBarDefaults
import androidx.compose.material3.BottomAppBarScrollBehavior import androidx.compose.material3.BottomAppBarScrollBehavior
import androidx.compose.material3.DrawerState import androidx.compose.material3.DrawerState
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
@ -65,6 +65,9 @@ fun KiwixMainActivityScreen(
bottomAppBarScrollBehaviour: BottomAppBarScrollBehavior bottomAppBarScrollBehaviour: BottomAppBarScrollBehavior
) { ) {
val navBackStackEntry by navController.currentBackStackEntryAsState() 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 { KiwixTheme {
ModalNavigationDrawer( ModalNavigationDrawer(
drawerState = leftDrawerState, drawerState = leftDrawerState,
@ -73,12 +76,18 @@ fun KiwixMainActivityScreen(
LeftDrawerMenu(leftDrawerContent) 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 { Box {
Scaffold( Scaffold(
bottomBar = { bottomBar = {
if (navBackStackEntry?.destination?.route in topLevelDestinationsRoute && shouldShowBottomAppBar) { if (shouldShowBottomBar) {
BottomNavigationBar( BottomNavigationBar(
navController = navController, navController = navController,
bottomAppBarScrollBehaviour = bottomAppBarScrollBehaviour, bottomAppBarScrollBehaviour = bottomAppBarScrollBehaviour,

View File

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

View File

@ -52,6 +52,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult import androidx.compose.material3.SnackbarResult
@ -424,6 +425,7 @@ abstract class CoreReaderFragment :
} }
} }
@OptIn(ExperimentalMaterial3Api::class)
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Suppress("LongMethod") @Suppress("LongMethod")
override fun onViewCreated( override fun onViewCreated(
@ -483,7 +485,8 @@ abstract class CoreReaderFragment :
onClick = { navigationIconClick() }, onClick = { navigationIconClick() },
iconTint = navigationIconTint() iconTint = navigationIconTint()
) )
} },
bottomAppBarScrollBehaviour = (requireActivity() as CoreMainActivity).bottomAppBarScrollBehaviour
) )
DialogHost(alertDialogShower as AlertDialogShower) DialogHost(alertDialogShower as AlertDialogShower)
} }
@ -587,11 +590,6 @@ abstract class CoreReaderFragment :
if (readerMenuState?.isInTabSwitcher == true) { if (readerMenuState?.isInTabSwitcher == true) {
onHomeMenuClicked() onHomeMenuClicked()
} else { } 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 val activity = activity as CoreMainActivity
if (activity.navigationDrawerIsOpen()) { if (activity.navigationDrawerIsOpen()) {
activity.closeNavigationDrawer() activity.closeNavigationDrawer()
@ -788,6 +786,7 @@ abstract class CoreReaderFragment :
protected open fun hideTabSwitcher(shouldCloseZimBook: Boolean = true) { protected open fun hideTabSwitcher(shouldCloseZimBook: Boolean = true) {
setUpDrawerToggle() setUpDrawerToggle()
(requireActivity() as CoreMainActivity).showBottomAppBar() (requireActivity() as CoreMainActivity).showBottomAppBar()
Log.e("SHOW_BOTTOM_APP", "hideTabSwitcher: ")
setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
readerScreenState.update { readerScreenState.update {
copy( copy(

View File

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