From a3de2a25c7caad1ea12da109d770e9fc0637cbb0 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 23 Jun 2023 15:14:39 +0530 Subject: [PATCH] Fixed extra space on the webview top if the webview is not atteched to any view --- .../kiwix/kiwixmobile/core/main/CoreReaderFragment.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 8b161bc7f..d7c003d47 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -686,15 +686,18 @@ abstract class CoreReaderFragment : */ protected open fun setTopMarginToWebViews(topMargin: Int) { for (webView in webViewList) { - webView.parent?.let { + if (webView.parent == null) { // Ensure that the web view has a parent before modifying its layout parameters // This check is necessary to prevent adding the margin when the web view is not attached to a layout // Adding the margin without a parent can cause unintended layout issues or empty // space on top of the webView in the tabs adapter. - val layoutParams = webView.layoutParams as FrameLayout.LayoutParams? - layoutParams?.topMargin = topMargin - webView.requestLayout() + val frameLayout = FrameLayout(requireActivity()) + // Add the web view to the frame layout + frameLayout.addView(webView) } + val layoutParams = webView.layoutParams as FrameLayout.LayoutParams? + layoutParams?.topMargin = topMargin + webView.requestLayout() } }