diff --git a/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt b/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt index 8814e3a2..c13e7e7f 100644 --- a/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt +++ b/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt @@ -21,6 +21,7 @@ import org.autojs.autojs6.R import org.autojs.autojs6.databinding.FragmentOnlineDocsBinding import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe +import org.intellij.lang.annotations.Language /** * Created by Stardust on Aug 22, 2017. @@ -59,7 +60,25 @@ class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressedHandl if (ViewUtils.isNightModeYes(requireContext())) { WebViewUtils.adaptDarkMode(webView) } - WebViewUtils.excludeWebViewFromNavigationBar(ewebView, webView) + WebViewUtils.excludeWebViewFromNavigationBar(ewebView, webView) { systemBarInsetsBottom -> + @Language("JavaScript") + val injectCode = """ + (function() { + let mainElements = document.querySelectorAll('main > *'); + if (mainElements.length > 0) { + // Online docs (zh-CN: 在线文档) + mainElements.forEach(ele => { + let basePaddingBottom = ele.className === 'sidebar-toggle' ? 10 : 0; + ele.style.paddingBottom = (basePaddingBottom + ${systemBarInsetsBottom}) / window.devicePixelRatio + 'px'; + }); + } else { + // Local docs (zh-CN: 本地文档) + document.body.style.paddingBottom = '${systemBarInsetsBottom}px'; + } + })(); + """.trimIndent() + injectCode + } } } restoreViewStates() diff --git a/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt b/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt index 8b523814..0b9915ec 100644 --- a/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt @@ -18,6 +18,7 @@ import org.intellij.lang.annotations.Language */ class WebViewUtils { + @Suppress("SameParameterValue") companion object { // @Hint by SuperMonster003 on Aug 26, 2022. @@ -72,11 +73,37 @@ class WebViewUtils { excludeWebViewFromSystemBars(webViewWrapper, webView, excludeStatusBar = false, excludeNavigationBar = true) } + fun excludeWebViewFromNavigationBar(webViewWrapper: View, webView: WebView, excludeNavigationBarInjectCode: (systemBarInsetsBottom: Int) -> String) { + excludeWebViewFromSystemBars(webViewWrapper, webView, excludeStatusBar = false, excludeNavigationBarInjectCode = excludeNavigationBarInjectCode) + } + fun excludeWebViewFromStatusBarAndNavigationBar(webViewWrapper: View, webView: WebView) { excludeWebViewFromSystemBars(webViewWrapper, webView, excludeStatusBar = true, excludeNavigationBar = true) } - @Suppress("SameParameterValue") + private fun excludeWebViewFromSystemBars(webViewWrapper: View, webView: WebView, excludeStatusBar: Boolean, excludeNavigationBarInjectCode: (systemBarInsetsBottom: Int) -> String) { + var mSystemBarInsets: Insets? = null + ViewCompat.setOnApplyWindowInsetsListener(webViewWrapper) { v, insets -> + val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()).also { + mSystemBarInsets = it + } + if (excludeStatusBar) { + v.setPadding(0, systemBarInsets.top, 0, 0) + } + webView.setPadding(0, 0, 0, systemBarInsets.bottom) + insets + } + webView.webViewClient = object : WebViewClient() { + override fun onPageFinished(view: WebView?, url: String?) { + super.onPageFinished(view, url) + val systemBarInsets = mSystemBarInsets ?: return + val webView = view ?: return + val injectCode = excludeNavigationBarInjectCode(systemBarInsets.bottom) + adjustBodyPaddingToAvoidNavOverlay(webView, injectCode) + } + } + } + private fun excludeWebViewFromSystemBars(webViewWrapper: View, webView: WebView, excludeStatusBar: Boolean, excludeNavigationBar: Boolean) { var mSystemBarInsets: Insets? = null ViewCompat.setOnApplyWindowInsetsListener(webViewWrapper) { v, insets -> @@ -97,34 +124,20 @@ class WebViewUtils { super.onPageFinished(view, url) val systemBarInsets = mSystemBarInsets ?: return val webView = view ?: return - adjustBodyPaddingToAvoidNavOverlay(webView, systemBarInsets) + // @Hint by SuperMonster003 on Mar 12, 2025. + // ! Inject JavaScript code for document body with adding a bottom padding + // ! to ensure that content won't be covered by nav bar when scrolling to the end. + // ! zh-CN: 注入 JavaScript, 为 body 添加底部 padding, 确保滚动到底部时导航栏不遮挡内容. + @Language("JavaScript") + val defaultInjectCode = "document.body.style.paddingBottom = '${systemBarInsets.bottom}px'" + adjustBodyPaddingToAvoidNavOverlay(webView, defaultInjectCode) } } } } - private fun adjustBodyPaddingToAvoidNavOverlay(webView: WebView, systemBarInsets: Insets) { - // @Hint by SuperMonster003 on Mar 12, 2025. - // ! Inject JavaScript code for document body with adding a bottom padding - // ! to ensure that content won't be covered by nav bar when scrolling to the end. - // ! zh-CN: 注入 JavaScript, 为 body 添加底部 padding, 确保滚动到底部时导航栏不遮挡内容. - @Language("JavaScript") - val jsCode = """ - (function() { - let mainElements = document.querySelectorAll('main > *'); - if (mainElements.length > 0) { - const additionalPadding = ${systemBarInsets.bottom}; - mainElements.forEach(ele => { - const computedStyle = window.getComputedStyle(ele); - const currentPadding = parseFloat(computedStyle.paddingBottom) || 0; - ele.style.paddingBottom = (currentPadding + additionalPadding) / window.devicePixelRatio + 'px'; - }); - } else { - document.body.style.paddingBottom = '${systemBarInsets.bottom}px'; - } - })(); - """.trimIndent() - webView.evaluateJavascript(jsCode, null) + private fun adjustBodyPaddingToAvoidNavOverlay(webView: WebView, injectCode: String) { + webView.evaluateJavascript(injectCode, null) } } diff --git a/version.properties b/version.properties index 55131186..8f2bcd70 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Wed Apr 16 17:21:22 CST 2025 -BUILD_TIME=1744795282245 +#Wed Apr 16 23:21:45 CST 2025 +BUILD_TIME=1744816905509 COMPILE_SDK_VERSION=35 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0 @@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=35 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3142 -VERSION_NAME=6.6.2 +VERSION_BUILD=3144 +VERSION_NAME=6.6.3 Alpha VSCODE_EXT_REQUIRED_VERSION=1.0.8