6.6.3 - Alpha5 - 修复文档活动页面显示在线文档时部分内容被系统导航栏遮挡的问题

This commit is contained in:
SuperMonster003
2025-05-26 01:00:00 +08:00
parent 8359429868
commit 7461f77543
5 changed files with 35 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ import org.autojs.autojs.util.DocsUtils.getUrl
import org.autojs.autojs.util.ViewUtils
import org.autojs.autojs.util.WebViewUtils
import org.autojs.autojs6.databinding.ActivityDocumentationBinding
import org.intellij.lang.annotations.Language
/**
* Created by Stardust on Oct 24, 2017.
@@ -31,7 +32,9 @@ class DocumentationActivity : BaseActivity() {
if (ViewUtils.isNightModeYes(this)) {
WebViewUtils.adaptDarkMode(webView)
}
WebViewUtils.excludeWebViewFromStatusBarAndNavigationBar(ewebView, webView)
WebViewUtils.excludeWebViewFromStatusBarAndNavigationBar(ewebView, webView) {
generateInjectCodeForBottomInsets(it)
}
webView.loadUrl(intent.getStringExtra(EXTRA_URL) ?: getUrl("index.html"))
}
}
@@ -57,6 +60,26 @@ class DocumentationActivity : BaseActivity() {
const val EXTRA_URL = "url"
fun generateInjectCodeForBottomInsets(systemBarInsetsBottom: Int): String {
@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()
return injectCode
}
}
}

View File

@@ -9,6 +9,7 @@ import android.webkit.WebView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.tabs.TabLayout
import org.autojs.autojs.event.BackPressedHandler
import org.autojs.autojs.ui.doc.DocumentationActivity.Companion.generateInjectCodeForBottomInsets
import org.autojs.autojs.ui.fragment.BindingDelegates.viewBinding
import org.autojs.autojs.ui.main.MainActivity
import org.autojs.autojs.ui.main.QueryEvent
@@ -21,7 +22,6 @@ 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.
@@ -60,24 +60,8 @@ class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressedHandl
if (ViewUtils.isNightModeYes(requireContext())) {
WebViewUtils.adaptDarkMode(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
WebViewUtils.excludeWebViewFromNavigationBar(ewebView, webView) {
generateInjectCodeForBottomInsets(it)
}
}
}

View File

@@ -81,6 +81,10 @@ class WebViewUtils {
excludeWebViewFromSystemBars(webViewWrapper, webView, excludeStatusBar = true, excludeNavigationBar = true)
}
fun excludeWebViewFromStatusBarAndNavigationBar(webViewWrapper: View, webView: WebView, excludeNavigationBarInjectCode: (systemBarInsetsBottom: Int) -> String) {
excludeWebViewFromSystemBars(webViewWrapper, webView, excludeStatusBar = true, excludeNavigationBarInjectCode = excludeNavigationBarInjectCode)
}
private fun excludeWebViewFromSystemBars(webViewWrapper: View, webView: WebView, excludeStatusBar: Boolean, excludeNavigationBarInjectCode: (systemBarInsetsBottom: Int) -> String) {
var mSystemBarInsets: Insets? = null
ViewCompat.setOnApplyWindowInsetsListener(webViewWrapper) { v, insets ->