Fixed extra space on the webview top if the webview is not atteched to any view

This commit is contained in:
MohitMaliFtechiz 2023-06-23 15:14:39 +05:30 committed by Kelson
parent 17cbcf082d
commit a3de2a25c7

View File

@ -686,17 +686,20 @@ abstract class CoreReaderFragment :
*/ */
protected open fun setTopMarginToWebViews(topMargin: Int) { protected open fun setTopMarginToWebViews(topMargin: Int) {
for (webView in webViewList) { for (webView in webViewList) {
webView.parent?.let { if (webView.parent == null) {
// Ensure that the web view has a parent before modifying its layout parameters // 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 // 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 // Adding the margin without a parent can cause unintended layout issues or empty
// space on top of the webView in the tabs adapter. // space on top of the webView in the tabs adapter.
val frameLayout = FrameLayout(requireActivity())
// Add the web view to the frame layout
frameLayout.addView(webView)
}
val layoutParams = webView.layoutParams as FrameLayout.LayoutParams? val layoutParams = webView.layoutParams as FrameLayout.LayoutParams?
layoutParams?.topMargin = topMargin layoutParams?.topMargin = topMargin
webView.requestLayout() webView.requestLayout()
} }
} }
}
protected fun startAnimation(view: View?, @AnimRes anim: Int) { protected fun startAnimation(view: View?, @AnimRes anim: Int) {
view?.startAnimation(AnimationUtils.loadAnimation(view.context, anim)) view?.startAnimation(AnimationUtils.loadAnimation(view.context, anim))